本文整理汇总了C++中SubscriptionList::add方法的典型用法代码示例。如果您正苦于以下问题:C++ SubscriptionList::add方法的具体用法?C++ SubscriptionList::add怎么用?C++ SubscriptionList::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubscriptionList
的用法示例。
在下文中一共展示了SubscriptionList::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCommandLine
bool parseCommandLine(int argc, char **argv)
{
int tokenCount = 0;
for (int i = 1; i < argc; ++i) {
if (!std::strcmp(argv[i],"-s") && i + 1 < argc) {
d_securities.push_back(argv[++i]);
continue;
}
if (!std::strcmp(argv[i],"-f") && i + 1 < argc) {
d_field = std::string(argv[++i]);
continue;
}
if (!std::strcmp(argv[i],"-t") && i + 1 < argc) {
d_tokens.push_back(argv[++i]);
++tokenCount;
std::cout << "User #" << tokenCount
<< " token: " << argv[i]
<< std::endl;
continue;
}
if (!std::strcmp(argv[i],"-ip") && i + 1 < argc) {
d_host = argv[++i];
continue;
}
if (!std::strcmp(argv[i],"-p") && i + 1 < argc) {
d_port = std::atoi(argv[++i]);
continue;
}
printUsage();
return false;
}
if (!d_tokens.size()) {
std::cout << "No tokens were specified" << std::endl;
printUsage();
return false;
}
if (!d_securities.size()) {
d_securities.push_back("MSFT US Equity");
}
for (size_t i = 0; i < d_securities.size(); ++i) {
d_subscriptions.add(d_securities[i].c_str(), d_field.c_str(), "",
CorrelationId(i));
}
return true;
}
示例2: subscribe_Impl
// [[Rcpp::export]]
SEXP subscribe_Impl(SEXP con_, std::vector<std::string> securities, std::vector<std::string> fields, Rcpp::Function fun,
SEXP options_, SEXP identity_) {
// via Rcpp Attributes we get a try/catch block with error propagation to R "for free"
Session* session =
reinterpret_cast<Session*>(checkExternalPointer(con_, "blpapi::Session*"));
const std::string mdsrv = "//blp/mktdata";
if (!session->openService(mdsrv.c_str())) {
Rcpp::stop("Failed to open " + mdsrv);
}
SubscriptionList subscriptions;
// put fields into comma delimited format
std::string fields_collapsed(vectorToCSVString(fields));
std::string options_collapsed("");
if(options_ != R_NilValue && Rf_length(options_)) {
std::vector<std::string> options(Rcpp::as< std::vector<std::string> >(options_));
options_collapsed = vectorToCSVString(options);
}
for(const std::string& security : securities) {
CorrelationId cid(reinterpret_cast<void*>(const_cast<char *>(security.c_str())));
subscriptions.add(security.c_str(),fields_collapsed.c_str(),options_collapsed.c_str(),cid);
}
// check if identity was passed, if so, use it
if(identity_ != R_NilValue) {
Identity* ip;
ip = reinterpret_cast<Identity*>(checkExternalPointer(identity_,"blpapi::Identity*"));
session->subscribe(subscriptions,*ip);
} else {
session->subscribe(subscriptions);
}
while (true) {
Event event = session->nextEvent();
Rcpp::checkUserInterrupt();
MessageIterator msgIter(event);
while (msgIter.next()) {
Message msg = msgIter.message();
const char *topic = (char *)msg.correlationId().asPointer();
if (event.eventType() == Event::SUBSCRIPTION_STATUS ||
event.eventType() == Event::SUBSCRIPTION_DATA) {
Rcpp::List ans;
auto it = BlpapiEventToString.find(event.eventType());
if(it==BlpapiEventToString.end()) {
throw Rcpp::exception("Unknown event type.");
}
ans["event.type"] = it->second;
ans["topic"] = topic;
ans["data"] = recursiveParse(msg.asElement());
// call user function
fun(ans);
}
}
}
return R_NilValue;
}