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.
|
||||||
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:
Create a request and send it to the server.
Wait for the response using IO2GResponseListener
.
Example: Get last order update [hide]
using fxcore2; namespace GetLastOrderUpdate { class Program { Static String sUserID = "XXXX"; Static String sPassword = "XXXX"; Static String sURL = "http://www.fxcorporate.com/Hosts.jsp"; Static String sConnection = "Demo"; Static String sAccountName = "XXXX"; //NOT AccountID! Static String sOrderID = "XXXX"; static void Main(string[] args) { //... session = O2GTransport.createSession(); SessionStatusListener statusListener = new SessionStatusListener(session); session.subscribeSessionStatus(statusListener); statusListener.login(sUserID, sPassword, sURL, sConnection); //... if (!statusListener.Error) { ResponseListener responseListener = new ResponseListener(); session.subscribeResponse(responseListener); GetLastOrderUpdate(responseListener, sOrderID, sAccountName); session.unsubscribeResponse(responseListener); session.logout(); while (!statusListener.Disconnected) Thread.Sleep(50); } else Console.WriteLine("Login error: {0}", statusListener.Error); session.unsubscribeSessionStatus(statusListener); session.Dispose(); } static bool GetLastOrderUpdate(ResponseListener responseListener, string orderID, string accountName) { O2GRequestFactory factory = Program.Session.getRequestFactory(); if (factory == null) return false; O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.GetLastOrderUpdate); valuemap.setString(O2GRequestParamsEnum.Key, Constants.KeyType.OrderID); valuemap.setString(O2GRequestParamsEnum.Id, orderID); // value of Key valuemap.setString(O2GRequestParamsEnum.AccountName, accountName); //Account name, not Account ID O2GRequest request = factory.createOrderRequest(valuemap); if (request != null) { Console.WriteLine("Send GetLastOrderUpdate request for requestID={0}", orderRequestID); responseListener.RequestID = request.RequestID; Program.Session.sendRequest(request); while (!responseListener.ResponseReceived) Thread.Sleep(50); if (string.IsNullOrEmpty(responseListener.Error)) return true; else { Console.WriteLine("GetLastOrderUpdate request failed: {0}", responseListener.Error); return false; } } else { Console.WriteLine("Cannot create request; probably some arguments are missing or incorrect"); return false; } } class ResponseListener : IO2GResponseListener { public string RequestID { get { return mRequestID;} set { mRequestID = value; mResponseReceived = false; } } private string mRequestID; public string Error { get { return mError; } private set { mError = value; } } private string mError; public bool ResponseReceived { get { return mResponseReceived; } private set { mResponseReceived = value; } } private bool mResponseReceived = false; #region IO2GResponseListener Members public void onRequestCompleted(string requestId, O2GResponse response) { if (requestId == mRequestID) { mResponseReceived = true; mError = string.Empty; if (response.Type == O2GResponseType.GetLastOrderUpdate) { O2GResponseReaderFactory factory = Program.Session.getResponseReaderFactory(); if (factory != null) { O2GLastOrderUpdateResponseReader reader = factory.createLastOrderUpdateResponseReader(response); Console.WriteLine("Last order update: UpdateType={0}, OrderID={1}, Status={2}, StatusTime={3}", reader.UpdateType.ToString(), reader.Order.OrderID, reader.Order.Status.ToString(), reader.Order.StatusTime.ToString("yyyy-MM-dd HH:mm:ss")); } } } } public void onRequestFailed(string requestId, string error) { mResponseReceived = true; mError = error; } public void onTablesUpdates(O2GResponse data) { //STUB } #endregion } } }