fix: Request binance fut md on ccapi dispatcher thread

This commit is contained in:
John Colvin committed 2025-04-29 19:32:21 +00:00
1 parent d72ebdf421
commit 69a0bcc9cd
1 file changed
+14 -2
@@ -220,12 +220,16 @@ 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.
start_thread = std::thread{[this]() {
start_thread = std::thread{[this, dispatcher]() {
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<domain::Security> secs;
// LOG(md, Info,
// "BinanceUsdsFuturesSubscription::start_thread. Received "
// "securities.\n{}",
// exch_info_res);
BinanceUsdsFuture::parse(exch_info_res.body, secs);
// Exclude secs that don't satisfy the SecurityCriteria
auto is_sec_excluded = [this](const Security &sec) {
@@ -245,9 +249,13 @@ struct BinanceUsdsFuturesSubscription::PImpl {
sec.security_common.id = sec_id;
}
auto sec_descs = get_sec_descs(secs);
nlohmann::json secs_j = secs;
LOG(md, Info, "Received BinanceUsdsFuture securities:\n{}",
fmt::to_string(fmt::join(sec_descs, "\n")));
on_securities(secs);
LOG(md, Info, "Received BinanceUsdsFuture securities (detailed):\n{}",
secs_j.dump(2));
dispatcher->dispatch(
[this, secs = std::move(secs)]() { on_securities(secs); });
}};
}
@@ -326,6 +334,10 @@ struct BinanceUsdsFuturesSubscription::PImpl {
* securities
*/
void on_securities(vector<Security> secs) {
LOG(md, Info,
"BinanceUsdsFuturesSubscription::on_securities. Requesting md for {} "
"secs.",
secs.size());
// 'sec_descs' is used to make depth subscriptions
vector<pair<SecurityType, string>> sec_descs;
sec_descs.reserve(secs.size());