Click or drag to resize

Getting started

The application SampleIQFeed shows an example of working with IQFeedTrader as shown in the figure below. The example source code is in the Samples/IQFeed folder of the installation package.

Iq Feed Sample
  1. First, you need to create an instance of the IQFeedTrader:

    C#
    Trader = new IQFeedTrader();
  2. Next, you should subscribe on required IQFeedTrader events:

    C#
    // subscribe on successfully connect event
    Trader.Connected += () =>
    {
        // set flag (connection is established)
        _isConnected = true;
    
        // update gui labes
        this.GuiAsync(() => ChangeConnectStatus(true));
    };
    
    // subscribe on connection error event
    Trader.ConnectionError += error => this.GuiAsync(() =>
    {
        // update gui labes
        ChangeConnectStatus(false);
    
        MessageBox.Show(this, error.ToString(), "Connection was dropped.");    
    });
    
    // subscribe on successfully disconnect event
    Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false));
    
    // subscribe on error event
    Trader.Error += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), "Data processing error"));
    
    // new securities received
    Trader.NewSecurities += securities => this.GuiAsync(() => _securitiesWindow.AddSecurities(securities));
    
    // new anonymous trades received
    Trader.NewTrades += trades => this.GuiAsync(() => _tradesWindow.Trades.AddRange(trades));
    
    // news received
    Trader.NewNews += news => this.GuiAsync(() => _newsWindow.News.Add(news));
  3. Then you need to establish the connection:

    C#
    Trader.Connect();
  4. The subscription to the news in the event handler will be done after a successful connection:

    C#
    Trader.RegisterNews();

    After this operation the following events should be expected:

    1. SecuritiesChanged – instrument change (last price, best bid/ask price, etc.).
    2. MarketDepthsChanged – order book change, requested through RegisterMarketDepth(Security) method.
    3. NewTrades – new ticks on instruments subscribed by using RegisterTrades(Security) method.
    4. NewNews – news.
  5. Instruments search (in more detail):

    IQFeed Find Security
    C#
    var criteria = new Security
    {
        Type = (SecurityTypes)SecType.SelectedValue,
        Code = SecCode.Text,
    };
    
    MainWindow.Instance.Trader.LookupSecurities(criteria);
  6. For updates on the selected instrument and ticks you need to use the RegisterSecurity(Security) and RegisterTrades(Security) methods, respectively:

    C#
    private void TradesClick(object sender, RoutedEventArgs e)
    {
        var security = SelectedSecurity;
        var trader = MainWindow.Instance.Trader;
    
        if (_tradesSecurities.Contains(security))
        {
              // unsubscribe from level1 flow
            trader.UnRegisterSecurity(security);
            trader.UnRegisterTrades(security);
    
            _tradesSecurities.Remove(security);
        }
        else
        {
            // subscribe to level1 flow
            trader.RegisterSecurity(security);
            trader.RegisterTrades(security);
    
            _tradesSecurities.Add(security);
        }
    }
  7. To request updates on the order books you need to use the RegisterMarketDepth(Security) method:

    C#
    private void Quotes_Click(object sender, RoutedEventArgs e)
    {
        var window = _quotesWindows.SafeAdd(SelectedSecurity, security =>
        {
            // subscribe on order book flow
            MainWindow.Instance.Trader.RegisterMarketDepth(security);
    
            // create order book window
            var wnd = new QuotesWindow { Title = security.Code + " quotes" };
            wnd.MakeHideable();
            return wnd;
        });
    
        if (window.Visibility == Visibility.Visible)
            window.Hide();
        else
            window.Show();
    }
  8. For the trade history getting on the specified date the IQFeedTraderGetHistoricalLevel1(SecurityId, DateTimeOffset, DateTimeOffset, Boolean) method should be used:

    IQFeed History Trades
    C#
    Trades.Clear();
    Trades.AddRange(MainWindow.Instance.Trader.GetTrades(SecurityPicker.SelectedSecurity, (DateTime)DatePicker.SelectedDate));
  9. For the candles history on instrument getting on the specified period the IQFeedTraderGetHistoricalCandles(Security, Type, Object, Int64, Boolean) method should be used:

    IQFeed History Candles
    C#
    Candles.Clear();
    Candles.AddRange(MainWindow.Instance.Trader.GetCandles(SecurityPicker.SelectedSecurity, (TimeSpan)TimeFramePicker.SelectedValue, (DateTimeOffset)DateFromPicker.SelectedDate, (DateTimeOffset)DateToPicker.SelectedDate));