Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 aa731, Today, 02:54 AM
    0 responses
    4 views
    0 likes
    Last Post aa731
    by aa731
     
    Started by thanajo, 05-04-2021, 02:11 AM
    3 responses
    470 views
    0 likes
    Last Post tradingnasdaqprueba  
    Started by Christopher_R, Today, 12:29 AM
    0 responses
    10 views
    0 likes
    Last Post Christopher_R  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    166 responses
    2,237 views
    0 likes
    Last Post sidlercom80  
    Started by thread, Yesterday, 11:58 PM
    0 responses
    4 views
    0 likes
    Last Post thread
    by thread
     
    Working...
    X