Get Last Order Update

Brief

Get the up-to-date order information from the server.

Details

This command is used to request the latest available information on the order from the server.
The command is useful in case the trader wants to get the information about his order after the relogin or the automatic reconnection.
The method can be called in the "logged in" state.
If the request has been executed successfuly, the response will be received in IO2GResponseListener.onRequestCompleted. The repsonse can be converted to O2GLastOrderUpdateResponseReader.
If the order has been executed, the server returns O2GLastOrderUpdateResponseReader with the 'Delete' type of the table update and the 'F' status ('Executed') in the order row.

To get the updated order information, please fill the following values in the value map:

Parameter name

Datatype

Description

Command

String

The command. Must be GetLastOrderUpdate.

Key

String

The order field to search the order.

OrderID

Search by identification number of the order.

RequestID

Search by the identifier of the order request. Note that if the order has the attached stop and limit orders, all of them have the same RequestID. In this case the main order will be returned.

RequestTXT

Search by the custom identifier of the order. In case there are a few orders with the same RequestTXT, the oldest order will be returned (the order which was created first).

Id

String

The value of the order field to search.

AccountName

String

The name of the account. Note that it is not AccountID.

To use the command:

  1. Create a request and send it to the server.

  2. Wait for the response using IO2GResponseListener.

Example: Get last order update [hide]

import com.fxcore2.Constants;
import com.fxcore2.O2GSession;
import com.fxcore2.O2GTransport;
import com.fxcore2.O2GLoginRules;
import com.fxcore2.O2GResponseReaderFactory;
import com.fxcore2.O2GResponse;
import com.fxcore2.O2GOffersTableResponseReader;
import com.fxcore2.O2GTableType;
import com.fxcore2.O2GOfferRow;
import com.fxcore2.O2GRequestFactory;
import com.fxcore2.O2GValueMap;
import com.fxcore2.O2GRequest;
import com.fxcore2.O2GRequestParamsEnum;
import com.fxcore2.O2GAccountsTableResponseReader;
import com.fxcore2.O2GAccountRow;
 
public class Main {
    //...
 
    public static void main(String[] args) {
 
       O2GSession mSession = null;
       String mUserID = "XXXX";
       String mPassword = "XXXX";
       String mURL = "http://www.fxcorporate.com/Hosts.jsp";
       String mConnection = "Demo";
       String mOrderID = "XXXX";
       String mAccountName = "XXXX";
 
       // Create a session, subscribe to session listener, login, open position, logout
       try {
           mSession = O2GTransport.createSession();
           SessionStatusListener statusListener = new SessionStatusListener(mSession, mDBName, mPin);
           mSession.subscribeSessionStatus(statusListener);
           ResponseListener responseListener = new ResponseListener(mSession);
           mSession.subscribeResponse(responseListener);
           mSession.login(mUserID, mPassword, mURL, mConnection);
           while (!statusListener.isConnected() && !statusListener.hasError()) {
                Thread.sleep(50);
           }
           if (!statusListener.hasError()) {
               getLastOrderUpdate(mSession, responseListener, mOrderID, mAccountName);
           }
           mSession.logout();
           while (!statusListener.isDisconnected()) {
               Thread.sleep(50);
           }
 
           mSession.unsubscribeSessionStatus(statusListener);
           mSession.unsubscribeResponse(responseListener);
           mSession.dispose();
           System.exit(1);
       } catch (Exception e) {
           System.out.println ("Exception: " + e.getMessage());
           System.exit(1);
       }
   }
 
   public static void getLastOrderUpdate(O2GSession session, ResponseListener responseListener, String orderID, String accountName) throws InterruptedException
   {
       O2GRequestFactory requestFactory = session.getRequestFactory();
       if (requestFactory != null) {
           O2GValueMap valuemap = requestFactory.createValueMap();
           valuemap.setString(O2GRequestParamsEnum.COMMAND, Constants.Commands.GetLastOrderUpdate);
           valuemap.setString(O2GRequestParamsEnum.ACCOUNT_NAME, accountName);
           valuemap.setString(O2GRequestParamsEnum.KEY, Constants.KeyType.OrderID);
           valuemap.setString(O2GRequestParamsEnum.ID, orderID);
           O2GRequest request = requestFactory.createOrderRequest(valuemap);
           responseListener.setRequest(request.getRequestId());
           session.sendRequest(request);
           Thread.sleep(1000);
       }
   }
}
 
public class ResponseListener implements IO2GResponseListener {
 
   private boolean mError = false;
   private boolean mRequestComplete = false;
   private String mRequestID = "";
   private O2GSession mSession;
 
   public ResponseListener(O2GSession session) {
       mSession = session;
   }
 
   // Shows if there was an error during the request processing
   public final boolean hasError() {
       return mError;
   }
 
   public void setRequest(String requestID){
       mRequestID = requestID;
       mError = false;
       mRequestComplete = false;
   }
 
    // Implementation of IO2GResponseListener interface public method onRequestCompleted
    public void onRequestCompleted(String requestID, O2GResponse response) {
       if (mRequestID.equals(requestID)) {
           System.out.println("Request completed.\nrequestID= " + requestID);
           O2GResponseReaderFactory readerFactory = mSession.getResponseReaderFactory();
           if (readerFactory == null) {
               mError = true;
               mRequestComplete = true;
               return;
           }
           mError = false;
           mRequestComplete = true;
 
           if (response.getType() == O2GResponseType.GET_LAST_ORDER_UPDATE) {
               O2GLastOrderUpdateResponseReader lastOrderUpdateResponseReader = readerFactory.createLastOrderUpdateResponseReader(response);
               O2GOrderRow orderRow = lastOrderUpdateResponseReader.getOrder();
               System.out.println("UpdateType: " + lastOrderUpdateResponseReader.getUpdateType().toString() + "; OrderID: " + orderRow.getOrderID() + "; Status: " + orderRow.getStatus());
           }
       }
   }
 
   // Implementation of IO2GResponseListener interface public method onRequestFailed
   public void onRequestFailed(String requestID, String error) {
       if (mRequestID.equals(requestID)) {
           System.out.println("Request failed.\nrequestID= " + requestID + "; error= " + error);
           mError = true;
           mRequestComplete = false;
       }
   }
 
   // Implementation of IO2GResponseListener interface public method onTablesUpdates
   public void onTablesUpdates(O2GResponse response) {}
 
 

back