public method IO2GResponseListener.onRequestCompleted

Brief

Processes a notification about a successful request completion.

Declaration
C#
void  onRequestCompleted (string requestId, O2GResponse response)

Parameters
requestId

The identifier of the successfully completed request. A session object may send multiple requests (see the O2GSession.sendRequest method). The method receives notifications of all the requests that have been successfully completed. To make sure you are getting a notification about a particular request, check whether or not the value of this parameter matches the value obtained by calling the O2GRequest.RequestID method. For details, see the example below.

response

The response object. The type of the response depends on the type of the request. For example, if you request information about open positions, the type of the response is O2GResponseType.GetTrades. For a complete list of the response types, see O2GResponseType. The response type specifies a reader that can parse the response. For example, if you request information about open positions, you must use the createTradesTableReader method to create the O2GTradesTableResponseReader object. For a complete list of the methods that create appropriate readers, see the O2GResponseReaderFactory object.

Details

In order to process a notification about a successful request completion, an instance of the class implementing the IO2GResponseListener interface must be subscribed to a session object. It is accomplished by calling the O2GSession.subscribeResponse method.

Note: For the order creation request, successful completion means that an order has been validated by the trading server and accepted for execution. It does not mean that the order has been actually inserted in the Orders table.

The order can be rejected if it has been successfully inserted in the Orders table. In case the order is deleted, the order status is \'R\'. The rejected amount is contained in the order amount field. The rejection message is inserted to the Messages table. The rejection message has the "Market Conditions" type(feature). The message text contains the OrderID. The order delete and the reject message notification can be received randomly.

To make sure that the order is inserted to or deleted from the Orders table or the message is inserted to the Messages table, use the following methods:

O2GTableManager used

Method

Yes

IO2GTableListener.onAdded

No

IO2GResponseListener.onTablesUpdates

Example

Process a notification about the request to get open positions [hide]

using System;
using System.Collections.Generic;
using System.Text;
using fxcore2;
 
namespace GetOffers
{
    class ResponseListener : IO2GResponseListener
    {
        private O2GSession mSession;
 
        public ResponseListener (O2GSession session)
        {
            mSession = session;
        }
 
        public void onRequestCompleted(string requestID, O2GResponse response)
        {
            if (response.Type == O2GResponseType.GetOffers)
            {
                printOffers(response);
            }
        }
 
        public void onRequestFailed(string requestID, string error)
        {
            Console.WriteLine("Request failed. requestID= {0}; error= {1}", requestID, error);
        }
 
        public void onTablesUpdates(O2GResponse response)
        {
           printOffers(response);
        }
 
        private void printOffers(O2GResponse response)
        {
            O2GResponseReaderFactory readerFactory = mSession.getResponseReaderFactory();
            if (readerFactory != null)
            {
                O2GOffersTableResponseReader reader = readerFactory.createOffersTableReader(response);
                int i;
                for (i = 0; i < reader.Count; i++)
                {
                    O2GOfferRow row = reader.getRow(i);
                    if (row.isBidValid && row.isAskValid)
                    {
                         Console.WriteLine("{0} {1} {2} {3}", row.OfferID, row.Instrument, row.Bid, row.Ask);
                    }
                }
            }
        }
 
    }
}
 

Declared in IO2GResponseListener

back