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:
// When user presses the Connect Button:
if (button != null && ReferenceEquals(button, connectButton))
{
if (connection == null)
{
// Establish connection:
connection = Connect("Simulated Data Feed");
//connection = Connect("Interactive Brokers");
}
else
connection.Disconnect();
}
// This method is fired on connection status events.
private void OnConnectionStatusUpdate(object sender, ConnectionStatusEventArgs 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();
});
}
}
private Connection Connect(string connectionName)
{
try
{
ConnectOptions connectOptions = null;
List<ConnectOptions> connectionOptionList = null;
// Copy list of connection options:
lock (Globals.ConnectOptions)
connectionOptionList = Globals.ConnectOptions.ToList();
// Get the configured account connection:
connectOptions = connectionOptionList.FirstOrDefault(o => 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 => 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;
}
}
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.
Comment