Click or drag to resize

Getting started

The SampleITCH application shows an example of working with ItchTrader as shown in the figure below. The example source code is in the Samples/ITCH folder of the installation package.Samples/ITCH.

ITCHSettings
  1. In the designer of the main window: 1) creating an instance of the connector, and to get order books, setting the CreateDepthFromOrdersLog property to ‘true’, 2) passing the connector's market data adapter to the Settings (PropertyGridEx) element. The adapter properties are configured in the graphical interface, see the figure above.

    C#
    public MainWindow()
    {
        ..................................................
    
        _logManager.Listeners.Add(new FileLogListener { LogDirectory = "StockSharp_ITCH" });
        _logManager.Listeners.Add(new GuiLogListener(Monitor));
    
        // create connector
        Trader = new ItchTrader
        {
            LogLevel = LogLevels.Debug,
            CreateDepthFromOrdersLog = true
        };
    
        _logManager.Sources.Add(Trader);
    
        Settings.SelectedObject = Trader.MarketDataAdapter;
    }
  2. 2. Then we install the necessary IConnector event handlers. In the handler of the LookupSecuritiesResult event, we subscribe to the receiving of the order log. We connect streams of instruments, orders, trades and the order log to the corresponding graphic elements. Establishing the connection.

    C#
    private void ConnectClick(object sender, RoutedEventArgs e)
    {
        if (!_isConnected)
        {
            .....................
    
            if (!_initialized)
            {
                _initialized = true;
    
                // subscribe on connection successfully event
                Trader.Connected += () =>
                {
                    // set flag (connection is established)
                    _isConnected = true;
    
                    // update gui labes
                    this.GuiAsync(() => ChangeConnectStatus(true));
                };
                Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false));
    
                // subscribe on connection error event
                Trader.ConnectionError += error => this.GuiAsync(() =>
                {
                    // update gui labes
                    ChangeConnectStatus(false);
    
                    MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);    
                });
    
                // subscribe on error event
                Trader.Error += error =>
                    this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));
    
                // subscribe on error of market data subscription event
                Trader.MarketDataSubscriptionFailed += (security, type, error) =>
                    this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security)));
    
                Trader.NewSecurity += _securitiesWindow.SecurityPicker.Securities.Add;
                Trader.NewTrade += _tradesWindow.TradeGrid.Trades.Add;
                Trader.NewOrderLogItem += _orderLogWindow.OrderLogGrid.LogItems.Add;
    
    
                var subscribed = false;
                //if (AllDepths.IsChecked == true)
                {
                    Trader.LookupSecuritiesResult += securities =>
                    {
                        if (subscribed)
                            return;
    
                        subscribed = true;
    
                        Trader.SendInMessage(new MarketDataMessage
                        {
                            IsSubscribe = true,
                            DataType = MarketDataTypes.OrderLog,
                            TransactionId = Trader.TransactionIdGenerator.GetNextId(),
                        });
                    };    
                }
    
                // set market data provider
                _securitiesWindow.SecurityPicker.MarketDataProvider = Trader;
    
                ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowOrdersLog.IsEnabled = true;
            }
    
            Trader.Connect();
        }
        else
        {
            Trader.Disconnect();
        }
    }