58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#pragma once
|
|
#ifdef SPARK_ENABLE_CCAPI
|
|
#include "BinanceBookLevel.h"
|
|
#include "lib/domain/Book.h"
|
|
#include <cstddef>
|
|
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace bts::md::binance {
|
|
|
|
class BinanceDepthSnapshot;
|
|
|
|
/**
|
|
* @brief Represents a Binance 'Diff. Depth' update
|
|
*
|
|
* @remark https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
|
|
*/
|
|
class BinanceDiffDepthUpdate {
|
|
public:
|
|
// json name: e
|
|
std::string event_type;
|
|
// json name: E
|
|
std::size_t event_time;
|
|
// json name: s
|
|
std::string symbol;
|
|
// The first event whose transition is included in this update
|
|
// json name: U
|
|
std::size_t first_update_id;
|
|
// The last event whose transition is included in this update
|
|
// json name: u
|
|
std::size_t last_update_id;
|
|
// json name: b
|
|
std::vector<BinanceBookLevel> changed_bids;
|
|
// json name: a
|
|
std::vector<BinanceBookLevel> changed_asks;
|
|
|
|
bool has_changes() const;
|
|
|
|
bool is_before_event(std::size_t event_id) const;
|
|
bool is_after_event(std::size_t event_id) const;
|
|
bool includes_event(std::size_t event_id) const;
|
|
|
|
void apply_to_book(domain::Book &book) const;
|
|
void merge(const BinanceDiffDepthUpdate &update);
|
|
void strip_non_changes(const BinanceDepthSnapshot &origin);
|
|
void validate() const;
|
|
};
|
|
|
|
void from_json(const nlohmann::json &j, BinanceDiffDepthUpdate &upd);
|
|
void to_json(nlohmann::json &j, const BinanceDiffDepthUpdate &upd);
|
|
|
|
BinanceDiffDepthUpdate &operator+=(
|
|
BinanceDiffDepthUpdate &lhs, const BinanceDiffDepthUpdate &rhs);
|
|
|
|
} // namespace bts::md::binance
|
|
#endif
|