Connect()
Connect()
Definition
Connects to a connection.
Syntax
Connection.Connect(ConnectOptions options)
Parameters
| Parameter | Description |
|---|---|
| options | The connection option of what you want to connect to |
Examples
// Example of subscribing/unsubscribing to execution update events from an Add On. The concept can be carried over// to any NinjaScript object you may be working on.public class MyAddOnTab : NTTabPage{private Connection connection;public MyAddOnTab(){// Connect to Kinetick EODif (connection == null)connection = Connect("Kinetick - End Of Day (Free)");}private Connection Connect(string connectionName){// Output the executiontry{// Get the configured account connectionConnectOptions connectOptions = null;lock (Core.Globals.ConnectOptions)connectOptions = Core.Globals.ConnectOptions.FirstOrDefault(o => o.Name == connectionName);if (connectOptions == null){NinjaTrader.Code.Output.Process("Could not connect. No connection found.", PrintTo.OutputTab1);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 connectedif (connect.Status == ConnectionStatus.Connected)return connect;elsereturn null;}return null;}catch (Exception error){NinjaTrader.Code.Output.Process("Connect exception: " + error.ToString(), PrintTo.OutputTab1);return null;}}// Called by TabControl when tab is being removed or window is closedpublic override void Cleanup(){// Disconnect from our connectionif (connection != null)connection.Disconnect();}// Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.}