Click or drag to resize

Reconnections

The Connector class (from which the InteractiveBrokersTrader and OpenECryTrader connectors are inherited) realizes in its code the connections monitoring. Such a tracking is configured through the ConnectorReConnectionSettings property and allows to track the following error scenarios:

  1. It is impossible to establish a connection (no connection, incorrect login-password, etc.). The number of attempts to establish a connection is set through the ReConnectionSettingsAttemptCount property. The default is 0, meaning that the mode is disabled. -1 specifies an infinite number of attempts.
  2. The connection was broken during the working process. The number of attempts to reestablish a connection is set through the ReConnectionSettingsReAttemptCount property. The default is 100. -1 specifies an infinite number of attempts. 0 – the mode is disabled.
  3. The corresponding IConnectorConnected or IConnectorDisconnected events may not come for a long time during the connection or disconnection process. For such situations, the ReConnectionSettingsTimeOutInterval property can be used to specify the maximum allowable time to wait a successful event. If the desired event is not occurred on the expiration of this time, then the IConnectorConnectionError event is called with an expiration error.

Use of the connection tracking

  1. For the demonstration the SampleOEC example working with OpenECry is taken.

    When creating a gateway, it is necessary to initialize the reconnections mechanism settings through the ConnectorReConnectionSettings property:

    C#
    // tradking interval is 10 seconds
    Trader.ReConnectionSettings.Interval = TimeSpan.FromSeconds(10);
    
    Trader.ReConnectionSettings.ConnectionRestored += () => this.GuiAsync(() => MessageBox.Show(this, "Connection was restored."));
    
    // connection was dropped
    Trader.ConnectionError += error => this.Sync(() => MessageBox.Show(this, error.ToString()));
  2. In order to check how the mechanism works, it is possible, for example, turn off your Internet connection:

    Внешние транзакции.

  3. The program will signal about loss of connection:

    Разрыв соединения.

  4. Once the external transactions turned on, the program will display a message about the successful reconnection:

    Восстановление соединения.