void input::run() { //if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); //std::cout << "Connecting to " + d_host + ":" << d_port << std::endl; Session session(sessionOptions); if (!session.start()) { std::cout << "Failed to start session." << std::endl; return; } if (!session.openService("//blp/refdata")) { std::cout << "Failed to open //blp/refdata" << std::endl; return; } sendRefDataRequest(session); // wait for events from session. try { eventLoop(session); } catch (Exception &e) { std::cerr << "Library Exception !!!" << e.description() << std::endl; } catch (...) { std::cerr << "Unknown Exception !!!" << std::endl; } session.stop(); }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::cout <<"Connecting to " << d_host << ":" << d_port << std::endl; Session session(sessionOptions); if (!session.start()) { std::cerr << "Failed to start session." << std::endl; return; } if (!session.openService("//blp/refdata")) { std::cerr << "Failed to open //blp/refdata" << std::endl; return; } sendIntradayTickRequest(session); // wait for events from session. eventLoop(session); session.stop(); }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) { printUsage(); return; } SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::cout << "Connecting to " + d_host + ":" << d_port << std::endl; SessionEventHandler eventHandler(d_identities, d_tokens, d_securities, d_field); Session session(sessionOptions, &eventHandler); if (!session.start()) { std::cerr << "Failed to start session. Exiting..." << std::endl; std::exit(-1); } openServices(&session); EventQueue authQueue; // Authorize all the users that are interested in receiving data if (authorizeUsers(&authQueue, &session)) { // Make the various requests that we need to make session.subscribe(d_subscriptions); } else { std::cerr << "Unable to authorize users, Press Enter to Exit" << std::endl; } // wait for enter key to exit application char dummy[2]; std::cin.getline(dummy,2); { // Check if there were any authorization events received on the // 'authQueue' Event event; while (0 == authQueue.tryNextEvent(&event)) { printEvent(event); } } session.stop(); std::cout << "Exiting...\n"; }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::string authOptions = "AuthenticationType=OS_LOGON"; if (d_useDS) { authOptions = "AuthenticationType=DIRECTORY_SERVICE;DirSvcPropertyName="; authOptions.append(d_DSProperty); } std::cout << "authOptions = " << authOptions << std::endl; sessionOptions.setAuthenticationOptions(authOptions.c_str()); std::cout << "Connecting to " << d_host << ":" << d_port << std::endl; d_session = new Session(sessionOptions); if (!d_session->start()) { std::cerr <<"Failed to start session." << std::endl; return; } if (!d_session->openService("//blp/refdata")) { std::cerr << "Failed to open //blp/refdata" << std::endl; return; } if (!d_session->openService("//blp/apiauth")) { std::cerr << "Failed to open //blp/apiauth" << std::endl; return; } CorrelationId tokenReqId(99); d_session->generateToken(tokenReqId); while (true) { Event event = d_session->nextEvent(); if (event.eventType() == Event::TOKEN_STATUS) { if (!processTokenStatus(event)) { break; } } else { if (!processEvent(event)) { break; } } } }
void run(int argc, char **argv) { d_host = "localhost"; d_port = 8194; if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::cout << "Connecting to " << d_host << ":" << d_port << std::endl; Session session(sessionOptions); if (!session.start()) { std::cerr <<"Failed to start session." << std::endl; return; } if (!session.openService("//blp/refdata")) { std::cerr <<"Failed to open //blp/refdata" << std::endl; return; } Service refDataService = session.getService("//blp/refdata"); Request request = refDataService.createRequest("HistoricalDataRequest"); request.getElement("securities").appendValue("IBM US Equity"); request.getElement("securities").appendValue("MSFT US Equity"); request.getElement("fields").appendValue("PX_LAST"); request.getElement("fields").appendValue("OPEN"); request.set("periodicityAdjustment", "ACTUAL"); request.set("periodicitySelection", "MONTHLY"); request.set("startDate", "20060101"); request.set("endDate", "20061231"); request.set("maxDataPoints", 100); std::cout << "Sending Request: " << request << std:: endl; session.sendRequest(request); while (true) { Event event = session.nextEvent(); MessageIterator msgIter(event); while (msgIter.next()) { Message msg = msgIter.message(); msg.asElement().print(std::cout); std::cout << std::endl; } if (event.eventType() == Event::RESPONSE) { break; } } }
void createSession() { SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::cout << "Connecting to " + d_host + ":" << d_port << std::endl; d_session = new Session(sessionOptions, new SessionEventHandler(d_identities, d_uuids)); bool sessionStarted = d_session->start(); if (!sessionStarted) { std::cerr << "Failed to start session. Exiting..." << std::endl; std::exit(-1); } }
void runRefData(double** refData, double** yesterdayData, std::vector<std::string>bonds){ d_host = "localhost"; d_port = 8194; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); Session session(sessionOptions); if (!session.start()){ std::cout << "Failed to start session" << std::endl; return; } if (!session.openService(APIREFDATA_SVC)){ std::cout << "Failed to open ref data service" << std::endl; return; } getTodayData(session, refData, bonds); getYesterdayData(session, yesterdayData, bonds); }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; for (size_t i = 0; i < d_hosts.size(); ++i) { sessionOptions.setServerAddress(d_hosts[i].c_str(), d_port, i); } sessionOptions.setAuthenticationOptions(d_authOptions.c_str()); sessionOptions.setAutoRestartOnDisconnection(true); sessionOptions.setNumStartAttempts(d_hosts.size()); std::cout << "Connecting to port " << d_port << " on "; std::copy(d_hosts.begin(), d_hosts.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; MyProviderEventHandler providerEventHandler(d_service); ProviderSession providerSession( sessionOptions, &providerEventHandler, 0); MyRequesterEventHandler requesterEventHandler; Session requesterSession(sessionOptions, &requesterEventHandler, 0); if (d_role == SERVER || d_role == BOTH) { serverRun(&providerSession); } if (d_role == CLIENT || d_role == BOTH) { clientRun(&requesterSession); } // wait for enter key to exit application std::cout << "Press ENTER to quit" << std::endl; char dummy[2]; std::cin.getline(dummy, 2); if (d_role == SERVER || d_role == BOTH) { providerSession.stop(); } if (d_role == CLIENT || d_role == BOTH) { requesterSession.stop(); } }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); std::cout << "Connecting to " + d_host + ":" << d_port << std::endl; Session session(sessionOptions); if (!startSession(session)) return; Service refDataService = session.getService("//blp/refdata"); Request request = refDataService.createRequest("ReferenceDataRequest"); request.append("securities", "IBM US Equity"); request.append("fields", "PX_LAST"); request.append("fields", "DS002"); session.sendRequest(request, d_cid); while (true) { Event event = session.nextEvent(); MessageIterator msgIter(event); while (msgIter.next()) { Message msg = msgIter.message(); if (event.eventType() == Event::RESPONSE || event.eventType() == Event::PARTIAL_RESPONSE) { ((Window *)msg.correlationId().asPointer())-> displaySecurityInfo(msg); } } if (event.eventType() == Event::RESPONSE) { // received final response break; } } }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; for (size_t i = 0; i < d_hosts.size(); ++i) { sessionOptions.setServerAddress(d_hosts[i].c_str(), d_port, i); } sessionOptions.setServerPort(d_port); sessionOptions.setAuthenticationOptions(d_authOptions.c_str()); sessionOptions.setAutoRestartOnDisconnection(true); sessionOptions.setNumStartAttempts(d_hosts.size()); MyEventHandler myEventHandler; ProviderSession session(sessionOptions, &myEventHandler, 0); std::cout << "Connecting to port " << d_port << " on "; std::copy(d_hosts.begin(), d_hosts.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; if (!session.start()) { std::cerr <<"Failed to start session." << std::endl; return; } Identity providerIdentity = session.createIdentity(); if (!d_authOptions.empty()) { bool isAuthorized = false; const char* authServiceName = "//blp/apiauth"; if (session.openService(authServiceName)) { Service authService = session.getService(authServiceName); isAuthorized = authorize(authService, &providerIdentity, &session, CorrelationId((void *)"auth")); } if (!isAuthorized) { std::cerr << "No authorization" << std::endl; return; } } TopicList topicList; topicList.add((d_service + d_topic).c_str(), CorrelationId(new MyStream(d_topic))); session.createTopics( &topicList, ProviderSession::AUTO_REGISTER_SERVICES, providerIdentity); // createTopics() is synchronous, topicList will be updated // with the results of topic creation (resolution will happen // under the covers) MyStreams myStreams; for (size_t i = 0; i < topicList.size(); ++i) { MyStream *stream = reinterpret_cast<MyStream*>( topicList.correlationIdAt(i).asPointer()); int resolutionStatus = topicList.statusAt(i); if (resolutionStatus == TopicList::CREATED) { Topic topic = session.getTopic(topicList.messageAt(i)); stream->setTopic(topic); myStreams.push_back(stream); } else { std::cout << "Stream '" << stream->getId() << "': topic not resolved, status = " << resolutionStatus << std::endl; } } Service service = session.getService(d_service.c_str()); // Now we will start publishing int value = 1; while (myStreams.size() > 0 && g_running) { Event event = service.createPublishEvent(); EventFormatter eventFormatter(event); for (MyStreams::iterator iter = myStreams.begin(); iter != myStreams.end(); ++iter) { eventFormatter.appendMessage(MARKET_DATA, (*iter)->getTopic()); eventFormatter.setElement("BID", 0.5 * ++value); eventFormatter.setElement("ASK", value); } MessageIterator iter(event); while (iter.next()) { Message msg = iter.message(); msg.print(std::cout); } session.publish(event); SLEEP(10); } session.stop(); }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; for (size_t i = 0; i < d_hosts.size(); ++i) { sessionOptions.setServerAddress(d_hosts[i].c_str(), d_port, i); } sessionOptions.setAuthenticationOptions(d_authOptions.c_str()); sessionOptions.setAutoRestartOnDisconnection(true); sessionOptions.setNumStartAttempts(d_hosts.size()); std::cout << "Connecting to port " << d_port << " on "; std::copy(d_hosts.begin(), d_hosts.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; MyEventHandler myEventHandler(d_service); ProviderSession session(sessionOptions, &myEventHandler, 0); if (!session.start()) { std::cerr <<"Failed to start session." << std::endl; return; } Identity providerIdentity = session.createIdentity(); if (!d_authOptions.empty()) { bool isAuthorized = false; const char* authServiceName = "//blp/apiauth"; if (session.openService(authServiceName)) { Service authService = session.getService(authServiceName); isAuthorized = authorize(authService, &providerIdentity, &session, CorrelationId((void *)"auth")); } if (!isAuthorized) { std::cerr << "No authorization" << std::endl; return; } } ServiceRegistrationOptions serviceOptions; serviceOptions.setGroupId(d_groupId.c_str(), d_groupId.size()); serviceOptions.setServicePriority(d_priority); if (!session.registerService(d_service.c_str(), providerIdentity, serviceOptions)) { std::cerr <<"Failed to register " << d_service << std::endl; return; } Service service = session.getService(d_service.c_str()); // Now we will start publishing int value=1; while (g_running) { Event event = service.createPublishEvent(); { MutexGuard guard(&g_mutex); if (0 == g_availableTopicCount) { guard.release()->unlock(); SLEEP(1); continue; } EventFormatter eventFormatter(event); for (MyStreams::iterator iter = g_streams.begin(); iter != g_streams.end(); ++iter) { if (!iter->second->isAvailable()) { continue; } std::ostringstream os; os << ++value; if (!iter->second->isInitialPaintSent()) { eventFormatter.appendRecapMessage( iter->second->topic()); eventFormatter.setElement("numRows", 25); eventFormatter.setElement("numCols", 80); eventFormatter.pushElement("rowUpdate"); for (int i = 1; i < 6; ++i) { eventFormatter.appendElement(); eventFormatter.setElement("rowNum", i); eventFormatter.pushElement("spanUpdate"); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 1); eventFormatter.setElement("length", 10); eventFormatter.setElement("text", "INITIAL"); eventFormatter.setElement("fgColor", "RED"); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.popElement(); } eventFormatter.popElement(); iter->second->setIsInitialPaintSent(true); } eventFormatter.appendMessage("RowUpdate", iter->second->topic()); eventFormatter.setElement("rowNum", 1); eventFormatter.pushElement("spanUpdate"); eventFormatter.appendElement(); Name START_COL("startCol"); eventFormatter.setElement(START_COL, 1); eventFormatter.setElement("length", int(os.str().size())); eventFormatter.setElement("text", os.str().c_str()); eventFormatter.popElement(); eventFormatter.popElement(); } } printMessages(event); session.publish(event); SLEEP(10); } session.stop(); }
void run(int argc, char **argv) { if (!parseCommandLine(argc, argv)) return; SessionOptions sessionOptions; for (size_t i = 0; i < d_hosts.size(); ++i) { sessionOptions.setServerAddress(d_hosts[i].c_str(), d_port, i); } sessionOptions.setServerPort(d_port); sessionOptions.setAuthenticationOptions(d_authOptions.c_str()); sessionOptions.setAutoRestartOnDisconnection(true); sessionOptions.setNumStartAttempts(d_hosts.size()); std::cout << "Connecting to port " << d_port << " on "; std::copy(d_hosts.begin(), d_hosts.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; MyEventHandler myEventHandler; ProviderSession session(sessionOptions, &myEventHandler, 0); if (!session.start()) { std::cerr <<"Failed to start session." << std::endl; return; } Identity providerIdentity = session.createIdentity(); if (!d_authOptions.empty()) { bool isAuthorized = false; const char* authServiceName = "//blp/apiauth"; if (session.openService(authServiceName)) { Service authService = session.getService(authServiceName); isAuthorized = authorize(authService, &providerIdentity, &session, CorrelationId((void *)"auth")); } if (!isAuthorized) { std::cerr << "No authorization" << std::endl; return; } } TopicList topicList; topicList.add(((d_service + "/") + d_topic).c_str(), CorrelationId(new MyStream(d_topic))); session.createTopics( &topicList, ProviderSession::AUTO_REGISTER_SERVICES, providerIdentity); MyStreams myStreams; for (size_t i = 0; i < topicList.size(); ++i) { MyStream *stream = reinterpret_cast<MyStream*>( topicList.correlationIdAt(i).asPointer()); int resolutionStatus = topicList.statusAt(i); if (resolutionStatus == TopicList::CREATED) { Topic topic = session.getTopic(topicList.messageAt(i)); stream->setTopic(topic); myStreams.push_back(stream); } else { std::cout << "Stream '" << stream->getId() << "': topic not resolved, status = " << resolutionStatus << std::endl; } } Service service = session.getService(d_service.c_str()); // Now we will start publishing while (g_running) { Event event = service.createPublishEvent(); EventFormatter eventFormatter(event); for (MyStreams::iterator iter = myStreams.begin(); iter != myStreams.end(); ++iter) { eventFormatter.appendMessage("PageData", (*iter)->getTopic()); eventFormatter.pushElement("rowUpdate"); eventFormatter.appendElement(); eventFormatter.setElement("rowNum", 1); eventFormatter.pushElement("spanUpdate"); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 20); eventFormatter.setElement("length", 4); eventFormatter.setElement("text", "TEST"); eventFormatter.popElement(); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 25); eventFormatter.setElement("length", 4); eventFormatter.setElement("text", "PAGE"); eventFormatter.popElement(); char buffer[10]; time_t rawtime; std::time(&rawtime); int length = (int)std::strftime(buffer, 10, "%X", std::localtime(&rawtime)); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 30); eventFormatter.setElement("length", length); eventFormatter.setElement("text", buffer); eventFormatter.setElement("attr", "BLINK"); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.appendElement(); eventFormatter.setElement("rowNum", 2); eventFormatter.pushElement("spanUpdate"); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 20); eventFormatter.setElement("length", 9); eventFormatter.setElement("text", "---------"); eventFormatter.setElement("attr", "UNDERLINE"); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.appendElement(); eventFormatter.setElement("rowNum", 3); eventFormatter.pushElement("spanUpdate"); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 10); eventFormatter.setElement("length", 9); eventFormatter.setElement("text", "TEST LINE"); eventFormatter.popElement(); eventFormatter.appendElement(); eventFormatter.setElement("startCol", 23); eventFormatter.setElement("length", 5); eventFormatter.setElement("text", "THREE"); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.popElement(); eventFormatter.setElement("contributorId", d_contributorId); eventFormatter.setElement("productCode", 1); eventFormatter.setElement("pageNumber", 1); } printMessages(event); session.publish(event); SLEEP(10); } session.stop(); }
int runHistData(double** data, std::vector<std::string>bonds, int history){ d_host = "localhost"; d_port = 8194; SessionOptions sessionOptions; sessionOptions.setServerHost(d_host.c_str()); sessionOptions.setServerPort(d_port); Session session(sessionOptions); if (!session.start()){ std::cout << "Failed to start session" << std::endl; return 0; } if (!session.openService(APIREFDATA_SVC)){ std::cout << "Failed to open ref data service" << std::endl; return 0; } Service refDataService = session.getService(APIREFDATA_SVC); Request request_hist = refDataService.createRequest("HistoricalDataRequest"); std::wstring stemp2 = std::to_wstring(bonds.size()); LPCWSTR sw2 = stemp2.c_str(); OutputDebugString(L"number bonds "); OutputDebugString(sw2); for (int i = 0; i < bonds.size(); i++){ const char* ISIN = bonds.at(i).c_str(); request_hist.getElement("securities").appendValue(ISIN); } request_hist.getElement("fields").appendValue("YLD_YTM_MID"); request_hist.set("periodicitySelection", "DAILY"); std::string endDate = today; std::string startDate = prevDate(history); request_hist.set("startDate", startDate.c_str()); request_hist.set("endDate", endDate.c_str()); session.sendRequest(request_hist); int i = 0; while (true){ Event event = session.nextEvent(); MessageIterator msgIter(event); while (msgIter.next()){ Message message = msgIter.message(); if (message.messageType() == "HistoricalDataResponse"){ i = parse_historical_response(message, data, true); } std::cout << std::endl; } if (event.eventType() == Event::RESPONSE){ break; } } return i; OutputDebugString(L"i HERE "); std::wstring stemp = std::to_wstring(i); LPCWSTR sw = stemp.c_str(); OutputDebugString(sw); }