The class provides access to information about a position closed during the current trading day.
Method/Use |
Prerequisites |
O2GClosedTradesTableResponseReader .getRow
This method is used to get the initial information about a closed position after a session with the trading server is established.
This method provides access to a single closed position. If you have multiple closed positions, call this method in a loop. |
Depending on the trading server settings, the ClosedTrades table may or may not be loaded by
the server automatically during a login process.
To determine whether the table is loaded or not and what follow-up action is required to get closed position information,
use the returned value of the
O2GLoginRules .isTableLoadedByDefault method:
If the table is loaded, you can get the closed position information by using the
O2GLoginRules .getTableRefreshResponse method;
Otherwise, you must create a request to load the table by using the
O2GRequestFactory .createRefreshTableRequest method.
You must obtain a response to this request by implementing of the
IO2GResponseListener .onRequestCompleted method.
Both the methods use the O2GResponse object of the O2GResponseType .GET_CLOSED_TRADES type.
You must parse this object by using the
O2GClosedTradesTableResponseReader object.
For details, see the example below. |
O2GTablesUpdatesReader .getTradeRow
This method is used to get information about a position closed during a session lifetime.
This method provides access to a single closed position. To track a closing of multiple positions, call this method in a loop. |
To receive information about a position closing, you must implement the IO2GResponseListener .onTablesUpdates method.
The received O2GResponse object is of the O2GResponseType .TABLES_UPDATES type.
You must parse this object by using the O2GTablesUpdatesReader object.
For details, see the example below. |
Get Trade ID, Offer ID and Amount of closed position [hide]
// Get closed trades information
public static void getClosedTrades(O2GSession session, ResponseListener responseListener) {
try {
O2GLoginRules loginRules = session.getLoginRules();
if (loginRules == null) {
return;
}
// Check if Closed Trades table is loaded automatically
if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.CLOSED_TRADES)) {
// If table is loaded, use getTableRefreshResponse method
O2GResponse closedTradesResponse = loginRules.getTableRefreshResponse(O2GTableType.CLOSED_TRADES);
O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
if (responseFactory == null) {
return;
}
O2GClosedTradesTableResponseReader closedTradesReader = responseFactory.createClosedTradesTableReader(closedTradesResponse);
for (int i = 0; i < closedTradesReader.size(); i++) {
O2GClosedTradeRow closedTrade = closedTradesReader.getRow(i);
System.out.println("TradeID = " + closedTrade.getTradeID() +
" CloseRate = " + closedTrade.getCloseRate() +
" GrossPL= " + closedTrade.getGrossPL());
}
} else {
// If table is not loaded, use createRefreshTableRequest method
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory != null) {
O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.CLOSED_TRADES);
responseListener.setRequest(request.getRequestId());
session.sendRequest(request);
Thread.sleep(1000);
}
}
} catch (Exception e) {
System.out.println("Exception in getClosedTrades().\n\t " + e.getMessage());
}
}
// 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;
}
O2GClosedTradesTableResponseReader reader = readerFactory.createClosedTradesTableReader(response);
for (int i = 0; i < reader.size(); i++) {
O2GClosedTradeRow closedtrade = reader.getRow(i);
System.out.println(" This is a response to your request: \nTradeID = " + closedtrade.getTradeID() +
" CloseRate = " + closedtrade.getCloseRate() +
" GrossPL= " + closedtrade.getGrossPL());
}
}
}
// Implementation of IO2GResponseListener interface public method onTablesUpdates
public void onTablesUpdates(O2GResponse response) {
O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
if (factory == null) {
return;
}
O2GTablesUpdatesReader updatesReader = factory.createTablesUpdatesReader(response);
for (int i = 0; i < updatesReader.size(); i++) {
O2GTableType tableType = updatesReader.getUpdateTable(i);
if (tableType == O2GTableType.CLOSED_TRADES) {
O2GClosedTradeRow closedtrade = updatesReader.getClosedTradeRow(i);
System.out.println(" This is a live update: \nTradeID = " + closedtrade.getTradeID() +
" CloseRate = " + closedtrade.getCloseRate() +
" GrossPL= " + closedtrade.getGrossPL());
}
}
}
Public Methods |
getAccountID
|
Gets the unique identification number of the position account.
|
getAccountKind
|
Gets the type of the position account.
|
getAccountName
|
Gets the unique name of the position account.
|
getAmount
|
Gets the amount of a closed position.
|
getBuySell
|
Gets the trade operation the position is opened by.
|
getCell
|
Gets a cell of the table.
|
getCloseOrderID
|
Gets the unique identification number of the order the position is closed by.
|
getCloseOrderParties
|
Gets the unique identifier of the environment that has been used to close the position.
|
getCloseOrderReqID
|
Gets the unique identifier of the order request the position is closed by.
|
getCloseOrderRequestTXT
|
Gets the custom identifier of the order the position is closed by.
|
getCloseQuoteID
|
Gets the unique identifier of the pair of prices (bid and ask) the position is closed at.
|
getCloseRate
|
Gets the price the position is closed at.
|
getCloseTime
|
Gets the date and time when the position is closed.
|
getColumns
|
Gets the columns of the table.
|
getCommission
|
Gets the amount of funds subtracted from the account balance to pay for the broker's service in accordance with the terms and conditions of the account trading agreement.
|
getGrossPL
|
Gets the profit/loss of the position.
|
getOfferID
|
Gets the unique identification number of a traded instrument.
|
getOpenOrderID
|
Gets the unique identification number of the order the position is opened by.
|
getOpenOrderParties
|
Gets the unique identifier of the environment that has been used to open the position.
|
getOpenOrderReqID
|
Gets the unique identifier of the order request the position is opened by.
|
getOpenOrderRequestTXT
|
Gets the custom identifier of the order the position is opened by.
|
getOpenQuoteID
|
Gets the unique identifier of the pair of prices (bid and ask) the position is opened at.
|
getOpenRate
|
Gets the price the position is opened at.
|
getOpenTime
|
Gets the date and time when the position is opened.
|
getRolloverInterest
|
Gets the cumulative amount of funds added to the account balance for holding a position opened overnight.
|
getTableType
|
Gets the type of the table.
|
getTradeID
|
Gets the unique identification number of the position.
|
getTradeIDOrigin
|
Gets the unique identification number of the position, a partial closing of which results in the opening of the current position.
|
getTradeIDRemain
|
Gets the unique identification number of the position opened as the result of the current position partial closing.
|
getValueDate
|
Gets the simulated delivery date.
|
isCellChanged
|
Gets a flag indicating whether the value of the cell is changed.
|