Add: Batch subs in binance sub
This commit is contained in:
1 parent
d386d93166
commit
f3b037553e
1 file changed
+16
-2
@@ -3,7 +3,6 @@
|
||||
#include "lib/api/md/BinanceMarketDataConfig.pb.h"
|
||||
#include "lib/collections/Contains.h"
|
||||
#include "lib/collections/Remove.h"
|
||||
#include "lib/collections/UnorderedSetFactory.h"
|
||||
#include "lib/core/FMT.h"
|
||||
#include "lib/domain/Security.h"
|
||||
#include "lib/domain/SecurityCriteria.h"
|
||||
@@ -35,6 +34,7 @@
|
||||
#include <range/v3/view.hpp>
|
||||
#include <range/v3/view/transform.hpp>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace bts::md::binance {
|
||||
@@ -293,6 +293,20 @@ struct BinanceSubscription::PImpl {
|
||||
{mk_stats_req(sec_descs, hnd_id),
|
||||
&mk_stats_handler(sec_descs, hnd_id)});
|
||||
}
|
||||
/**
|
||||
* @brief wrapper method to batch securities so sub limits are not reached
|
||||
*/
|
||||
template <class SecDescs>
|
||||
void batch_subscribe_market_data(SecDescs securities, size_t n = 16) {
|
||||
auto it = securities.begin();
|
||||
while (it != securities.end()) {
|
||||
auto batch_end = std::next(it, std::min(n, static_cast<size_t>(std::distance(it, securities.end()))));
|
||||
SecDescs batch(it, batch_end);
|
||||
subscribe_market_data(batch);
|
||||
it = batch_end;
|
||||
std::this_thread::sleep_for(500ms);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Subscribes to depth, ticker, and price data for a list of
|
||||
@@ -360,7 +374,7 @@ struct BinanceSubscription::PImpl {
|
||||
}
|
||||
|
||||
listener->on_securities(sec_ptrs);
|
||||
subscribe_market_data(sec_descs);
|
||||
batch_subscribe_market_data(sec_descs,4);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user