• 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

AddOnFramework: Problems with Connect() method

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

  • GoSPvC
    started a topic AddOnFramework: Problems with Connect() method

    AddOnFramework: Problems with Connect() method

    Hi,

    i have some problems with the Connect() method of the AddOnFramework-Sample.
    I have used the code of the sample at my AddOn to establish a Simulated Data Feed connection.

    This is the Button:
    PHP Code:
    // When user presses the Connect Button:
        
    if (button != null && ReferenceEquals(buttonconnectButton))
        {
            if (
    connection == null)
            {
                
    // Establish connection:
                
    connection Connect("Simulated Data Feed");
                
    //connection = Connect("Interactive Brokers");
            
    }
            else
                
    connection.Disconnect();
        } 
    This is the OnConnectionStatusUpdate():
    PHP Code:
    // This method is fired on connection status events.
    private void OnConnectionStatusUpdate(object senderConnectionStatusEventArgs e)
    {
        try
        {
            
    // For multi-threading reasons, work with a copy of the EventArgs to prevent situations where the EventArgs may already be ahead of us
            // while in the middle processing it.
            
    ConnectionStatusEventArgs eCopy e;

            if (
    eCopy.Connection.Options.Name == "Simulated Data Feed")
            {
                
    // Switch button to be a connect button
                
    if (eCopy.Status == ConnectionStatus.Disconnected)
                {
                    
    connection null;
                    
    Dispatcher.InvokeAsync(() =>
                    {
                        
    connectButton.Content "Connect";
                    });
                }
                
    // Switch button to be a disconnect button
                
    else if (eCopy.Status == ConnectionStatus.Connected)
                {
                    if (
    connection == null)
                        
    connection eCopy.Connection;
                    
    Dispatcher.InvokeAsync(() =>
                    {
                        
    connectButton.Content "Disconnect";
                    });
                }
            }

            
    // If connection hits an error, report it.
            
    if (eCopy.Error != ErrorCode.NoError)
            {
                
    Dispatcher.InvokeAsync(() =>
                {
                    
    outputBox.AppendText(string.Format("{0}{1}. Error: {2} NativeError: {3}",
                        
    Environment.NewLine,
                        
    eCopy.Connection.Options.Name,
                        
    eCopy.Error,
                        
    eCopy.NativeError));
                });
            }

            
    Dispatcher.InvokeAsync(() =>
            {
                
    outputBox.AppendText(string.Format("{0}{1}. Status: {2}",
                        
    Environment.NewLine,
                        
    eCopy.Connection.Options.Name,
                        
    eCopy.Status));
            });
        }
        catch (
    Exception error)
        {
            
    Dispatcher.InvokeAsync(() =>
            {
                
    // It is important to protect NinjaTrader from any unhandled exceptions that may arise from your code
                
    LoggingTabInstance.LoggingBox "TradingSystem - OnConnectionStatusUpdate Exception: " error.ToString();
            });
        }

    This is Connect():
    PHP Code:
    private Connection Connect(string connectionName)
    {
        try
        {
            
    ConnectOptions connectOptions null;
            List<
    ConnectOptionsconnectionOptionList null;

            
    // Copy list of connection options:
            
    lock (Globals.ConnectOptions)
                
    connectionOptionList Globals.ConnectOptions.ToList();

            
    // Get the configured account connection:
            
    connectOptions connectionOptionList.FirstOrDefault(=> o.Name == connectionName);

            if (
    connectOptions == null)
            {
                
    outputBox.Text "Could not connect. No connection found.";
                return 
    null;
            }

            
    // If connection is not already connected, connect.
            
    lock (Connection.Connections)
                if (
    Connection.Connections.FirstOrDefault(=> c.Options.Name == connectionName) == null)
                {
                    
    Connection connect Connection.Connect(connectOptions);

                    
    // Only return connection if successfully connected:
                    
    if (connect.Status == ConnectionStatus.Connected)
                        return 
    connect;
                    else
                        return 
    null;
                }

            return 
    null;
        }
        catch (
    Exception error)
        {
            
    // It is important to protect NinjaTrader from any unhandled exceptions that may arise from your code.
            
    LoggingTabInstance.LoggingBox "TradingSystem - Connect Exception: " error.ToString();
            return 
    null;
        }

    If I click on "Connect" at my AddOn NinjaTrader hang up (the AddOn-Window and the ControlCenter-Window).
    Even if I click on the "Connect Kinetick EOD"-Button at the AddOnFramework-sample I've got the same behaviour, the AddOn-Window and the ControlCenter-Window hang up.

    I had to end task by windows taskmanager to close NinjaTrader.

    At the attached png you can see: There is no error logging.
    Attached Files

  • NinjaTrader_Jim
    replied
    Hi GoSPvC,

    Thanks for the reply.

    As per my reply in our email, we will not concern ourselves with any internal exceptions that we may find when we attach an exception handler to AppDomain. Exceptions within NinjaTrader should normally be a cause for a concern when the internal logic spits out one of these errors to a window or to the log and trace files.

    If you come across an issue and you notice some internal exceptions, we could gather that information when investigating the issue.

    As for Connect() returning null, yes this is the case in the sample code. This is because private Connection Connect(string connectionName) will only return the Connection class when connect.Status equals ConnectionStatus.Connected. The status reaches ConnectionStatus.Connecting when Connection.Connect() is called, so you would have to change the return condition in this private method as follows to have it return when connecting.

    Code:
    if (connect.Status == ConnectionStatus.Connected || connect.Status == ConnectionStatus.Connecting)
    	return connect;
    Please let me know if I can be of further help.

    Leave a comment:


  • GoSPvC
    replied
    Hi Jim,

    thanks for the updated Connect() method. NinjaTrader won't hang up anymore.
    Now there is another problem:

    If I use the new Connect() to connect to the Simulated Data Feed, I get this connection. But Connect() returns null. I have noticed this because on a try to disconnect I got a
    Code:
    System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei NinjaTrader.Gui.NinjaScript.V1TradingSystemTab.OnButtonClick(Object sender, RoutedEventArgs eArgs)
    If i force Connect() to return the connection, I got NO exception but a disconnect.

    It seems that after
    PHP Code:
    Connection connect Connection.Connect(connectOptions); 
    the connection isn't established but still connecting when asking for the return. The following returns a connect:

    PHP Code:
    // Only return connection if successfully connected
    if (connect.Status == ConnectionStatus.Connected
        
    || connect.Status == ConnectionStatus.Connecting)
        return 
    connect;
    else
        return 
    null
    Thanks, GoS

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello GoSPvC,

    Thanks for the reply.

    That sounds like a very strange issue.

    I am not running into any exceptions when I click on the Connections menu of the Control Center or when I open Connections window.

    Could you reproduce this issue after restarting NinjaTrader? If possible, please include a short video demonstrating how you are encountering this issue. We use Jing: https://www.techsmith.com/jing.html

    I have attached a revised version of the AddOnFramework sample. This will make its way to the help guide shortly.

    I look forward to being of further assistance.
    Attached Files

    Leave a comment:


  • GoSPvC
    replied
    Hi,

    maybe i have some additional information.
    If clicking on connections at ControlCenter the menu with available connections opens and i get several exceptions, all the same text:

    Code:
    22:52:15 NinjaTrader.exe - OnFirstChanceException(): hwnd darf nicht IntPtr.Zero (0) oder NULL sein.
    System.ArgumentException: hwnd darf nicht IntPtr.Zero (0) oder NULL sein.
       bei System.Windows.Automation.Provider.AutomationInteropProvider.HostProviderFromHandle(IntPtr hwnd)
    Maybe it helps you,

    GoS

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello GoSPvC,

    Thanks for the note.

    This issue seems to have come up recently. It has been accepted as a bug and is being tracked with the ticket ID NTEIGHT-11807.

    You can reference this ticket number in the Release Notes page for the version of NinjaTrader 8 that includes the bug fix.

    Release Notes can be found here: https://ninjatrader.com/support/help...ease_notes.htm

    Thanks for bringing this matter to light!

    Leave a comment:


  • GoSPvC
    replied
    Hi Jim,

    after some try and error, i have commented out the line:
    PHP Code:
    lock (Connection.Connections
    Now the Connect/Disconnect is doing without hang up.
    I am not that educated in C# to know what's the meaning of that but this should be a hint for you.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello GoSPvC,

    Thanks for the report!

    I have been able to reproduce the issue with the AddOn Framework sample and we are looking into the matter further on our end.

    I'll update this post as more information becomes available.

    Thanks in advance for your patience.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by TazoTodua, Today, 06:00 AM
0 responses
7 views
0 likes
Last Post TazoTodua  
Started by Thans1946, Today, 04:04 AM
0 responses
5 views
0 likes
Last Post Thans1946  
Started by gbux11, Today, 02:36 AM
0 responses
8 views
0 likes
Last Post gbux11
by gbux11
 
Started by fx.practic, Today, 01:47 AM
0 responses
14 views
0 likes
Last Post fx.practic  
Started by bneccv, Yesterday, 09:25 PM
0 responses
5 views
0 likes
Last Post bneccv
by bneccv
 
Working...
X