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 IO2GLastOrderUpdateResponseReader.
If the order has been executed, the server returns IO2GLastOrderUpdateResponseReader 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

const char*

The command. Must be GetLastOrderUpdate.

Key

const char*

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

const char*

The value of the order field to search.

AccountName

const char*

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]

// Forward definition
std::string getAccountName(IO2GSession *session);
IO2GResponse* sendGetLastOrderUpdateRequest(IO2GSession *session, LPCSTR accountName, LPCSTR orderID, IO2GResponseListener *responseListener);
IO2GLastOrderUpdateResponseReader* processResponse(IO2GSession *session, IO2GResponse *response);
void printLastOrderUpdateResponse(IO2GLastOrderUpdateResponseReader *lastOrderUpdateResponseReader);
 
 
 // Program entry point
 int main(int argc, char *argv[])
 {
   IO2Session *session = NULL;
   // Must be implemented by the user
   IO2GResponseListener *responseListener = NULL;
   //.... Obtain session object and connect to the server
   std::string accountName = getAccountName(session);
   std::string orderID = "XXXXX"; // Should be specified by the user
 
   IO2GResponse *response = sendGetLastOrderUpdateRequest(accountName, orderID);
   if (response)
   {
       O2G2Ptr<IO2GLastOrderUpdateResponseReader> lastOrderUpdateResponseReader = processResponse(response);
       printLastOrderUpdate(lastOrderUpdateResponseReader);
   }
   response->release();
   //...Logout
 }
 
std::string getAccountName(IO2GSession *session)
{
    O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
    std::string sAccountName = "";
    if(loginRules->isTableLoadedByDefault(::Accounts))
    {
        O2G2Ptr<IO2GResponse> response = loginRules->getTableRefreshResponse(::Accounts);
        if(response)
        {
            O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
            O2G2Ptr<IO2GAccountsTableResponseReader> responseReader = readerFactory->createAccountsTableReader(response);
            O2G2Ptr<IO2GAccountRow> row = responseReader->getRow(0);
            sAccountName = row->getAccountName();
            std::cout << "Using account Name: " << accountName << std::endl;!
        }
    }
    return sAccountName;
}
 
/** Sync method. Send a request and wait for the response/
IO2GResponse* sendGetLastOrderUpdateRequest(IO2GSession *session, LPCSTR accountName, LPCSTR orderID, IO2GResponseListener *responseListener)
{
    O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
    O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
    valuemap->setString(Command, O2G2::Commands::GetLastOrderUpdate);
    valuemap->setString(AccountName, sAccountName.c_str());
    valuemap->setString(Key, O2G2::KeyType::OrderID);
    valuemap->setString(Id, orderID);
 
    O2G2Ptr<IO2GRequest> lastOrderUpdateRequest = requestFactory->createOrderRequest(valuemap);
    // Response listener receives async callback. Therefore, request ID must be set
    // before sending the request.
    responseListener->setRequest(lastOrderUpdateRequest->getRequestID());
    session->sendRequest(lastOrderUpdateRequest);
    uni::WaitForSingleObject(responseListener->getResponseEvent(), INFINITE);
    return responseListener->getLastUpdateOrderUpdateResponse();
}
 
IO2GLastOrderUpdateReader* processResponse(IO2GSession *session, IO2GResponse *response)
{
    O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
    return readerFactory->createLastOrderUpdateResponseReader(response);
}
 
void printLastOrderUpdate(IO2GLastOrderUpdateReader *lastOrderUpdateReader)
{
    O2GTableUpdateType updateType = lastOrderUpdateResponseReader->getUpdateType();
    std::string updateTypeString;
    switch(updateType)
    {
    case Delete:
        updateTypeString = "Delete";
        break;
    case Insert:
        updateTypeString = "Insert";
        break;
    case Update:
        updateTypeString = "Update";
        break;
    default:
        updateTypeString = "Undefined";
    }
    O2G2Ptr<IO2GOrderRow> orderRow = lastOrderUpdateResponseReader->getOrder();
 
    std::cout << "UpdateType: " <<  updateTypeString
              << "; Order ID: " << orderRow->getOrderID()
              << "; Status: "  << orderRow->getStatus() << std::endl;
}
 
// In response listener file
void ResponseListener::onRequestCompleted(const char *requestId, IO2GResponse  *response)
{
    if (response != 0 && mRequestID == requestID)
    {
       mLastOrderUpdateResponseLast = response;
    }
    uni::SetEvent(mResponseEvent);
}
 
 

back