Files
spark/src/lib/md/binance/BinanceDiffDepthSubscription.h
T

61 lines
1.9 KiB
C++

#pragma once
#ifdef SPARK_ENABLE_CCAPI
#include "lib/io/URL.h"
#include "lib/md/IMarketDataListener.h"
#include "lib/md/binance/BinanceDiffDepthUpdate.h"
#include "server/sparkd/cmds/spartan/system/Delegate.h"
#include <memory>
namespace bts::md::binance {
class BinanceDepthStreamParams;
/**
* @brief Manages a connection to a binance 'diff depth' stream, and provides
* incremental updates of type `BinanceDiffDepthUpdate` to callers via the
* `on_depth_changed` delegate.
*
* @note Users of this class should bind their handler to the
* `on_depth_changed` delegate BEFORE calling `connect` to avoid missing an
* update (as they are incremental, a missed update corrupts the sequence
* thereafter).
*/
class BinanceDiffDepthSubscription {
public:
BinanceDiffDepthSubscription();
explicit BinanceDiffDepthSubscription(BinanceDepthStreamParams params);
BinanceDiffDepthSubscription(const BinanceDiffDepthSubscription &) = delete;
BinanceDiffDepthSubscription(BinanceDiffDepthSubscription &&) noexcept;
BinanceDiffDepthSubscription &operator=(
const BinanceDiffDepthSubscription &) = delete;
BinanceDiffDepthSubscription &operator=(
BinanceDiffDepthSubscription &&) noexcept;
~BinanceDiffDepthSubscription();
/**
* @brief Connects to a binance market data site and begins forwarding
* updates to the `on_depth_changed` delegate
*/
void connect();
void add_listener(const std::string &symbol, IMarketDataListener *listener);
bool remove_listener(const std::string &symbol, IMarketDataListener *listener);
using OnDepthChanged = spartan::Delegate<void(
const std::string &, bts::md::binance::BinanceDiffDepthUpdate)>;
/**
* @brief The depth changed callback
*/
OnDepthChanged &on_depth_changed();
private:
struct PImpl;
std::unique_ptr<PImpl> me_;
};
} // namespace bts::md::binance
#endif