本文整理汇总了C++中O2G2Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ O2G2Ptr类的具体用法?C++ O2G2Ptr怎么用?C++ O2G2Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了O2G2Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printResult
void ResponseListener::printResult()
{
if (mOrderMonitorNetting)
{
OrderMonitorNetting::ExecutionResult result = mOrderMonitorNetting->getResult();
std::vector<IO2GTradeRow*> trades;
std::vector<IO2GTradeRow*> updatedTrades;
std::vector<IO2GClosedTradeRow*> closedTrades;
O2G2Ptr<IO2GOrderRow> order = mOrderMonitorNetting->getOrder();
std::string orderID = order->getOrderID();
mOrderMonitorNetting->getTrades(trades);
mOrderMonitorNetting->getUpdatedTrades(updatedTrades);
mOrderMonitorNetting->getClosedTrades(closedTrades);
switch (result)
{
case OrderMonitorNetting::Canceled:
{
if (trades.size() > 0)
{
printTrades(trades, orderID);
printUpdatedTrades(updatedTrades, orderID);
printClosedTrades(closedTrades, orderID);
std::cout << "A part of the order has been canceled. "
<< "Amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
}
else
{
std::cout << "The order: OrderID=" << orderID << " has been canceled" << std::endl;
std::cout << "The cancel amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
}
}
break;
case OrderMonitorNetting::FullyRejected:
{
std::cout << "The order has been rejected. OrderID = " << orderID << std::endl;
std::cout << "The rejected amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;;
std::cout << "Rejection cause: " << mOrderMonitorNetting->getRejectMessage() << std::endl;
}
break;
case OrderMonitorNetting::PartialRejected:
{
printTrades(trades, orderID);
printUpdatedTrades(updatedTrades, orderID);
printClosedTrades(closedTrades, orderID);
std::cout << "A part of the order has been rejected. "
<< "Amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
std::cout << "Rejection cause: " << mOrderMonitorNetting->getRejectMessage() << std::endl;
}
break;
case OrderMonitorNetting::Executed:
{
printTrades(trades, orderID);
printUpdatedTrades(updatedTrades, orderID);
printClosedTrades(closedTrades, orderID);
}
break;
}
}
}
示例2: BOOST_LOG_TRIVIAL
std::vector<Prices> ForexConnectClient::getPricesFromResponse(IO2GResponse* response)
{
std::vector<Prices> prices;
if (!response || response->getType() != MarketDataSnapshot)
{
return prices;
}
BOOST_LOG_TRIVIAL(debug) << "Request with RequestID='" << response->getRequestID() << "' is completed:";
O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = mpResponseReaderFactory->createMarketDataSnapshotReader(response);
if (!reader)
{
return prices;
}
for (int ii = reader->size() - 1; ii >= 0; ii--)
{
DATE dt = reader->getDate(ii);
if (reader->isBar())
{
prices.push_back(Prices(toPtime(dt),
reader->getAskOpen(ii),
reader->getAskHigh(ii),
reader->getAskLow(ii),
reader->getAskClose(ii)));
}
else
{
prices.push_back(Prices(toPtime(dt),
reader->getAsk(ii)));
}
}
return prices;
}
示例3: printOrders
// Print orders table using IO2GEachRowListener
void printOrders(IO2GTableManager *tableManager, const char *sAccountID)
{
O2G2Ptr<IO2GOrdersTable> ordersTable = (IO2GOrdersTable *)tableManager->getTable(Orders);
if (ordersTable->size() == 0)
{
std::cout << "Table is empty!" << std::endl;
}
else
{
ordersTable->forEachRow(new EachRowListener(sAccountID));
}
}
示例4: printTrades
void TableListener::printTrades(std::vector<IO2GTradeRow*> &trades, std::string &sOrderID)
{
if (trades.size() == 0)
return;
std::cout << "For the order: OrderID=" << sOrderID << " the following positions have been opened: " << std::endl;
for (size_t i = 0; i < trades.size(); ++i)
{
O2G2Ptr<IO2GTradeRow> trade = trades[i];
std::string tradeID = trade->getTradeID();
int amount = trade->getAmount();
double rate = trade->getOpenRate();
std::cout << "Trade ID: " << tradeID << ", "
<< "Amount: " << amount << ", "
<< "Rate: " << rate << std::endl;
}
}
示例5: unsubscribeEvents
void TableListener::unsubscribeEvents(IO2GTableManager *manager)
{
O2G2Ptr<IO2GAccountsTable> accountsTable = (IO2GAccountsTable *)manager->getTable(Accounts);
O2G2Ptr<IO2GOrdersTable> ordersTable = (IO2GOrdersTable *)manager->getTable(Orders);
O2G2Ptr<IO2GTradesTable> tradesTable = (IO2GTradesTable *)manager->getTable(Trades);
O2G2Ptr<IO2GMessagesTable> messagesTable = (IO2GMessagesTable *)manager->getTable(Messages);
O2G2Ptr<IO2GClosedTradesTable> closedTradesTable = (IO2GClosedTradesTable *)manager->getTable(ClosedTrades);
accountsTable->unsubscribeUpdate(Update, this);
ordersTable->unsubscribeUpdate(Insert, this);
ordersTable->unsubscribeUpdate(Delete, this);
tradesTable->unsubscribeUpdate(Insert, this);
tradesTable->unsubscribeUpdate(Update, this);
closedTradesTable->unsubscribeUpdate(Insert, this);
messagesTable->unsubscribeUpdate(Insert, this);
}
示例6: printMargins
// Get and print margin requirements
void printMargins(IO2GSession *session, IO2GAccountRow *account, IO2GOfferRow *offer)
{
O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
if (!loginRules)
{
std::cout << "Cannot create request" << std::endl;
return;
}
O2G2Ptr<IO2GTradingSettingsProvider> tradingSettings = loginRules->getTradingSettingsProvider();
double dMmr = 0;
double dEmr = 0;
double dLmr = 0;
tradingSettings->getMargins(offer->getInstrument(), account, dMmr, dEmr, dLmr);
std::cout << "Margin requirements: MMR=" << std::fixed << dMmr << "; EMR=" << std::fixed << dEmr
<< "; LMR=" << std::fixed << dLmr << std::endl;
}
示例7:
// Subscribe or unsubscribe an instrument
IO2GRequest *createSetSubscriptionStatusRequest(IO2GSession *session, const char *sOfferID, const char *sStatus, ResponseListener *responseListener)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return NULL;
}
O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::SetSubscriptionStatus);
valuemap->setString(SubscriptionStatus, sStatus);
valuemap->setString(OfferID, sOfferID);
O2G2Ptr<IO2GRequest> request = requestFactory->createOrderRequest(valuemap);
if (!request)
{
std::cout << requestFactory->getLastError() << std::endl;
return NULL;
}
return request.Detach();
}
示例8: strcmp
// Find the first opened position by AccountID and OfferID
IO2GTradeRow *getTrade(IO2GTableManager *tableManager, const char *sAccountID, const char *sOfferID)
{
O2G2Ptr<IO2GTradesTable> tradesTable = (IO2GTradesTable *)tableManager->getTable(Trades);
for (int i = 0; i < tradesTable->size(); ++i)
{
O2G2Ptr<IO2GTradeRow> trade = tradesTable->getRow(i);
if (strcmp(sAccountID, trade->getAccountID()) == 0 &&
strcmp(sOfferID, trade->getOfferID()) == 0)
return trade.Detach();
}
return NULL;
}
示例9: SessionStatusListener
void ForexConnectClient::init()
{
mpSession = CO2GTransport::createSession();
mpListener = new SessionStatusListener(mpSession, false);
mpSession->subscribeSessionStatus(mpListener);
mpSession->useTableManager(Yes, 0);
if (!login())
{
throw std::runtime_error("Login fail.");
}
mpLoginRules = mpSession->getLoginRules();
if (!mpLoginRules->isTableLoadedByDefault(Accounts))
{
logout();
throw std::runtime_error("Accounts table not loaded");
}
O2G2Ptr<IO2GResponse> response = mpLoginRules->getTableRefreshResponse(Accounts);
if(!response)
{
logout();
throw std::runtime_error("No response to refresh accounts table request");
}
mpResponseReaderFactory = mpSession->getResponseReaderFactory();
O2G2Ptr<IO2GAccountsTableResponseReader> accountsResponseReader = mpResponseReaderFactory->createAccountsTableReader(response);
mpAccountRow = accountsResponseReader->getRow(0);
mAccountID = mpAccountRow->getAccountID();
mpResponseListener = new ResponseListener(mpSession);
mpSession->subscribeResponse(mpResponseListener);
mpRequestFactory = mpSession->getRequestFactory();
}
示例10:
IO2GRequest *createEntryOrderRequest(IO2GSession *session, const char *sOfferID, const char *sAccountID, int iAmount, double dRate, const char *sBuySell, const char *sOrderType, const char *expDate)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return NULL;
}
O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::CreateOrder);
valuemap->setString(OrderType, sOrderType);
valuemap->setString(AccountID, sAccountID);
valuemap->setString(OfferID, sOfferID);
valuemap->setString(BuySell, sBuySell);
valuemap->setInt(Amount, iAmount);
valuemap->setDouble(Rate, dRate);
valuemap->setString(CustomID, "EntryOrder");
if(strcmp(expDate, "") != 0)
{
valuemap->setString(TimeInForce, "GTD"); // 'Good till Date'
valuemap->setString(ExpireDateTime, expDate); // FIX UTCTimestamp format: "yyyyMMdd- HH:mm:ss.SSS" (milliseconds are optional)
}
O2G2Ptr<IO2GRequest> request = requestFactory->createOrderRequest(valuemap);
if (!request)
{
std::cout << requestFactory->getLastError() << std::endl;
return NULL;
}
return request.Detach();
}
示例11: main
int main(int argc, char *argv[])
{
std::string procName = "CreateEntry";
if (argc == 1)
{
printHelp(procName);
return -1;
}
bool bWasError = false;
LoginParams *loginParams = new LoginParams(argc, argv);
SampleParams *sampleParams = new SampleParams(argc, argv);
printSampleParams(procName, loginParams, sampleParams);
if (!checkObligatoryParams(loginParams, sampleParams))
return -1;
IO2GSession *session = CO2GTransport::createSession();
SessionStatusListener *sessionListener = new SessionStatusListener(session, true,
loginParams->getSessionID(),
loginParams->getPin());
session->subscribeSessionStatus(sessionListener);
bool bConnected = login(session, sessionListener, loginParams);
if (bConnected)
{
bool bIsAccountEmpty = !sampleParams->getAccount() || strlen(sampleParams->getAccount()) == 0;
O2G2Ptr<IO2GAccountRow> account = getAccount(session, sampleParams->getAccount());
ResponseListener *responseListener = new ResponseListener(session);
session->subscribeResponse(responseListener);
if (account)
{
if (bIsAccountEmpty)
{
sampleParams->setAccount(account->getAccountID());
std::cout << "Account: " << sampleParams->getAccount() << std::endl;
}
O2G2Ptr<IO2GOfferRow> offer = getOffer(session, sampleParams->getInstrument());
if (offer)
{
O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
if (loginRules)
{
O2G2Ptr<IO2GTradingSettingsProvider> tradingSettingsProvider = loginRules->getTradingSettingsProvider();
int iBaseUnitSize = tradingSettingsProvider->getBaseUnitSize(sampleParams->getInstrument(), account);
int iAmount = iBaseUnitSize * sampleParams->getLots();
int iCondDistEntryLimit = tradingSettingsProvider->getCondDistEntryLimit(sampleParams->getInstrument());
int iCondDistEntryStop = tradingSettingsProvider->getCondDistEntryStop(sampleParams->getInstrument());
std::string sOrderType = getEntryOrderType(offer->getBid(), offer->getAsk(), sampleParams->getRate(),
sampleParams->getBuySell(), offer->getPointSize(), iCondDistEntryLimit, iCondDistEntryStop);
O2G2Ptr<IO2GRequest> request = createEntryOrderRequest(session, offer->getOfferID(), account->getAccountID(), iAmount,
sampleParams->getRate(), sampleParams->getBuySell(), sOrderType.c_str(), sampleParams->getExpDate());
if (request)
{
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (responseListener->waitEvents())
{
std::cout << "Done!" << std::endl;
}
else
{
std::cout << "Response waiting timeout expired" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "Cannot create request" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "Cannot get login rules" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "The instrument '" << sampleParams->getInstrument() << "' is not valid" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "No valid accounts" << std::endl;
bWasError = true;
}
session->unsubscribeResponse(responseListener);
responseListener->release();
logout(session, sessionListener);
}
else
//.........这里部分代码省略.........
示例12: onTablesUpdates
/** Request update data received data handler. */
void ResponseListener::onTablesUpdates(IO2GResponse *data)
{
if (data)
{
O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
if (factory)
{
O2G2Ptr<IO2GTablesUpdatesReader> reader = factory->createTablesUpdatesReader(data);
if (reader)
{
for (int i = 0; i < reader->size(); ++i)
{
if (reader->getUpdateTable(i) == Orders)
{
O2G2Ptr<IO2GOrderRow> order = reader->getOrderRow(i);
if (reader->getUpdateType(i) == Insert)
{
if (mRequestID == order->getRequestID())
{
std::cout << "The order has been added. OrderID='" << order->getOrderID() << "', "
<< "Type='" << order->getType() << "', "
<< "BuySell='" << order->getBuySell() << "', "
<< "Rate='" << order->getRate() << "', "
<< "TimeInForce='" << order->getTimeInForce() << "'"
<< std::endl;
SetEvent(mResponseEvent);
}
}
}
}
}
}
}
}
示例13:
IO2GRequest *createNetEntryOrderRequest(IO2GSession *session, const char *sOfferID,
const char *sAccountID, double dRate, const char *sBuySell, const char *sOrderType)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return NULL;
}
O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::CreateOrder);
valuemap->setString(OrderType, sOrderType);
valuemap->setString(AccountID, sAccountID);
valuemap->setString(OfferID, sOfferID);
valuemap->setString(BuySell, sBuySell);
valuemap->setString(NetQuantity, "Y");
valuemap->setDouble(Rate, dRate);
valuemap->setString(CustomID, "EntryOrder");
O2G2Ptr<IO2GRequest> request = requestFactory->createOrderRequest(valuemap);
if (!request)
{
std::cout << requestFactory->getLastError() << std::endl;
return NULL;
}
return request.Detach();
}
示例14: main
int main(int argc, char* argv[])
{
std::string procName = "CloseAllPositionsByInstrument";
if (argc == 1)
{
printHelp(procName);
return -1;
}
LoginParams *loginParams = new LoginParams(argc, argv);
SampleParams *sampleParams = new SampleParams(argc, argv);
printSampleParams(procName, loginParams, sampleParams);
if (!checkObligatoryParams(loginParams, sampleParams))
return -1;
IO2GSession *session = CO2GTransport::createSession();
SessionStatusListener *sessionListener = new SessionStatusListener(session, false,
loginParams->getSessionID(),
loginParams->getPin());
session->subscribeSessionStatus(sessionListener);
bool bConnected = login(session, sessionListener, loginParams);
bool bWasError = false;
if (bConnected)
{
bool bIsAccountEmpty = !sampleParams->getAccount() || strlen(sampleParams->getAccount()) == 0;
O2G2Ptr<IO2GAccountRow> account = getAccount(session, sampleParams->getAccount());
ResponseListener *responseListener = new ResponseListener(session);
session->subscribeResponse(responseListener);
if (account)
{
if (bIsAccountEmpty)
{
sampleParams->setAccount(account->getAccountID());
std::cout << "Account: " << sampleParams->getAccount() << std::endl;
}
O2G2Ptr<IO2GOfferRow> offer = getOffer(session, sampleParams->getInstrument());
if (offer)
{
CloseOrderData closeOrdersData;
if (getCloseOrdersData(session, responseListener, sampleParams->getAccount(), offer->getOfferID(), closeOrdersData))
{
O2G2Ptr<IO2GRequest> request = createCloseMarketNettingOrderRequest(session, &closeOrdersData);
if (request)
{
std::vector<std::string> requestIDs(request->getChildrenCount());
for (int i = 0; i < request->getChildrenCount(); ++i)
{
IO2GRequest *requestChild = request->getChildRequest(i);
requestIDs[i] = requestChild->getRequestID();
requestChild->release();
}
responseListener->setRequestIDs(requestIDs);
session->sendRequest(request);
if (responseListener->waitEvents())
{
Sleep(1000); // Wait for the balance update
std::cout << "Done!" << std::endl;
}
else
{
std::cout << "Response waiting timeout expired" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "Cannot create request" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "There are no opened positions for instrument '" <<
sampleParams->getInstrument() << "'" << std::endl;
}
}
else
{
std::cout << "The instrument '" << sampleParams->getInstrument() << "' is not valid" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "No valid accounts" << std::endl;
bWasError = true;
}
session->unsubscribeResponse(responseListener);
responseListener->release();
logout(session, sessionListener);
}
else
{
bWasError = true;
}
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[])
{
std::string procName = "PrintTable";
if (argc == 1)
{
printHelp(procName);
return -1;
}
bool bWasError = false;
LoginParams *loginParams = new LoginParams(argc, argv);
SampleParams *sampleParams = new SampleParams(argc, argv);
printSampleParams(procName, loginParams, sampleParams);
if (!checkObligatoryParams(loginParams, sampleParams))
return -1;
IO2GSession *session = CO2GTransport::createSession();
session->useTableManager(Yes, 0);
SessionStatusListener *sessionListener = new SessionStatusListener(session, true,
loginParams->getSessionID(),
loginParams->getPin());
session->subscribeSessionStatus(sessionListener);
bool bConnected = login(session, sessionListener, loginParams);
if (bConnected)
{
bool bIsAccountEmpty = !sampleParams->getAccount() || strlen(sampleParams->getAccount()) == 0;
O2G2Ptr<IO2GTableManager> tableManager = session->getTableManager();
O2GTableManagerStatus managerStatus = tableManager->getStatus();
while (managerStatus == TablesLoading)
{
Sleep(50);
managerStatus = tableManager->getStatus();
}
if (managerStatus == TablesLoadFailed)
{
std::cout << "Cannot refresh all tables of table manager" << std::endl;
}
O2G2Ptr<IO2GAccountRow> account = getAccount(tableManager, sampleParams->getAccount());
if (account)
{
if (bIsAccountEmpty)
{
sampleParams->setAccount(account->getAccountID());
std::cout << "Account: " << sampleParams->getAccount() << std::endl;
}
}
else
{
std::cout << "No valid accounts" << std::endl;
bWasError = true;
}
printOrders(tableManager, sampleParams->getAccount());
std::cout << "Done!" << std::endl;
logout(session, sessionListener);
}
else
{
bWasError = true;
}
session->unsubscribeSessionStatus(sessionListener);
sessionListener->release();
session->release();
if (bWasError)
return -1;
return 0;
}