How to get offers

Brief

The article discusses how to get offers in C++.

Details

There are two ways to get offers in your C++ application.
The first way is to use table listener. In this case you should:

  1. Create a session, a session status listener, subscribe the status listener to the session status (see this article).

  2. Implement the IO2GTableListener interface in a table listener class:

    class TableListener : public IO2GTableListener {...}
  3. Allow the use of table manager (it should be done before the login):

    session->useTableManager(::Yes, NULL);
  4. Log in (see this article).

  5. Get table manager:

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

    while (tableManager->getStatus() != TablesLoaded && tableManager->getStatus() != TablesLoadFailed) 
        uni::Sleep(50);
  7. Get "Offers" table:

    IO2GOffersTable *offersTable = (IO2GOffersTable *)tableManager->getTable(::Offers);
  8. The table can be processed to get information about offers:

    
    IO2GOfferTableRow *offerRow = NULL;
    IO2GTableIterator tableIterator = {0, 0, NULL};
    while (offersTable->getNextRow(tableIterator, offerRow))
    {
        printf("Instrument: %s, Bid = %f, Ask = %f\n", offerRow->getInstrument(), offerRow->getBid(), offerRow->getAsk());
        offerRow->release();
    }
    
  9. To capture updates of "Offers" table create table listener and subscribe it to "Update" event of "Offers" table:

    
    TableListener * tableListener = new TableListener();
    offersTable->subscribeUpdate(Update, tableListener);
    
  10. Process table updates in "onChanged" event of IO2GTableListener:

    
    void TableListener::onChanged(const char *rowID, IO2GRow *row)
    {
        IO2GOfferRow *offerRow = static_cast<IO2GOfferRow *>(row);
        if (offerRow!=NULL)
            printf("Instrument: %s, Bid = %f, Ask = %f\n", offerRow->getInstrument(), offerRow->getBid(), offerRow->getAsk());
    }
    
  11. Unsubscribe from table listener when you are done:

    
    offersTable->unsubscribeUpdate(Update, tableListener);
    delete tableListener;
    offersTable->release();
    
  12. Log out (see this article).

Get offers example [show]

The second way to get offers in your C++ application is to use response listener. In that case you should:

  1. Create a session, a session status listener, subscribe the status listener to the session status (see this article).

  2. Implement the IO2GResponseListener interface in a response listener class:

    class ResponseListener : public IO2GResponseListener{...}


  3. Create a response listener object:

    ResponseListener * responseListener = new ResponseListener(...);

    Subscribe an object of this class to the session response:

    pSession->subscribeResponse(responseListener);


  4. Log in (see this article).

  5. The events are coming asynchronously. They should come in another thread. When an event comes, a signal will be sent to the main thread.

  6. Use the function onSessionStatusChanged of the session status listener to capture the Connected event.

  7. Get IO2GLoginRules:

    IO2GLoginRules * loginRules = mSession->getLoginRules();


  8. Then you can get IO2GResponse:

    IO2GResponse * response = loginRules->getTableRefreshResponse(Offers);

    The response can be processed to extract necessary information.

  9. You should also capture IO2GResponse in the onTablesUpdates function of a response listener class.

  10. To get information from the "Offers" table from IO2GResponse:
    1. Create IO2GResponseReaderFactory:

    IO2GResponseReaderFactory * factory = mSession->getResponseReaderFactory();


    2. Create IO2GOffersTableResponseReader:

    IO2GOffersTableResponseReader * offersReader = factory->createOffersTableReader(response);


    3. Process row by row:

    
    for (int i = 0; i < offersReader->size(); i++)
    {
          IO2GOfferRow * offer = offersReader->getRow(i);
          // Information like
          // offer->getInstrument(),
          // offer->getOfferID(),
          // offer->getBid(),
          // offer->getAsk(),
          // offer->getVolume()
          // can be extracted now.
    }
    

back