refactor: Split MarketDataGateway up into providers/sources

MarketDataGateway still exists, but is greatly simplified. It creates
several `IMarketDataProvider`s, each of which generates a list of
`IMarketDataSource`s. The market data sources provide market data to an
`IMarketDataListener`.

* EmumbaMarketDataProvider
* CCApiMarketDataProvider
* PyMarketDataProvider
* OnixsMarketDataProvider
* ReplayMarketDataProvider

As a side effect, individual py market data sources are now explicitly
limited to a single venue (it probably should have been this way all
along, since the shared memory writers do not expect updates to involve
multiple venues).
This commit is contained in:
John Colvin committed 2024-11-25 19:21:48 +00:00
1 parent d68fe93422
commit 0aaa6e18fd
60 files changed
+1724 -758

No files matched your search

+24 -3
View File
@@ -20,19 +20,32 @@ class PyBook {
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 Must be unique for each security at a particular venue (i.e., a single
* venue cannot have 2 securities with the same name).
* @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.
*
@@ -57,6 +70,7 @@ class PyBook {
private:
std::string venue_;
std::string security_type_;
std::string exchange_security_id_;
PyBookSide bids_;
PyBookSide asks_;
@@ -69,6 +83,13 @@ class PyBook {
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_;
}
+3 -3
View File
@@ -37,9 +37,6 @@ namespace py = pybind11;
// Binds getter -> <name>, and setter -> set_<name>.
#define PROP(type, name) \
def(_STR(name), &type::name).def(_STR(set_##name), &type::set_##name)
// namespace blah {
// typedef bts::md::py_interop::PyBookSide & (bts::md::py_interop::PyBook::*bids());
// }
// Define python module with c++ classes.
PYBIND11_MODULE(python_md_module, m) {
@@ -93,6 +90,7 @@ PYBIND11_MODULE(python_md_module, m) {
py::class_<bts::md::py_interop::PyBook>(m, "PyBook")
.def(py::init<>())
.PROP(PyBook, venue)
.PROP(PyBook, security_type)
.PROP(PyBook, exchange_security_id)
.EXPLICIT_DEF(PyBook, bids, BookSideGetter)
.DEF(PyBook, set_bids)
@@ -110,6 +108,7 @@ PYBIND11_MODULE(python_md_module, m) {
py::class_<PyTrade>(m, "PyTrade")
.def(py::init<>())
.PROP(PyTrade, venue)
.PROP(PyTrade, security_type)
.PROP(PyTrade, exchange_security_id)
.PROP(PyTrade, price)
.PROP(PyTrade, quantity)
@@ -142,5 +141,6 @@ PYBIND11_MODULE(python_md_module, m) {
}
#undef PROP
#undef EXPLICIT_DEF
#undef DEF
#undef _STR
+7
View File
@@ -12,6 +12,9 @@ class PyTrade {
const std::string &venue() const;
void set_venue(std::string value);
const std::string &security_type() const;
void set_security_type(std::string value);
const std::string &exchange_security_id() const;
void set_exchange_security_id(std::string value);
@@ -37,6 +40,7 @@ class PyTrade {
private:
std::string venue_;
std::string security_type_;
std::string exchange_security_id_;
double price_;
double quantity_;
@@ -51,6 +55,9 @@ class PyTrade {
inline const std::string &PyTrade::venue() const { return venue_; }
inline void PyTrade::set_venue(std::string value) { venue_ = std::move(value); }
inline const std::string &PyTrade::security_type() const { return security_type_; }
inline void PyTrade::set_security_type(std::string value) { security_type_ = std::move(value); }
inline const std::string &PyTrade::exchange_security_id() const {
return exchange_security_id_;
}
@@ -54,6 +54,7 @@ def _get_book_side(levels: list[(float, float)], is_bid_side: bool):
def _get_trade(
venue: str,
security_type: str,
exchange_security_id: str,
price: float,
quantity: float,
@@ -61,6 +62,7 @@ def _get_trade(
):
trade = pymd.PyTrade()
trade.set_venue(venue)
trade.set_security_type(security_type)
trade.set_exchange_security_id(exchange_security_id)
trade.set_price(price)
trade.set_quantity(quantity)
@@ -94,6 +96,7 @@ class DummyMdProvider(pymd.MdProvider):
asks = _get_book_side([(100.25, 3)], is_bid_side=False)
book = pymd.PyBook()
book.set_venue("Glbx")
book.set_security_type("FUTURE")
book.set_exchange_security_id("ESH5")
book.set_bids(bids)
book.set_asks(asks)
@@ -105,6 +108,7 @@ class DummyMdProvider(pymd.MdProvider):
def add_fake_trades():
trade = _get_trade(
venue="Glbx",
security_type="FUTURE",
exchange_security_id="ESH5",
price=100,
quantity=2,
@@ -119,4 +123,4 @@ class DummyMdProvider(pymd.MdProvider):
add_fake_trades()
def stop(self):
print("Stopping python MdProviderImpl")
print("Stopping python DummyMdProvider")