class O2GGenericTableResponseReader
Brief
The class provides methods to read a stream of trading table rows coming from the trading server.
Details
The O2GGenericTableResponseReader
is a generic class that provides
methods to read responses to requests for initial trading tables information.
The O2GGenericTableResponseReader
can be used to process the contents of the following response types:
GET_OFFERS, GET_ACCOUNTS,
GET_TRADES, GET_CLOSED_TRADES,
GET_ORDERS, and GET_MESSAGES.
You can not create an instance of the class directly. You can only use the methods of the class on the following subclasses:
O2GOffersTableResponseReader
O2GAccountsTableResponseReader
O2GTradesTableResponseReader
O2GClosedTradesTableResponseReader
O2GOrdersTableResponseReader
O2GMessagesTableResponseReader
O2GTable
.
Note: The O2GTable
class is available only when your application uses the O2GTableManager.
The usage of the O2GTable
class is similar to the usage of the O2GGenericTableResponseReader
class: it can not be instantiated directly and you can use its methods
only on the following subclasses:
O2GOffersTable
O2GAccountsTable
O2GTradesTable
O2GClosedTradesTable
O2GOrdersTable
O2GMessagesTable
O2GSummaryTable
If initial trading table information is received as a response to the
O2GLoginRules.getTableRefreshResponse request, you can process the response in
the main thread of your program.
If initial trading table information is received as a response to the
O2GRequestFactory.createRefreshTableRequest, you must process the response in
your implementation of the IO2GResponseListener.onRequestCompleted method.
Example
Get initial accounts and trades information [show]
Get initial accounts and trades information [hide]
// Get accounts information
public static void getAccounts(O2GSession session, ResponseListener responseListener) {
try {
O2GLoginRules loginRules = session.getLoginRules();
if (loginRules != null & loginRules.isTableLoadedByDefault(O2GTableType.ACCOUNTS)) {
O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.ACCOUNTS);
O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse);
useGenericReader(accountsReader);
} else {
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory != null) {
O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.ACCOUNTS);
responseListener.setRequest(request.getRequestId());
session.sendRequest(request);
Thread.sleep(1000);
}
}
} catch (Exception e) {
System.out.println("Exception in getAccounts().\n\t " + e.getMessage());
}
}
// Get trades information
public static void getTrades(O2GSession session, ResponseListener responseListener) {
try {
O2GLoginRules loginRules = session.getLoginRules();
if (loginRules != null & loginRules.isTableLoadedByDefault(O2GTableType.TRADES)) {
O2GResponse tradesResponse = loginRules.getTableRefreshResponse(O2GTableType.TRADES);
O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
O2GTradesTableResponseReader tradesReader = responseFactory.createTradesTableReader(tradesResponse);
useGenericReader(tradesReader);
} else {
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory != null) {
O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.TRADES);
responseListener.setRequest(request.getRequestId());
session.sendRequest(request);
Thread.sleep(1000);
}
}
} catch (Exception e) {
System.out.println("Exception in getTrades().\n\t " + e.getMessage());
}
}
// Use generic reader
public static void useGenericReader(O2GGenericTableResponseReader genericReader) {
int columnsCount = 0;
System.out.println("\n\nThis is a response to your " + genericReader.getType() + " table refresh request.\n");
O2GTableColumnCollection columns = genericReader.getColumns();
columnsCount = columns.size();
for (int j = 0; j < columnsCount; j++) {
O2GTableColumn column = columns.get(j);
System.out.println("" + column.getId() + " " + column.getType());
for (int i = 0; i < genericReader.size(); i++) {
Object value = genericReader.getCell(i, j);
System.out.println("Value: " + value);
}
}
}
// Implementation of IO2GResponseListener interface public method onRequestCompleted
public void onRequestCompleted(String requestID, O2GResponse response) {
int columnsCount = 0;
O2GGenericTableResponseReader reader = null;
if (requestID.equals(mRequestID)) {
O2GResponseReaderFactory readerFactory = mSession.getResponseReaderFactory();
if (readerFactory != null) {
switch (response.getType()) {
case GET_ACCOUNTS: {
reader = readerFactory.createAccountsTableReader(response);
}
case GET_TRADES: {
reader = readerFactory.createTradesTableReader(response);
}
System.out.println("\n\nThis is a response to your " + reader.getType() + " request.\n");
O2GTableColumnCollection columns = reader.getColumns();
columnsCount = columns.size();
for (int j = 0; j < columnsCount; j++) {
O2GTableColumn column = columns.get(j);
System.out.println("" + column.getId() + " " + column.getType());
for (int i = 0; i < reader.size(); i++) {
Object value = reader.getCell(i, j);
System.out.println("Value: " + value);
}
}
}
}
}
}
The namespace is com.fxcore2
.
Public Methods |
getCell
|
Gets the value of a cell.
|
getColumns
|
Gets an instance of the class that provides access to the list of table columns.
|
getGenericRow
|
Gets a row by its index.
|
getType
|
Gets the type of a trading table.
|
isCellValid
|
Checks whether the cell value can be used or not.
|
size
|
Gets the number of rows in the reader.
|
back