ConnectOptions

View as Markdown

Definition

ConnectOptions is an abstract class used to configure options for a specific configured Connection. An instance of ConnectOptions can be passed into the Connection.Connect() method to initiate a connection, as seen in the example below.

For a complete, working example of this class in use, download the framework example located on our Developing AddOns Overview.

Properties

Properties accessible from an instance of ConnectOptions include:


  • BrandName
  • A string representing the provider name

  • CanEnableHds
  • A bool determining the connection can use NinjaTrader Historical Data Servers. Related properties include HasHdsAlwaysEnabled and IsHdsEnabled

  • CanManageOrders
  • A bool determining orders can be managed on the Connection. Related properties include IsDataProviderOnly

  • Mode
  • A NinjaTrader.Cbi.Mode object representing the current mode of the connection (Mode.Live or Mode.Simulation)
NameThe user-configured name of the ConnectionProviderThe provider configured in the Connection

Examples

1// Connecting to a configured connection
2private Connection Connect(string connectionName)
3{
4 // Get the configured account connection by using the string passed into this custom Connect() method
5 // We will lock the ConnectOptions collection to avoid in-flight changes causing any issues
6 ConnectOptions connectOptions = null;
7 lock (Core.Globals.ConnectOptions)
8 connectOptions = Core.Globals.ConnectOptions.FirstOrDefault(o => o.Name == connectionName);
9
10 // If connection is not already connected, connect to it
11 lock (Connection.Connections)
12 if (Connection.Connections.FirstOrDefault(c => c.Options.Name == connectionName) == null)
13 {
14 Connection connect = Connection.Connect(connectOptions);
15
16 // Only return connection if successfully connected
17 if (connect.Status == ConnectionStatus.Connected)
18 return connect;
19 else
20 return null;
21 }
22}