The class provides access to open position information.
Method/Use |
Prerequisites |
O2GTradesTableResponseReader .getRow
This method is used to get the initial open position information after a session with the trading server is established.
This method provides access to a single open position. If you have multiple open positions, call this method in a loop. |
Depending on the trading server settings, the Trades table may or may not be loaded by the server automatically during the login process.
To determine whether the table is loaded or not and what follow-up action is required to get the open position information, use the returned value of the O2GLoginRules .isTableLoadedByDefault method:
If the table is loaded, you can get the open 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 imlementing the IO2GResponseListener .onRequestCompleted method.
Both methods use the O2GResponse object of the O2GResponseType .GetTrades type.
You must parse this object by using the O2GTradesTableResponseReader object.
For details, see the example below. |
O2GTablesUpdatesReader .getTradeRow
This method is used to get open position information updates.
This method provides access to a single open position. If you have multiple open positions, call this method in a loop. |
To receive the open position information updates, you must implement the IO2GResponseListener .onTablesUpdates method.
The received O2GResponse object is of the O2GResponseType .TablesUpdates type.
You must parse this object by using the O2GTablesUpdatesReader object.
For details, see the example below. |
Get Trade ID, Offer ID and Amount [hide]
// Get trades information
public static void getTrades(O2GSession session, ResponseListener responseListener)
{
try
{
O2GLoginRules loginRules = session.getLoginRules();
// Check if Trades table is loaded automatically
if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.Trades))
{
// If table is loaded, use getTableRefreshResponse method
O2GResponse tradesResponse = loginRules.getTableRefreshResponse(O2GTableType.Trades);
O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
if (responseFactory != null)
{
O2GTradesTableResponseReader tradesReader = responseFactory.createTradesTableReader(tradesResponse);
for (int i = 0; i < tradesReader.Count; i++)
{
O2GTradeRow trade = tradesReader.getRow(i);
Console.WriteLine("TradeID = " + trade.TradeID +
" OfferID = " + trade.OfferID +
" Amount= " + trade.Amount);
}
}
}
else
{
// If table is not loaded, use createRefreshTableRequest method
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory != null)
{
O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.Trades);
responseListener.setRequest(request.RequestID);
session.sendRequest(request);
Thread.Sleep(1000);
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception in getTrades().\n\t " + e.Message);
}
}
// 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)
{
O2GTradesTableResponseReader reader = readerFactory.createTradesTableReader(response);
for (int i = 0; i < reader.Count; i++)
{
O2GTradeRow trade = reader.getRow(i);
Console.WriteLine(" This is a response to your request: \nTradeID = " + trade.TradeID +
" OfferID = " + trade.OfferID +
" Amount= " + trade.Amount);
}
}
}
}
// Implementation of IO2GResponseListener interface public method onTablesUpdates
public void onTablesUpdates(O2GResponse response)
{
O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
if (factory != null)
{
O2GTablesUpdatesReader updatesReader = factory.createTablesUpdatesReader(response);
for (int i = 0; i < updatesReader.Count; i++)
{
O2GTableType tableType = updatesReader.getUpdateTable(i);
if (tableType == O2GTableType.Trades)
{
O2GTradeRow trade = updatesReader.getTradeRow(i);
Console.WriteLine(" This is a live update: \nTradeID = " + trade.TradeID +
" OfferID = " + trade.OfferID +
" Amount= " + trade.Amount);
}
}
}
}
Public Properties |
AccountID
|
Gets the unique identification number of the account the position is opened on.
|
AccountKind
|
Gets the type of the account the position is opened on.
|
AccountName
|
Gets the unique name of the account the position is opened on.
|
Amount
|
Gets the amount of the position.
|
BuySell
|
Gets the trade operation the position is opened by.
|
Columns
|
The columns of the table.
|
Commission
|
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.
|
OfferID
|
Gets the unique identification number of the instrument traded.
|
OpenOrderID
|
Gets the unique identification number of the order the position is opened by.
|
OpenOrderReqID
|
Gets the identifier of the order request the position is opened by.
|
OpenOrderRequestTXT
|
Gets the custom identifier of the order the position is opened by.
|
OpenQuoteID
|
Gets the unique identifier of the pair of prices (bid and ask) the position is opened at.
|
OpenRate
|
Gets the price the position is opened at.
|
OpenTime
|
Gets the date and time when the position is opened.
|
Parties
|
Gets the unique identifier of the environment that has been used to open the position.
|
RolloverInterest
|
Gets the cumulative amount of funds that is added to the account balance for holding the position opened overnight.
|
TableType
|
The type of the table.
|
TradeID
|
Gets the unique identification number of the open position.
|
TradeIDOrigin
|
Gets the unique identification number of the position, the partial closing of which has resulted in the opening of the current position.
|
UsedMargin
|
Gets the amount of funds currently committed to maintain the position.
|
ValueDate
|
Gets the simulated delivery date.
|
Public Methods |
getCell
|
Gets a cell of the table.
|
isCellChanged
|
Gets a flag indicating whether the value of the cell is changed.
|