How to get offers

Brief

The article discusses how to get offers in .Net.

Details

There are different ways to get offers in your .NET application.

Using Table Manager and .NET Events

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

  2. Allow the use of table manager:

    mSession.useTableManager(O2GTableManagerMode.Yes, null);

    It should be done before the login.

  3. Log in (see this article).

  4. Get O2GTableManager and wait for TablesLoaded status:

    
    O2GTableManager tableMgr = mSession.getTableManager();
    managerStatus = tableMgr.getStatus();
    while (managerStatus == O2GTableManagerStatus.TablesLoading)
    {
        Thread.Sleep(50);
        managerStatus = tableMgr.getStatus();
    }
    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
        return;
    
  5. Get "Offers" table:

    O2GOffersTable offersTable = (O2GOffersTable)tableMgr.getTable(O2GTableType.Offers);
  6. Specify the method that will be triggered by the RowChanged event.

    offersTable.RowChanged +=new EventHandler<RowEventArgs>(offersTable_RowChanged);
  7. Get information about a new offer in that method.

    
    static void offersTable_RowChanged(object sender, RowEventArgs e)
    {
        O2GOfferTableRow offerTableRow = (O2GOfferTableRow)e.RowData;
        if (offerTableRow != null)
        {
            Console.WriteLine("Instrument {0}, Bid={1}, Ask = {2}", offerTableRow.Instrument, offerTableRow.Bid, offerTableRow.Ask);
        }
    }
    
  8. Log out, unsubscribe from the session status listener, and dispose the session when you are done:

    
    mSession.logout();
    mSession.unsubscribeSessionStatus(statusListener);
    mSession.Dispose();
    

Get offers using table manager example: [show]

Using Table Manager and Table Listener

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

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

    class TableListener : IO2GTableListener{...}
  3. Allow the use of table manager:

    mSession.useTableManager(O2GTableManagerMode.Yes, null);


    It should be done before the login.

  4. Log in (see this article).

  5. Get O2GTableManager and wait for TablesLoaded status:

    
    O2GTableManager tableMgr = mSession.getTableManager();
    managerStatus = tableMgr.getStatus();
    while (managerStatus == O2GTableManagerStatus.TablesLoading)
    {
        Thread.Sleep(50);
        managerStatus = tableMgr.getStatus();
    }
    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
        return;
    
  6. Get "Offers" table:

    O2GOffersTable offersTable = (O2GOffersTable)tableMgr.getTable(O2GTableType.Offers);
  7. The table can be processed to get information about offers:

    
    O2GTableIterator iterator = new O2GTableIterator();
    O2GOfferTableRow offerTableRow;
    while (offersTable.getNextRow(iterator, out offerTableRow) == true)
    {
        Console.WriteLine("Instrument = {0}, Bid = {1}, Ask = {2}",
        offerTableRow.Instrument, offerTableRow.Bid, offerTableRow.Ask);
    }
    
  8. To capture updates of "Offers" table create table listener and subscribe it to "Update" event of "Offers" table:

    
    TableListener tableListener = new TableListener();
    offersTable.subscribeUpdate(O2GTableUpdateType.Update, tableListener);
    
  9. Process table updates in "onChanged" event of IO2GTableListener

    
    public void onChanged(string rowID, O2GRow rowData)
    {
        O2GOfferTableRow offerTableRow = (O2GOfferTableRow)rowData;
        if (offerTableRow != null)
        {
            Console.WriteLine("Instrument = {0}, Bid = {1}, Ask = {2}",
            offerTableRow.Instrument, offerTableRow.Bid, offerTableRow.Ask);
        }
    }
    
  10. Unsubscribe from table listener, log out, unsubscribe from the session status listener, and dispose the session when you are done:

    
    offersTable.unsubscribeUpdate(O2GTableUpdateType.Update, tableListener);
    mSession.logout();
    mSession.unsubscribeSessionStatus(statusListener);
    mSession.Dispose();
    

Using Response Listener

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

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

    public class MyResponseListener : IO2GResponseListener{...}
  3. Subscribe an object of this class to the session response:

    
    MyResponseListener responseListener = new MyResponseListener();
    mSession.subscribeResponse(responseListener);
    
  4. Log in (see this article).

  5. Use the listener onSessionStatusChanged function to capture the Connected event.

  6. Get O2GLoginRules:

    O2GLoginRules rules = mSession.getLoginRules();
  7. Then you can get O2GResponse:

    O2GResponse response = rules.getTableRefreshResponse(O2GTableType.Offers);


    The response can be processed to extract necessary information.

  8. You should also capture O2GResponse in the onTablesUpdates function of a response listener class and process the response.

  9. To get information from the "Offers" table from O2GResponse:
    1. Create O2GResponseReaderFactory:

    O2GResponseReaderFactory respReaderFactory = session.getResponseReaderFactory();

    2. Create O2GOffersTableResponseReader:

    O2GOffersTableResponseReader reader = respReaderFactory.createOffersTableReader(response);

    3. Process row by row:

    
    for (i = 0; i < reader.Count; i++)
    {
        O2GOfferRow row = reader.getRow(i);
        //information like row.OfferID, row.Instrument, row.Bid, row.Ask could be extracted now
    }
    
  10. Log out, unsubscribe from the session status listener and response listener, and dispose the session when you are done:

    
    mSession.unsubscribeResponse(responseListener);
    mSession.logout();
    mSession.unsubscribeSessionStatus(statusListener);
    mSession.Dispose();
    

Get offers example: [show]

back