public method IO2GResponseListener.onRequestCompleted

Brief

Processes a notification about a request successful completion.

Declaration
Java
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 the value of this parameter matches the value obtained by calling the O2GRequest.getRequestId 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.GET_TRADES. For a complete list of the response types, see O2GResponseType. The response type defines 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 request successful 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

Proccess notification about the request to get open positions [hide]

    // Create a request to get open positions information
    O2GRequestFactory requestFactory = session.getRequestFactory();
    if (requestFactory != null) {
        O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.TRADES);
        responseListener.setRequest(request.getRequestId());
        session.sendRequest(request);
        Thread.sleep(1000);
    }
 
     // Set request in the implementation of IO2GResponseListener interface
     public void setRequest(String requestID) {
        mRequestID = requestID;
     }
 
    // Implementation of IO2GResponseListener interface public method onRequestCompleted
    public void onRequestCompleted(String requestID, O2GResponse response) {
        if (requestID.equals(mRequestID)) {
            O2GResponseReaderFactory readerFactory = mSession.getResponseReaderFactory();
            if (readerFactory == null) {
                return;
            }
            O2GTradesTableResponseReader reader = readerFactory.createTradesTableReader(response);
            for (int i = 0; i < reader.size(); i++) {
                O2GTradeRow trade = reader.getRow(i);
                System.out.println(" This is a response to your request: \nTradeID = " + trade.getTradeID() +
                                   " OfferID = " +  trade.getOfferID() +
                                   " Amount= " + trade.getAmount());
            }
        }
    }

Declared in IO2GResponseListener

back