• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom share service problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom share service problem

    Hi, I'm trying to create a custom share service, but I'm not managing to create even a basic implementation of one :/
    I tried creating a default implementation using the "New Share Service" button, but it did't allow me to use the service because it wan't configured.
    Then I added the default values for the attributes in the documentation, with an exception of the attribute IsAuthenticationRequired, because it says that it's "name doesn't exist in the current context " when I try to set it in the OnStateChange() method.
    After doing this, NinjaTrader allowed me to configure the custom share service, but when I try to use it with the share option in the context menu, it just gives me an alert message saying "Unhandled exception: Object reference not set to an instance of an object", as if there was something null.

    I also tried overriding the CopyTo() method, with no success.

    Any help is appreciated, thanks!

    #2
    Hello Matheusfx,

    Welcome to the forums!

    It looks like those sections of the help guide are out of date. I have informed the Product Management team to look into updating it. Most of the "Syntax" sections of the help guide pages are valid to the descriptions, but the example code is off in several instances for now.

    I went through those sections of the help guide and placed them in my own Share Service (with modifications to the documented code) and I did not run into issues when accessing the Share Service from the Options menu of the Control Center. I'll provide the code for your reference:

    Code:
    public class MyCustomShareService : ShareService
    {
    	protected override void OnStateChange()
    	{
    		if (State == State.SetDefaults)
    		{
    			Description									= @"Enter the description for your new custom Share Service here.";
    			Name										= "MyCustomShareService";
    			UseOAuth        							= true;
    			CharacterLimit        						= 140;
    			CharactersReservedPerMedia        			= 40;
    			IsDefault        							= false;
    			Signature        							= "This message sent from NinjaTrader 8";
    			IsImageAttachmentSupported 					= false;
    			
    		}
    		else if (State == State.Configure)
    		{
    		}
    	}
    
    	public override async Task OnShare(string text, string imgFilePath)
    	{
    		// place your share service logic here
    	}
    	
    	public override async Task OnAuthorizeAccount()
    	{
    	  	//MyShareServicesToken() is a place holder for an actual API's token method
    	  	string result = "Just Go"; // await MyShareServicesToken("myToken");
    	  
    	  	// result is also a place holder
    	  	if(result == "APIErrorCode123")
    	  	{
    	    	Print("Unable to authorize token");
    	    	return;
    	  	}
    	  
    	  	// please see the your API's OUATH documenation for proper handshake usage
    	 	else Print("Success!");
    		IsConfigured = true;
    	}
    	
    	
    	public override object Icon
    	{         
    	  get 
    	  {
    	    //use a unicode character as our string which will render an arrow
    	    string uniCodeArrow = "\u279A";           
    	    return uniCodeArrow; 
    	  }   
    	}
    
    }
    While developing, I would suggest to reference the existing Share Services as much as possible for an example on how you can develop your own. This will also give you a good idea on how you can override CopyTo in which you would need to add a using statement for System.Reflection to use PropertyInfo[].

    Code:
    public override void CopyTo(NinjaScript ninjaScript)
    {
    	base.CopyTo(ninjaScript);
    
    	// Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change.
    	//  Use reflection to set the appropriate properties, rather than casting ninjaScript to Facebook.
    	PropertyInfo[] props = ninjaScript.GetType().GetProperties();
    	foreach (PropertyInfo pi in props)
    	{
    		// Your own tokens here. Please see other Share Services for a working example
    	}
    }
    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jim; 08-25-2017, 10:47 AM.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by maxgn, Today, 03:34 PM
    0 responses
    4 views
    0 likes
    Last Post maxgn
    by maxgn
     
    Started by Boonfly8, Today, 02:47 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by marioresa, Today, 02:20 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by Parmenides48, Today, 01:26 PM
    1 response
    20 views
    0 likes
    Last Post NinjaTrader_JoshG  
    Started by pjsmith, Today, 12:39 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_PatrickH  
    Working...
    X