void parse_ref_response(Message message, double** data){ Element ReferenceDataResponse = message.asElement(); ReferenceDataResponse.print(std::cout); if (ReferenceDataResponse.hasElement("responseError")){ OutputDebugString(L"ERROR"); return; } Element securityDataArray = message.getElement("securityData"); int numItems = securityDataArray.numValues(); double array[11]; int sequenceNum; for (int i = 0; i < numItems; i++){ Element securityData = securityDataArray.getValueAsElement(i); sequenceNum = securityData.getElementAsInt32("sequenceNumber"); Element fieldData = securityData.getElement("fieldData"); Datetime maturity = fieldData.getElementAsDatetime("MATURITY"); array[0] = (maturity.year()); //0 array[1] = (maturity.month()); //1 array[2] = (maturity.day()); //2 Datetime issue_dt = fieldData.getElementAsDatetime("ISSUE_DT"); array[3] = (maturity.year() - issue_dt.year()); //3 //newRow.push_back(issue_dt.month()); //newRow.push_back(issue_dt.day()); array[4] = (fieldData.getElementAsFloat64("DUR_ADJ_MID")); //4 array[5] = (fieldData.getElementAsFloat64("LAST_PRICE")); //5 array[6] = (fieldData.getElementAsFloat64("PX_LAST_EOD")); //6 array[7] = (fieldData.getElementAsFloat64("YLD_YTM_MID")); //7 array[8] = (fieldData.getElementAsFloat64("ASSET_SWAP_SPD_MID")); //8 array[9] = (fieldData.getElementAsFloat64("BB_Z_SPREAD_TO_OIS_DISC_MID")); //9 array[10] = (fieldData.getElementAsFloat64("BB_Z_SPREAD_TO_OIS_DISC_MID")); //10 } for (int j = 0; j < 11; j++){ data[sequenceNum][j] = array[j]; } }
void processMessage(Message &msg) { Element data = msg.getElement(BAR_DATA).getElement(BAR_TICK_DATA); int numBars = data.numValues(); std::cout <<"Response contains " << numBars << " bars" << std::endl; std::cout <<"Datetime\t\tOpen\t\tHigh\t\tLow\t\tClose" << "\t\tNumEvents\tVolume" << std::endl; for (int i = 0; i < numBars; ++i) { Element bar = data.getValueAsElement(i); Datetime time = bar.getElementAsDatetime(TIME); assert(time.hasParts(DatetimeParts::DATE | DatetimeParts::HOURS | DatetimeParts::MINUTES)); double open = bar.getElementAsFloat64(OPEN); double high = bar.getElementAsFloat64(HIGH); double low = bar.getElementAsFloat64(LOW); double close = bar.getElementAsFloat64(CLOSE); int numEvents = bar.getElementAsInt32(NUM_EVENTS); long long volume = bar.getElementAsInt64(VOLUME); std::cout.setf(std::ios::fixed, std::ios::floatfield); std::cout << time.month() << '/' << time.day() << '/' << time.year() << " " << time.hours() << ":" << time.minutes() << "\t\t" << std::showpoint << std::setprecision(3) << open << "\t\t" << high << "\t\t" << low << "\t\t" << close << "\t\t" << numEvents << "\t\t" << std::noshowpoint << volume << std::endl; } }
const double bbgDatetimeToPOSIX(const Datetime& dt) { boost::gregorian::date bbg_boost_date(dt.year(),dt.month(),dt.day()); boost::posix_time::time_duration td = boost::posix_time::hours(dt.hours()) + boost::posix_time::minutes(dt.minutes()) + boost::posix_time::seconds(dt.seconds()) + boost::posix_time::milliseconds(dt.milliseconds()); boost::posix_time::ptime bbg_ptime(bbg_boost_date,td); struct tm tm_time(to_tm(bbg_ptime)); return static_cast<double>(mktime(&tm_time)); }
Datetime Datetime::today() { Datetime x = Datetime::now(); return Datetime(x.year(), x.month(), x.day()); }
const double bbgDateToPOSIX(const Datetime& bbg_date) { boost::gregorian::date bbg_boost_date(bbg_date.year(),bbg_date.month(),bbg_date.day()); struct tm tm_time(to_tm(bbg_boost_date)); return static_cast<double>(mktime(&tm_time)); }
const int bbgDateToJulianDate(const Datetime& bbg_date) { const boost::gregorian::date r_epoch(1970,1,1); boost::gregorian::date bbg_boost_date(bbg_date.year(),bbg_date.month(),bbg_date.day()); boost::gregorian::date_period dp(r_epoch,bbg_boost_date); return static_cast<int>(dp.length().days()); }