From eccfd1ee30d6f8a1f954b272c8d92ef6fe736acc Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 25 Jun 2025 19:27:18 +0000 Subject: [PATCH] fix: Disable ccapi md provider if venue has empty symbols config Previously, ccapi exchanges (e.g., binance) would subscribe to EVERYTHING if symbols config was empty. There are way too many symbols for that. --- .../md/ccapi/CCApiMarketDataProvider.cpp | 103 +++++++++++------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/src/app_sparkd/sparkd/md/ccapi/CCApiMarketDataProvider.cpp b/src/app_sparkd/sparkd/md/ccapi/CCApiMarketDataProvider.cpp index 9019ecc71..5595ef8c2 100644 --- a/src/app_sparkd/sparkd/md/ccapi/CCApiMarketDataProvider.cpp +++ b/src/app_sparkd/sparkd/md/ccapi/CCApiMarketDataProvider.cpp @@ -1,5 +1,5 @@ #include "CCApiMarketDataProvider.h" -#include "spark/api/domain/Venue.pb.h" +#include "spark/api/domain/Venue.h" #include "spark/api/md/MarketDataConfig.pb.h" #include "spark/config/config.h" #include "spark/io/ProtoPrinter.h" @@ -7,6 +7,8 @@ #include "spark/md/GeneralMarketDataListener.h" #include "spark/md/GeneralSecurityIndex.h" #include "spark/md/MDProducer.h" +#include "spark/md/SymbolLoader.h" +#include "spark/md/UserSymbol.h" #include "spark/persistence/IDGenerator.h" #include "sparkd/md/binance/BinanceSubscription.h" #include "sparkd/md/binance_us/BinanceUsSubscription.h" @@ -82,56 +84,81 @@ CCApiMarketDataProvider::get_sources() { "CCApiMarketDataProvider::get_sources failed. Invalid config: {}", fmt::to_string(fmt::join(cfg_errs, "\n"))); } - + std::set syms; + auto is_venue_enabled = [&syms](api::domain::Venue venue) { + syms.clear(); + SymbolLoader::load(syms, domain::SecurityCriteria::create({venue})); + if (syms.empty()) { + LOG(md, Warn, + R"([ccapi_md_pro_disabled.json]{{ "venue": "{}", "rsn": "No symbols config", "ts": {} }})", + venue, core::TimeStamp::now_ns()); + return false; + } + return true; + }; // Binance - for (const auto &binance : cfg.binance()) { - me_->sources.emplace_back( - api::domain::VENUE_BINANCE, - std::make_shared( - &me_->dispatcher, binance, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_BINANCE)) { + for (const auto &binance : cfg.binance()) { + me_->sources.emplace_back( + api::domain::VENUE_BINANCE, + std::make_shared( + &me_->dispatcher, binance, me_->sec_id_store.get())); + } } // Binance US - for (const auto &binance_us : cfg.binance_us()) { - me_->sources.emplace_back( - api::domain::VENUE_BINANCE_US, - std::make_shared( - &me_->dispatcher, binance_us, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_BINANCE_US)) { + for (const auto &binance_us : cfg.binance_us()) { + me_->sources.emplace_back( + api::domain::VENUE_BINANCE_US, + std::make_shared( + &me_->dispatcher, binance_us, me_->sec_id_store.get())); + } } // Binance USDS Futures - for (const auto &binance_ufs : cfg.binance_usds_futures()) { - me_->sources.emplace_back( - api::domain::VENUE_BINANCE_USDS_FUTURES, - std::make_shared< - binance_usds_futures::BinanceUsdsFuturesSubscription>( - &me_->dispatcher, binance_ufs, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_BINANCE_USDS_FUTURES)) { + for (const auto &binance_ufs : cfg.binance_usds_futures()) { + me_->sources.emplace_back( + api::domain::VENUE_BINANCE_USDS_FUTURES, + std::make_shared< + binance_usds_futures::BinanceUsdsFuturesSubscription>( + &me_->dispatcher, binance_ufs, me_->sec_id_store.get())); + } } // Coinbase - for (const auto &coinbase : cfg.coinbase()) { - me_->sources.emplace_back( - api::domain::VENUE_COINBASE, - std::make_shared( - &me_->dispatcher, coinbase, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_COINBASE)) { + for (const auto &coinbase : cfg.coinbase()) { + me_->sources.emplace_back( + api::domain::VENUE_COINBASE, + std::make_shared( + &me_->dispatcher, coinbase, me_->sec_id_store.get())); + } } // Deribit - for (const auto &deribit : cfg.deribit()) { - me_->sources.emplace_back( - api::domain::VENUE_DERIBIT, - std::make_shared( - &me_->dispatcher, deribit, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_DERIBIT)) { + for (const auto &deribit : cfg.deribit()) { + me_->sources.emplace_back( + api::domain::VENUE_DERIBIT, + std::make_shared( + &me_->dispatcher, deribit, me_->sec_id_store.get())); + } } // FTX - for (const auto &ftx : cfg.ftx()) { - me_->sources.emplace_back( - api::domain::VENUE_FTX, - std::make_shared( - &me_->dispatcher, ftx, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_FTX)) { + for (const auto &ftx : cfg.ftx()) { + me_->sources.emplace_back( + api::domain::VENUE_FTX, + std::make_shared( + &me_->dispatcher, ftx, me_->sec_id_store.get())); + } } // Okx - for (const auto &okx : cfg.okx()) { - me_->sources.emplace_back( - api::domain::VENUE_OKX, - std::make_shared( - &me_->dispatcher, okx, me_->sec_id_store.get())); + if (is_venue_enabled(api::domain::VENUE_OKX)) { + for (const auto &okx : cfg.okx()) { + me_->sources.emplace_back( + api::domain::VENUE_OKX, + std::make_shared( + &me_->dispatcher, okx, me_->sec_id_store.get())); + } } return me_->sources; }