diff --git a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesSubscription.cpp b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesSubscription.cpp index 6f0fe8b09..63dfd1184 100644 --- a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesSubscription.cpp +++ b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesSubscription.cpp @@ -200,6 +200,7 @@ struct BinanceUsdsFuturesSubscription::PImpl { unordered_map depth_handlers; unordered_map ticker_handlers; unordered_map stats_handlers; + std::thread start_thread; explicit PImpl( ccapi::EventDispatcher *dispatcher, @@ -219,32 +220,35 @@ struct BinanceUsdsFuturesSubscription::PImpl { // Request the list of all spots at Binance. Match the results against our SecurityCriteria, // and subscribe to md for each matching spot. - std::string exch_info_url = this->cfg.url_rest_base(); - exch_info_url.append("/fapi/v1/exchangeInfo"); - bts::http::HttpResponse exch_info_res; - bts::http::HttpClient::get(exch_info_url, {}, &exch_info_res); - std::vector secs; - BinanceUsdsFuture::parse(exch_info_res.body, secs); - // Exclude secs that don't satisfy the SecurityCriteria - auto is_sec_excluded = [this](const Security &sec) { - return sec.type() != api::domain::SecurityType::SECURITY_TYPE_FUTURE || - !criteria.includes_or_undefined(sec) || - CONTAINS(this->cfg.excluded_securities(), sec.desc()) || - known_sec_names.find(sec.desc()) != known_sec_names.end(); - }; - REMOVE_IF(secs, is_sec_excluded); - // Assign security ids - for (auto &sec : secs) { - // Since the ids haven't been set yet, we should expect them to be 0 - bts_assert(sec.id().value() == 0); - SecurityID sec_id{ - sec_id_store->get_or_add(VENUE, sec.type(), sec.desc())}; - sec.security_common.id = sec_id; - } - auto sec_descs = get_sec_descs(secs); - LOG(md, Info, "Received BinanceUsdsFuture securities:\n{}", - fmt::to_string(fmt::join(sec_descs, "\n"))); - on_securities(secs); + start_thread = std::thread{[this]() { + std::string exch_info_url = this->cfg.url_rest_base(); + exch_info_url.append("/fapi/v1/exchangeInfo"); + bts::http::HttpResponse exch_info_res; + bts::http::HttpClient::get(exch_info_url, {}, &exch_info_res); + std::vector secs; + BinanceUsdsFuture::parse(exch_info_res.body, secs); + // Exclude secs that don't satisfy the SecurityCriteria + auto is_sec_excluded = [this](const Security &sec) { + return sec.type() != + api::domain::SecurityType::SECURITY_TYPE_FUTURE || + !criteria.includes_or_undefined(sec) || + CONTAINS(this->cfg.excluded_securities(), sec.desc()) || + known_sec_names.find(sec.desc()) != known_sec_names.end(); + }; + REMOVE_IF(secs, is_sec_excluded); + // Assign security ids + for (auto &sec : secs) { + // Since the ids haven't been set yet, we should expect them to be 0 + bts_assert(sec.id().value() == 0); + SecurityID sec_id{ + this->sec_id_store->get_or_add(VENUE, sec.type(), sec.desc())}; + sec.security_common.id = sec_id; + } + auto sec_descs = get_sec_descs(secs); + LOG(md, Info, "Received BinanceUsdsFuture securities:\n{}", + fmt::to_string(fmt::join(sec_descs, "\n"))); + on_securities(secs); + }}; } SecurityID get_sec_id(SecurityType sec_type, const string &sec_desc) {