Click or drag to resize

Getting started

The application SampleQuantFeed shows an example of working with QuantFeedTrader as shown in the figure below. The example source code is in the Samples/QuantHouse folder of the installation package.

QuantFEED Sample
  1. First, you need to create an instance of the QuantFeedTrader:

    C#
    // the connector initialization
    Trader = new QuantFeedTrader();
    
    Trader.Login = Login.Text;
    Trader.Password = Password.SecurePassword;
    Trader.Address = Address.Text.To<EndPoint>();
  2. Next, you should subscribe on required QuantFeedTrader events:

    C#
    // subscribe on connection successfully event
    Trader.Connected += () =>
    {
        _isConnected = true;
        Trader.RegisterNews();
    
        // 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
        this.GuiAsync(() => 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, msg, error) =>
        this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security)));
    
    Trader.NewSecurity += security => _securitiesWindow.SecurityPicker.Securities.Add(security);
    Trader.NewNews += news => _newsWindow.NewsGrid.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. NewTrade – new ticks on instruments subscribed by using RegisterTrades(Security) method.
    4. NewNews – news.
  5. Instruments search (in more detail):

    C#
    private void FindClick(object sender, RoutedEventArgs e)
    {
        var wnd = new SecurityLookupWindow { Criteria = new Security { Code = "AAPL" } };
    
        if (!wnd.ShowModal(this))
            return;
    
        MainWindow.Instance.Trader.LookupSecurities(wnd.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 Level1Click(object sender, RoutedEventArgs e)
    {
        TryInitialize();
    
        var window = _level1Windows.SafeAdd(SelectedSecurity, security =>
        {
            // create level1 window
            var wnd = new Level1Window { Title = security.Code + " level1" };
    
            // subscribe on level1
            MainWindow.Instance.Trader.RegisterSecurity(security);
    
            wnd.MakeHideable();
            return wnd;
        });
    
        if (window.Visibility == Visibility.Visible)
            window.Hide();
        else
            window.Show();
    }
  7. To request updates on the order books you need to use the RegisterMarketDepth(Security) method:

    C#
    private void DepthClick(object sender, RoutedEventArgs e)
    {
        var trader = MainWindow.Instance.Trader;
    
        var window = _quotesWindows.SafeAdd(SelectedSecurity, security =>
        {
            // subscribe on order book flow
            trader.RegisterMarketDepth(security);
    
            // create order book window
            var wnd = new QuotesWindow { Title = security.Id + " " + LocalizedStrings.MarketDepth };
            wnd.MakeHideable();
            return wnd;
        });
    
        if (window.Visibility == Visibility.Visible)
            window.Hide();
        else
            window.Show();
    
        TryInitialize();
    }