#pragma once #include "python_md/py_book_side.h" #include #include namespace bts::md::py_interop { /** * @brief Represents the L2 Order Book for a particular security, at a particular venue. */ class PyBook { public: /** * @brief Gets the name of the venue (i.e., exchange). * * @return const std::string& The name of the venue. */ const std::string &venue() const; void set_venue(std::string value); /** * @brief Gets the name of the security type (e.g., "SPOT", "FUTURE", "OPTION"). * * @return const std::string& The name of the security type. */ const std::string &security_type() const; /** * @brief Sets the security type. * * @param value The new security type (should be "SPOT", "FUTURE", or "OPTION"). */ void set_security_type(std::string value); /** * @brief Gets the exchange security id. This is typically the security's name * (e.g., "BTS-PERPETUAL", or "ESH5"). * * @note Should be unique for each security at a particular venue (i.e., a single * venue cannot have 2 securities with the same name). MUST be unique for each security * of the same type (e.g., SPOT, FUTURE, OPTION) at a particular venue. * * @note There is no "security_id" member because that is an internal id that * we generate elsewhere in c++ code. The python plugins just need to set the * venue and exchange_security_id. */ const std::string &exchange_security_id() const; /** * @brief Sets the exchange security id. * * @param value The new exchange security id. */ void set_exchange_security_id(std::string value); PyBookSide &bids(); const PyBookSide &bids() const; void set_bids(PyBookSide bids); PyBookSide &asks(); const PyBookSide &asks() const; void set_asks(PyBookSide asks); /** * @brief Gets the number of levels in the book (i.e., the number of prices * with resting orders). */ constexpr int size() const; std::string to_string() const; private: std::string venue_; std::string security_type_; std::string exchange_security_id_; PyBookSide bids_; PyBookSide asks_; }; ////////////////////////////////////////////////// // Definition ////////////////////////////////////////////////// inline const std::string &PyBook::venue() const { return venue_; } inline void PyBook::set_venue(std::string value) { venue_ = std::move(value); } inline const std::string &PyBook::security_type() const { return security_type_; } inline void PyBook::set_security_type(std::string value) { security_type_ = std::move(value); } inline const std::string &PyBook::exchange_security_id() const { return exchange_security_id_; } inline void PyBook::set_exchange_security_id(std::string value) { exchange_security_id_ = std::move(value); } inline PyBookSide &PyBook::bids() { return bids_; } inline const PyBookSide &PyBook::bids() const { return bids_; } inline void PyBook::set_bids(PyBookSide bids) { bids_ = std::move(bids); } inline PyBookSide &PyBook::asks() { return asks_; } inline const PyBookSide &PyBook::asks() const { return asks_; } inline void PyBook::set_asks(PyBookSide asks) { asks_ = std::move(asks); } constexpr int PyBook::size() const { return bids_.size() + asks_.size(); } inline std::string PyBook::to_string() const { std::stringstream str; // pseudo json format str << "bids: [" << bids_.to_string() << "], asks: [" << asks_.to_string() << "]"; return str.str(); } } // namespace bts::md::py_interop