本文整理汇总了C++中O2G2Ptr::getRequestID方法的典型用法代码示例。如果您正苦于以下问题:C++ O2G2Ptr::getRequestID方法的具体用法?C++ O2G2Ptr::getRequestID怎么用?C++ O2G2Ptr::getRequestID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类O2G2Ptr
的用法示例。
在下文中一共展示了O2G2Ptr::getRequestID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
}
}
}
}
}
示例2: updateMargins
// Update margin requirements
void updateMargins(IO2GSession *session, ResponseListener *responseListener)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return;
}
O2G2Ptr<IO2GValueMap> valuemap = requestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::UpdateMarginRequirements);
O2G2Ptr<IO2GRequest> request = requestFactory->createOrderRequest(valuemap);
if (!request)
{
std::cout << requestFactory->getLastError() << std::endl;
return;
}
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (!responseListener->waitEvents())
{
std::cout << "Response waiting timeout expired" << std::endl;
return;
}
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
if (response && response->getType() == MarginRequirementsResponse)
{
O2G2Ptr<IO2GResponseReaderFactory> responseFactory = session->getResponseReaderFactory();
if (responseFactory)
{
responseFactory->processMarginRequirementsResponse(response);
std::cout << "Margin requirements have been updated" << std::endl;
}
}
}
示例3: getHistoryPrices
bool getHistoryPrices(IO2GSession *session, const char *sInstrument, const char *sTimeframe, DATE dtFrom, DATE dtTo, ResponseListener *responseListener)
{
O2G2Ptr<IO2GRequestFactory> factory = session->getRequestFactory();
if (!factory)
{
std::cout << "Cannot create request factory" << std::endl;
return false;
}
//find timeframe by identifier
O2G2Ptr<IO2GTimeframeCollection> timeframeCollection = factory->getTimeFrameCollection();
O2G2Ptr<IO2GTimeframe> timeframe = timeframeCollection->get(sTimeframe);
if (!timeframe)
{
std::cout << "Timeframe '" << sTimeframe << "' is incorrect!" << std::endl;
return false;
}
O2G2Ptr<IO2GRequest> request = factory->createMarketDataSnapshotRequestInstrument(sInstrument, timeframe, timeframe->getQueryDepth());
DATE dtFirst = dtTo;
// there is limit for returned candles amount
do
{
factory->fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (!responseListener->waitEvents())
{
std::cout << "Response waiting timeout expired" << std::endl;
return false;
}
// shift "to" bound to oldest datetime of returned data
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
if (response && response->getType() == MarketDataSnapshot)
{
O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
if (readerFactory)
{
O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = readerFactory->createMarketDataSnapshotReader(response);
if (reader->size() > 0)
{
if (abs(dtFirst - reader->getDate(0)) > 0.0001)
dtFirst = reader->getDate(0); // earliest datetime of returned data
else
break;
}
else
{
std::cout << "0 rows received" << std::endl;
break;
}
}
printPrices(session, response);
}
else
{
break;
}
} while (dtFirst - dtFrom > 0.0001);
return true;
}
示例4: toOleTime
std::vector<Prices> ForexConnectClient::getHistoricalPrices(const std::string& instrument,
const boost::posix_time::ptime& from,
const boost::posix_time::ptime& to,
const std::string& timeFrame)
{
std::vector<Prices> prices;
O2G2Ptr<IO2GTimeframeCollection> timeframeCollection = mpRequestFactory->getTimeFrameCollection();
O2G2Ptr<IO2GTimeframe> timeframe = timeframeCollection->get(timeFrame.c_str());
if (!timeframe)
{
BOOST_LOG_TRIVIAL(error) << "Timeframe '" << timeFrame << "' is incorrect!";
return prices;
}
O2G2Ptr<IO2GRequest> request = mpRequestFactory->createMarketDataSnapshotRequestInstrument(instrument.c_str(),
timeframe,
timeframe->getQueryDepth());
DATE dtFrom = toOleTime(from);
DATE dtTo = toOleTime(to);
DATE dtFirst = dtTo;
do
{
mpRequestFactory->fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
mpResponseListener->setRequestID(request->getRequestID());
mpSession->sendRequest(request);
if (!mpResponseListener->waitEvents())
{
BOOST_LOG_TRIVIAL(error) << "Response waiting timeout expired";
return prices;
}
// shift "to" bound to oldest datetime of returned data
O2G2Ptr<IO2GResponse> response = mpResponseListener->getResponse();
if (response && response->getType() == MarketDataSnapshot)
{
O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = mpResponseReaderFactory->createMarketDataSnapshotReader(response);
if (reader->size() > 0)
{
if (fabs(dtFirst - reader->getDate(0)) > 0.0001)
dtFirst = reader->getDate(0); // earliest datetime of returned data
else
break;
}
else
{
BOOST_LOG_TRIVIAL(warning) << "0 rows received";
break;
}
std::vector<Prices> prc = getPricesFromResponse(response);
prices.insert(prices.end(), prc.begin(), prc.end());
}
else
{
break;
}
} while (dtFirst - dtFrom > 0.0001);
return prices;
}
示例5: getCloseOrdersData
bool getCloseOrdersData(IO2GSession *session, ResponseListener *responseListener, const char *sAccountID, const char *sOfferID, CloseOrderData &closeOrdersData)
{
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return false;
}
O2G2Ptr<IO2GRequest> request = requestFactory->createRefreshTableRequestByAccount(Trades, sAccountID);
if (!request)
{
std::cout << requestFactory->getLastError() << std::endl;
return false;
}
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (!responseListener->waitEvents())
{
std::cout << "Response waiting timeout expired" << std::endl;
return false;
}
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
bool bIsTradesFound = false;
if (response)
{
O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
O2G2Ptr<IO2GTradesTableResponseReader> responseReader = readerFactory->createTradesTableReader(response);
for (int i = 0; i < responseReader->size(); ++i)
{
O2G2Ptr<IO2GTradeRow> trade = responseReader->getRow(i);
if (strcmp(sOfferID, trade->getOfferID()) != 0)
continue;
bIsTradesFound = true;
std::string sBuySell = trade->getBuySell();
// Set opposite side
OrderSide side = (sBuySell == O2G2::Buy) ? Sell : Buy;
if (closeOrdersData.offerID != sOfferID)
{
closeOrdersData.offerID = sOfferID;
closeOrdersData.account = sAccountID;
closeOrdersData.side = side;
}
else
{
OrderSide currentSide = closeOrdersData.side;
if (currentSide != Both && currentSide != side)
closeOrdersData.side = Both;
}
}
}
return bIsTradesFound;
}
示例6: openPosition
bool ForexConnectClient::openPosition(const std::string& instrument,
const std::string& buysell,
int amount)
{
if (buysell != O2G2::Sell && buysell != O2G2::Buy)
{
return false;
}
std::map<std::string, std::string> offers = getOffers();
std::string offerID;
std::map<std::string, std::string>::const_iterator offer_itr = offers.find(instrument);
if (offer_itr != offers.end()) {
offerID = offer_itr->second;
} else {
BOOST_LOG_TRIVIAL(error) << "Could not find offer row for instrument " << instrument;
return false;
}
O2G2Ptr<IO2GTradingSettingsProvider> tradingSettingsProvider = mpLoginRules->getTradingSettingsProvider();
int iBaseUnitSize = tradingSettingsProvider->getBaseUnitSize(instrument.c_str(), mpAccountRow);
O2G2Ptr<IO2GValueMap> valuemap = mpRequestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::CreateOrder);
valuemap->setString(OrderType, O2G2::Orders::TrueMarketOpen);
valuemap->setString(AccountID, mAccountID.c_str());
valuemap->setString(OfferID, offerID.c_str());
valuemap->setString(BuySell, buysell.c_str());
valuemap->setInt(Amount, amount * iBaseUnitSize);
valuemap->setString(TimeInForce, O2G2::TIF::IOC);
valuemap->setString(CustomID, "TrueMarketOrder");
O2G2Ptr<IO2GRequest> request = mpRequestFactory->createOrderRequest(valuemap);
if (!request)
{
BOOST_LOG_TRIVIAL(error) << mpRequestFactory->getLastError();
return false;
}
mpResponseListener->setRequestID(request->getRequestID());
mpSession->sendRequest(request);
if (mpResponseListener->waitEvents())
{
Sleep(1000); // Wait for the balance update
BOOST_LOG_TRIVIAL(info) << "Done!";
return true;
}
BOOST_LOG_TRIVIAL(error) << "Response waiting timeout expired";
return false;
}
示例7: closePosition
bool ForexConnectClient::closePosition(const std::string& tradeID)
{
TableHandler<Trades, IO2GTradesTable, IO2GTradeTableRow> handler(mpSession);
IO2GTradeTableRow *tradeRow = NULL;
IO2GTableIterator tableIterator;
while (true) {
tradeRow = handler.getNextRow();
if (!tradeRow) {
BOOST_LOG_TRIVIAL(error) << "Could not find trade with ID = " << tradeID;
return false;
}
if (tradeID == tradeRow->getTradeID()) {
break;
}
}
O2G2Ptr<IO2GValueMap> valuemap = mpRequestFactory->createValueMap();
valuemap->setString(Command, O2G2::Commands::CreateOrder);
valuemap->setString(OrderType, O2G2::Orders::TrueMarketClose);
valuemap->setString(AccountID, mAccountID.c_str());
valuemap->setString(OfferID, tradeRow->getOfferID());
valuemap->setString(TradeID, tradeID.c_str());
valuemap->setString(BuySell, (strcmp(tradeRow->getBuySell(), O2G2::Buy) == 0) ? O2G2::Sell : O2G2::Buy);
valuemap->setInt(Amount, tradeRow->getAmount());
valuemap->setString(CustomID, "CloseMarketOrder");
O2G2Ptr<IO2GRequest> request = mpRequestFactory->createOrderRequest(valuemap);
if (!request)
{
BOOST_LOG_TRIVIAL(error) << mpRequestFactory->getLastError();
return false;
}
mpResponseListener->setRequestID(request->getRequestID());
mpSession->sendRequest(request);
if (mpResponseListener->waitEvents())
{
Sleep(1000); // Wait for the balance update
BOOST_LOG_TRIVIAL(info) << "Done!";
return true;
}
BOOST_LOG_TRIVIAL(error) << "Response waiting timeout expired";
return false;
}
示例8: isOrderExists
bool isOrderExists(IO2GSession *session, const char *sAccountID, const char *sOrderID, ResponseListener *responseListener)
{
if (!session || !responseListener || !sAccountID)
return false;
O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
if (!requestFactory)
{
std::cout << "Cannot create request factory" << std::endl;
return false;
}
O2G2Ptr<IO2GRequest> request = requestFactory->createRefreshTableRequestByAccount(Orders, sAccountID);
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (!responseListener->waitEvents())
{
std::cout << "Response waiting timeout expired" << std::endl;
return false;
}
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
if (response)
{
O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
if (readerFactory)
{
O2G2Ptr<IO2GOrdersTableResponseReader> ordersResponseReader = readerFactory->createOrdersTableReader(response);
for (int i = 0; i < ordersResponseReader->size(); ++i)
{
O2G2Ptr<IO2GOrderRow> order = ordersResponseReader->getRow(i);
if (sOrderID && strcmp(order->getOrderID(), sOrderID) == 0)
return true;
}
}
}
return false;
}
示例9: 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
//.........这里部分代码省略.........
示例10: main
int main(int argc, char *argv[])
{
std::string procName = "GetLastOrderUpdate";
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))
{
delete loginParams;
delete 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();
O2G2Ptr<IO2GRequest> request = createTrueMarketOrderRequest(session, offer->getOfferID(), account->getAccountID(), iAmount, sampleParams->getBuySell());
if (request)
{
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (responseListener->waitEvents())
{
std::string sOrderID = responseListener->getOrderID();
if (!sOrderID.empty())
{
O2G2Ptr<IO2GRequest> updateRequest = getLastOrderUpdateRequest(session, sOrderID.c_str(), account->getAccountName());
if (updateRequest)
{
responseListener->setRequestID(updateRequest->getRequestID());
session->sendRequest(updateRequest);
if (responseListener->waitEvents())
{
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
if (response && response->getType() == GetLastOrderUpdate)
{
O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
if (readerFactory)
{
O2G2Ptr<IO2GLastOrderUpdateResponseReader> reader = readerFactory->createLastOrderUpdateResponseReader(response);
char sTime[20];
formatDate(reader->getOrder()->getStatusTime(), sTime);
std::cout << "Last order update: UpdateType='" << reader->getUpdateType() << "', "
<< "OrderID='" << reader->getOrder()->getOrderID() << "', "
<< "Status='" << reader->getOrder()->getStatus() << "', "
<< "StatusTime='" << sTime << "'"
<< std::endl;
}
}
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;
}
}
//.........这里部分代码省略.........
示例11: 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)
{
switch (reader->getUpdateTable(i))
{
case Orders:
{
O2G2Ptr<IO2GOrderRow> order = reader->getOrderRow(i);
if (mRequestID != order->getRequestID())
break;
switch (reader->getUpdateType(i))
{
case Insert:
if ((isClosingOrder(order) || isOpeningOrder(order)) &&
mOrderMonitorNetting == NULL)
{
std::cout << "The order has been added. OrderID='" << order->getOrderID() << "', "
<< "Rate='" << order->getRate() << "', "
<< "TimeInForce='" << order->getTimeInForce() << "'"
<< std::endl;
O2G2Ptr<IO2GTradeRow> trade = NULL;
std::string sTradeID = std::string(order->getTradeID());
if (mTradesTable)
{
for (int j = 0; j < mTradesTable->size(); ++j)
{
if (sTradeID == mTradesTable->getRow(j)->getTradeID())
{
trade = mTradesTable->getRow(j);
break;
}
}
}
if (trade)
mOrderMonitorNetting = new OrderMonitorNetting(order, trade->getAmount());
else
mOrderMonitorNetting = new OrderMonitorNetting(order, 0);
}
break;
case Delete:
if (mOrderMonitorNetting)
{
std::cout << "The order has been deleted. OrderID='" << order->getOrderID() << "'"
<< std::endl;
mOrderMonitorNetting->onOrderDeleted(order);
if (mOrderMonitorNetting->isOrderCompleted())
{
printResult();
SetEvent(mResponseEvent);
}
}
break;
}
}
break;
case Trades:
{
O2G2Ptr<IO2GTradeRow> trade = reader->getTradeRow(i);
switch (reader->getUpdateType(i))
{
case Insert:
{
if (mOrderMonitorNetting)
{
mOrderMonitorNetting->onTradeAdded(trade);
if (mOrderMonitorNetting->isOrderCompleted())
{
printResult();
SetEvent(mResponseEvent);
}
}
}
break;
case Update:
{
if (mOrderMonitorNetting)
{
mOrderMonitorNetting->onTradeUpdated(trade);
if (mOrderMonitorNetting->isOrderCompleted())
{
printResult();
SetEvent(mResponseEvent);
}
}
}
break;
}
}
break;
case ClosedTrades:
//.........这里部分代码省略.........
示例12: main
int main(int argc, char *argv[])
{
std::string procName = "NetStopLimit";
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();
session->useTableManager(Yes, 0);
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;
ResponseListener *responseListener = new ResponseListener();
TableListener *tableListener = new TableListener(responseListener);
session->subscribeResponse(responseListener);
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;
}
O2G2Ptr<IO2GOfferRow> offer = getOffer(tableManager, sampleParams->getInstrument());
if (offer)
{
O2G2Ptr<IO2GTradeRow> trade = getTrade(tableManager, sampleParams->getAccount(), offer->getOfferID());
if (trade)
{
const char *sBuySell = strcmp(trade->getBuySell(), O2G2::Buy) == 0 ? O2G2::Sell : O2G2::Buy;
O2G2Ptr<IO2GRequest> requestStop = createNetEntryOrderRequest(session, offer->getOfferID(),
account->getAccountID(), sampleParams->getRateStop(), sBuySell, O2G2::Orders::StopEntry);
if (requestStop)
{
tableListener->subscribeEvents(tableManager);
responseListener->setRequestID(requestStop->getRequestID());
tableListener->setRequestID(requestStop->getRequestID());
session->sendRequest(requestStop);
if (responseListener->waitEvents())
{
O2G2Ptr<IO2GRequest> requestLimit = createNetEntryOrderRequest(session, offer->getOfferID(),
account->getAccountID(), sampleParams->getRateLimit(), sBuySell, O2G2::Orders::LimitEntry);
if (requestLimit)
{
responseListener->setRequestID(requestLimit->getRequestID());
tableListener->setRequestID(requestLimit->getRequestID());
session->sendRequest(requestLimit);
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 << "Response waiting timeout expired" << std::endl;
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
std::string procName = "OpenPosition";
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();
session->useTableManager(Yes, 0);
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;
ResponseListener *responseListener = new ResponseListener();
TableListener *tableListener = new TableListener(responseListener);
session->subscribeResponse(responseListener);
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 && strcmp(account->getMaintenanceType(), "0") != 0) // not netting account
{
if (bIsAccountEmpty)
{
sampleParams->setAccount(account->getAccountID());
std::cout << "Account: " << sampleParams->getAccount() << std::endl;
}
O2G2Ptr<IO2GOfferRow> offer = getOffer(tableManager, 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();
O2G2Ptr<IO2GRequest> request = createTrueMarketOrderRequest(session, offer->getOfferID(), account->getAccountID(), iAmount, sampleParams->getBuySell());
if (request)
{
tableListener->subscribeEvents(tableManager);
responseListener->setRequestID(request->getRequestID());
tableListener->setRequestID(request->getRequestID());
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;
}
tableListener->unsubscribeEvents(tableManager);
tableListener->release();
}
else
{
std::cout << "Cannot create request" << std::endl;
bWasError = true;
}
}
else
{
std::cout << "Cannot get login rules" << std::endl;
bWasError = true;
}
//.........这里部分代码省略.........
示例14: main
int main(int argc, char *argv[])
{
std::string procName = "JoinNewGroup";
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();
int iContingencyGroupType = 1; // OCO group
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;
}
std::vector<std::string> orderIDs(2);
orderIDs[0] = sampleParams->getPrimaryID();
orderIDs[1] = sampleParams->getSecondaryID();
for (size_t i=0; i < orderIDs.size(); ++i)
{
if (!isOrderExists(session, sampleParams->getAccount(), orderIDs[i].c_str(), responseListener))
{
std::cout << "Order '" << orderIDs[i] << "' does not exist" << std::endl;
bWasError = true;
}
}
if (!bWasError)
{
O2G2Ptr<IO2GRequest> request = joinToNewGroupRequest(session, sampleParams->getAccount(),
orderIDs, iContingencyGroupType);
if (request)
{
responseListener->setRequestID(request->getRequestID());
responseListener->setOrderIDs(orderIDs);
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 << "No valid accounts" << std::endl;
bWasError = true;
}
session->unsubscribeResponse(responseListener);
responseListener->release();
logout(session, sessionListener);
}
else
{
bWasError = true;
}
session->unsubscribeSessionStatus(sessionListener);
sessionListener->release();
session->release();
if (bWasError)
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[])
{
std::string procName = "SubscriptionStatus";
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 = getOfferAndPrint(session, sampleParams->getInstrument());
if (offer)
{
O2G2Ptr<IO2GRequest> request = createSetSubscriptionStatusRequest(session, offer->getOfferID(), sampleParams->getStatus(), responseListener);
if (request)
{
responseListener->setRequestID(request->getRequestID());
session->sendRequest(request);
if (responseListener->waitEvents())
{
O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
if (response && response->getType() == CommandResponse)
{
printf("Subscription status for '%s' is set to '%s'\n",
sampleParams->getInstrument(), sampleParams->getStatus());
}
printMargins(session, account, offer);
updateMargins(session, responseListener);
printMargins(session, account, offer);
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 << "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;
}
session->unsubscribeSessionStatus(sessionListener);
sessionListener->release();
session->release();
if (bWasError)
return -1;
return 0;
//.........这里部分代码省略.........