本文整理汇总了C++中O2G2Ptr::getTimeFrameCollection方法的典型用法代码示例。如果您正苦于以下问题:C++ O2G2Ptr::getTimeFrameCollection方法的具体用法?C++ O2G2Ptr::getTimeFrameCollection怎么用?C++ O2G2Ptr::getTimeFrameCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类O2G2Ptr
的用法示例。
在下文中一共展示了O2G2Ptr::getTimeFrameCollection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}