How to use table manager in ForexConnect API

Brief

The article describes usage of a table manager in ForexConnect API.

Details

Table manager creates a convenient interface which allows access to trading tables.
Table manager provides the following advantages:

The disadvantage of table manager usage compared to the usage of response listener is performance decrease. Performance decreases because the calculated values are computed on each change of the price. If your application does not need calculated values, usage of table manager is not recommended.

For implementation details, please refer to the ForexConnect API Class Hierarchy section.

Starting Table Manager

To ensure correct usage of table manager, please follow these steps:

  1. Create an IO2GSession object using createSession() method:

    IO2GSession *session = CO2GTransport::createSession();
  2. Before the login, specify that your session will use table manager by calling useTableManager() method:

    session->useTableManager(::Yes, NULL);
  3. Login into the ForexConnect API using login() method with your connection parameters:

    session->login(user.c_str(), password.c_str(), url.c_str(), connection.c_str());

    Note: For complete login details, please refer to the How to log in section.
    Obtain table manager for your session using getTableManager() method:

    IO2GTableManager *tableManager = session->getTableManager();
  4. Wait for TablesLoaded status of IO2GTableManager.

    
    while (tableManager->getStatus() != TablesLoaded && tableManager->getStatus() != TablesLoadFailed)
       uni::Sleep(50);
    if (tableManager->getStatus() == TablesLoaded)
    {
        //...
    }
    

    Now trading tables are ready and available for usage. Please see examples below about getting data from the tables and getting notification about tables updates.

  5. Do not forget to release table manager when you are done:

    tableManager->release();

Getting Data from Trading Tables

To get data from trading table:
- use getTable() method and cast the return value to the corresponding class;
- get row data using findRow, getRow, or getNextRow.

Please see a table below for a list of trading tables and corresponding subclasses of IO2GTable

Table

Corresponding class

Accounts

IO2GAccountsTable

Offers

IO2GOffersTable

Orders

IO2GOrdersTable

Trades

IO2GTradesTable

Closed Trades

IO2GClosedTradesTable

Messages

IO2GMessagesTable

Summary

IO2GSummaryTable

For example, if you want to get ask and bid prices from the Offers table, please follow these steps:

  1. Obtain IO2GOffersTable using getTable() method and casting result to IO2GOffersTable:

    IO2GOffersTable *offersTable = (IO2GOffersTable *)tableManager->getTable(::Offers);
  2. Obtain IO2GOfferRow using getNextRow() method, extract necessary information from it, and release IO2GOfferRow:

    
    IO2GTableIterator tableIterator = {0, 0, NULL};
    IO2GOfferTableRow *offerRow = NULL;
    while (offersTable->getNextRow(tableIterator, offerRow))
    {
        //...
        offerRow->release();
    }
    
  3. Release IO2GOffersTable when you are done.

    offersTable->release();

Receiving Notifications about Trading Tables Updates

To receive notifications about updates of trading tables you should:
- create a table listener class which implements IO2GTableListener interface
- create an object of that class
- subscribe table listener object to a table event
- unsubscribe table listener from that table event when you are done

Please see the table below for subscribing/unsubscribing methods of IO2GTable and corresponding events of IO2GTableListener.

Method of IO2GTable to subscribe

Update type

Event of IO2GTableListener

Method of IO2GTable to unsubscribe

subscribeUpdate

Delete

Insert

Update

onDeleted

onAdded

onChanged

unsubscribeUpdate

subscribeStatus

N/A

onStatusChanged

unsubscribeStatus

For example, if you want to get updates for ask and bid prices, your table listener class may look similar to this:

tablelistener.h [show]

tablelistener.cpp [show]

Follow these steps:

  1. Create an instance of your table listener class:

    TableListener *tableListener = new TableListener();
  2. Subscribe to onChanged() event using the subscribeUpdate() method:

    offersTable->subscribeUpdate(Update, tableListener);
  3. Wait for updates:

    uni::Sleep(10000);
  4. Unsubscribe from your table listener class using the unsubscribeUpdate() method:

    offersTable->unsubscribeUpdate(Update, tableListener);
  5. Release table, table listener, and table manager:

    
    offersTable->release();
    tableListener->release();
    tableManager->release();
    

For complete list of steps required to obtain offers information, please refer to How to get offers section.

back