Click or drag to resize

Simulator

Testing on market data is trading with a real connection to the exchange ("live" quotes), but without actual orders registering on the exchange. All the registered orders are intercepted, and their execution is emulated based on market order books. Such testing can be useful, for example, if trading simulator is developed. Or it is necessary to check the trading algorithm at short period of time with the real quotes.

To emulate the trading on real data it is necessary to use RealTimeEmulationTraderTUnderlyingMarketDataAdapter, which acts as a "wrapper" of the specific trading system connector (OpenECry, Rithmic etc.). Below is a description of an example of working with the emulator using the connection to OpenECry. The example itself is in the Samples/Testing/SampleRealTimeEmulation folder.

Work with the trading emulator on real data

  1. Creating the RealTimeEmulationTraderTUnderlyingMarketDataAdapter instance and passing to its constructor the OpenECryMessageAdapter adapter. To create identifiers of the "virtual" transactions using the MillisecondIncrementalIdGenerator identifier generator.

    C#
    _connector = new RealTimeEmulationTrader<SmartComMessageAdapter>(new OpenECryMessageAdapter(new MillisecondIncrementalIdGenerator())
    {
        Login = Login.Text,
        Password = Password.Password.To<SecureString>(),
        Address = Address.SelectedAddress
    });
  2. The created connector is used as a usual connector. In our case, subscribing to events, creating CandleManager, passing an information to the graphical components and establishing the connection.

    C#
    SecurityEditor.SecurityProvider = new FilterableSecurityProvider(_connector);
    
    _candleManager = new CandleManager(_connector);
    
    _logManager.Sources.Add(_connector);
    
    _connector.Connected += () =>
    {
        // set flag (connection is established)
        _isConnected = true;
    
        // update gui labels
        this.GuiAsync(() =>
        {
            ChangeConnectStatus(true);
            ConnectBtn.IsEnabled = false;
        });
    };
    
    // subscribe on connection error event
    _connector.ConnectionError += error => this.GuiAsync(() =>
    {
        // update gui labels
        ChangeConnectStatus(false);
    
        MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);
    });
    
    _connector.NewMarketDepths += OnDepths;
    _connector.MarketDepthsChanged += OnDepths;
    
    _connector.NewPortfolios += PortfolioGrid.Portfolios.AddRange;
    _connector.NewPositions += PortfolioGrid.Positions.AddRange;
    
    _connector.NewOrders += Orders.Orders.AddRange;
    _connector.NewMyTrades += Trades.Trades.AddRange;
    
    // subscribe on error of order registration event
    _connector.OrdersRegisterFailed += OrdersFailed;
    
    _candleManager.Processing += (s, candle) =>
    {
        if (candle.State == CandleStates.Finished)
            _buffer.Add(candle);
    };
    
    // subscribe on error event
    _connector.Error += error =>
        this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));
    
    // subscribe on error of market data subscription event
    _connector.MarketDataSubscriptionFailed += (security, type, error) =>
        this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security)));
    
    _connector.Connect();
  3. The following figure shows the result of the example work.

    sample realtaime emulation