class IO2GLastOrderUpdateResponseReader
Brief
The class reads a response to a request for the current state of an order.
Details
To get information about the current state of an order, you must request it. The process of requesting the current order state consists of several steps that are described in the
Get Last Order Update section.
The possible states of different order types are described in the Orders State Machines section.
As an answer to the request, the trading server sends a response object of the GetLastOrderUpdate type.
This object is the response
parameter in your implementation of the
IO2GResponseListener.onRequestCompleted method.
To process the response contents, you must use an instance of the IO2GLastOrderUpdateResponseReader
class.
To create an instance of the IO2GLastOrderUpdateResponseReader
class, pass the response object as an argument to the
IO2GResponseReaderFactory.createLastOrderUpdateResponseReader method. For example,
O2GLastOrderUpdateResponseReader orderReader = factory.createLastOrderUpdateResponseReader(response);
Example
Requesting the current order state by the order's unique identifier [show]
Requesting the current order state by the order's unique identifier [hide]
void getLastOrderUpdate(IO2GSession *session, ResponseListener *responseListener, const char * orderID, const char * accountName)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (requestFactory != NULL)
{
O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::GetLastOrderUpdate);
valuemap->setString(AccountName, accountName);
valuemap->setString(Key, O2G2::KeyType::OrderID);
valuemap->setString(ID, orderID);
O2G2Ptr<IO2GRequest> request = requestFactory->createOrderRequest(valuemap);
responseListener->setRequest(request->getRequestID());
session->sendRequest(request);
uni::Sleep(1000);
}
}
// Set request in the implementation of IO2GResponseListener interface
void ResponseListener::setRequest(const char * requestID)
{
mRequestID = requestID;
}
std::string updateTypeToString(O2GTableUpdateType updateType)
{
std::string sRes = "";
switch (updateType)
{
case Delete:
sRes = "Delete";
break;
case Insert:
sRes = "Insert";
break;
case Update:
sRes = "Update";
break;
default:
sRes = "UpdateUnknown";
}
return sRes;
}
// Implementation of IO2GResponseListener interface public method onRequestCompleted
void onRequestCompleted(const char * requestID, IO2GResponse *response)
{
if (mRequestID == requestID)
{
std::cout << "Request completed." << std::endl << "requestID = " << requestID << std::endl;
O2G2Ptr<IO2GResponseReaderFactory> readerFactory = mSession->getResponseReaderFactory();
if (readerFactory != NULL)
{
if (response->getType() == GetLastOrderUpdate)
{
O2G2Ptr<IO2GLastOrderUpdateResponseReader> lastOrderUpdateResponseReader = readerFactory->createLastOrderUpdateResponseReader(response);
O2G2Ptr<IO2GOrderRow> orderRow = lastOrderUpdateResponseReader->getOrder();
std::cout << "UpdateType: " << updateTypeToString(lastOrderUpdateResponseReader->getUpdateType()) <<
" OrderID: " << orderRow->getOrderID() <<
" Status: " << orderRow->getStatus() << std::endl;
}
}
}
}
Public Methods |
getOrder
|
Gets an instance of the class that provides access to order information.
|
getUpdateType
|
Gets the last operation that has been performed with an order.
|
back