cleanup: Get rid of "PyList" classes, bind to stl vector instead
I wasn't aware this was possible until recently.
This commit is contained in:
1 parent
0462c97b76
commit
ccf8b671bf
12 files changed
+105
-417
No files matched your search
@@ -4,7 +4,6 @@
|
||||
#include "python_md/py_contract_specification.h"
|
||||
#include "python_md/py_md_executor.h"
|
||||
#include "python_md/py_security.h"
|
||||
#include "python_md/py_security_list.h"
|
||||
#include "python_md/py_trade.h"
|
||||
#include "spark/api/domain/CallPut.pb.h"
|
||||
#include "spark/api/domain/SecurityType.h"
|
||||
@@ -17,6 +16,7 @@
|
||||
#include "spark/domain/SecurityID.h"
|
||||
#include "spark/domain/SpotSecurity.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/domain_model/SecurityType.h"
|
||||
#include "spark/io/json_formatter.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
@@ -51,13 +51,10 @@ using bts::domain::SpotSecurity;
|
||||
using bts::domain::TradeRecord;
|
||||
using bts::io::json_formatter;
|
||||
using bts::md::py_interop::PyBook;
|
||||
using bts::md::py_interop::PyBookList;
|
||||
using bts::md::py_interop::PyBookSide;
|
||||
using bts::md::py_interop::PyMdExecutor;
|
||||
using bts::md::py_interop::PySecurity;
|
||||
using bts::md::py_interop::PySecurityList;
|
||||
using bts::md::py_interop::PyTrade;
|
||||
using bts::md::py_interop::PyTradeList;
|
||||
using bts::persistence::IDGenerator;
|
||||
using std::optional;
|
||||
using std::shared_ptr;
|
||||
@@ -106,20 +103,22 @@ struct PyMarketDataSubscription::PImpl : private py_interop::MdSink {
|
||||
vector<TradeRecord> trades_;
|
||||
vector<const TradeRecord *> trade_ptrs_;
|
||||
|
||||
void on_securities(const PySecurityList &py_securities) override {
|
||||
void on_securities(const vector<PySecurity> &py_securities) override {
|
||||
LOG(md, Info, R"([py_md_secs.json]{{ "secs": {}, "ts": {}}})",
|
||||
json_formatter(py_securities.items()), TimeStamp::now_ns());
|
||||
json_formatter(py_securities), TimeStamp::now_ns());
|
||||
// `securities_` and `security_ptrs_` should already be empty, but no harm in clearing them
|
||||
// again. We keep them as member variables to avoid (re)allocating memory in each callback.
|
||||
securities_.clear();
|
||||
security_ptrs_.clear();
|
||||
for (const auto &py_sec : py_securities.items()) {
|
||||
for (const auto &py_sec : py_securities) {
|
||||
auto sec = to_bts_security_(py_sec);
|
||||
if (!sec) {
|
||||
LOG(md, Error,
|
||||
"Failed to convert security {} to bts::domain::Security",
|
||||
py_sec.name());
|
||||
LOG(md, Error, R"([py_md_sec_parse_error.json]{{ "sec": {}, "ts": {}}})", py_sec);
|
||||
LOG(md, Error,
|
||||
R"([py_md_sec_parse_error.json]{{ "sec": {}, "ts": {}}})",
|
||||
py_sec);
|
||||
continue;
|
||||
}
|
||||
securities_.push_back(std::move(*sec));
|
||||
@@ -134,10 +133,10 @@ struct PyMarketDataSubscription::PImpl : private py_interop::MdSink {
|
||||
security_ptrs_.clear();
|
||||
}
|
||||
|
||||
void on_books(const PyBookList &py_books) override {
|
||||
void on_books(const vector<PyBook> &py_books) override {
|
||||
LOG(md, Info, R"([py_md_books.json]{{ "bks": {}, "ts": {}}})",
|
||||
json_formatter(py_books.items()), TimeStamp::now_ns());
|
||||
for (auto &py_book : py_books.items()) {
|
||||
json_formatter(py_books), TimeStamp::now_ns());
|
||||
for (auto &py_book : py_books) {
|
||||
bts_assert(book_.count_populated() == 0);
|
||||
to_book_(py_book, book_);
|
||||
listener_->on_book(book_);
|
||||
@@ -145,14 +144,14 @@ struct PyMarketDataSubscription::PImpl : private py_interop::MdSink {
|
||||
}
|
||||
}
|
||||
|
||||
void on_trades(const PyTradeList &py_trades) override {
|
||||
void on_trades(const vector<PyTrade> &py_trades) override {
|
||||
LOG(md, Info, R"([py_md_trades.json]{{ "trds": {}, "ts": {}}})",
|
||||
json_formatter(py_trades.items()), TimeStamp::now_ns());
|
||||
json_formatter(py_trades), TimeStamp::now_ns());
|
||||
// `trades_` and `trade_ptrs_` should already be empty, but no harm in clearing them again.
|
||||
// We keep them as member variables to avoid (re)allocating memory in each callback.
|
||||
trades_.clear();
|
||||
trade_ptrs_.clear();
|
||||
for (const auto &py_trade : py_trades.items()) {
|
||||
for (const auto &py_trade : py_trades) {
|
||||
LOG(md, Info, "PyMarketDataSubscription received trade {}",
|
||||
py_trade.to_string());
|
||||
to_bts_trade_(py_trade, trades_.emplace_back());
|
||||
@@ -198,7 +197,7 @@ struct PyMarketDataSubscription::PImpl : private py_interop::MdSink {
|
||||
if (spec.price_infos().size() > 0) {
|
||||
bts_assert(spec.price_infos().size() == 1);
|
||||
const py_interop::PyContractPriceInfo &price_info =
|
||||
spec.price_infos().items()[0];
|
||||
spec.price_infos()[0];
|
||||
bts_assert(price_info.tick_unit() > 0 && price_info.tick_base() > 0);
|
||||
sec_comm.min_price_increment =
|
||||
price_info.tick_unit() / price_info.tick_base();
|
||||
@@ -209,7 +208,7 @@ struct PyMarketDataSubscription::PImpl : private py_interop::MdSink {
|
||||
if (spec.quantity_infos().size() > 0) {
|
||||
bts_assert(spec.quantity_infos().size() == 1);
|
||||
const py_interop::PyContractQuantityInfo &qty_info =
|
||||
spec.quantity_infos().items()[0];
|
||||
spec.quantity_infos()[0];
|
||||
bts_assert(qty_info.tick_unit() > 0 && qty_info.tick_base() > 0);
|
||||
sec_comm.min_quantity_increment =
|
||||
qty_info.tick_unit() / qty_info.tick_base();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_book_list.h"
|
||||
#include "python_md/py_security_list.h"
|
||||
#include "python_md/py_trade_list.h"
|
||||
#include "python_md/py_book.h"
|
||||
#include "python_md/py_security.h"
|
||||
#include "python_md/py_trade.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
@@ -10,9 +12,9 @@ class MdSink {
|
||||
public:
|
||||
virtual ~MdSink();
|
||||
|
||||
virtual void on_securities(const py_interop::PySecurityList &securities) = 0;
|
||||
virtual void on_books(const py_interop::PyBookList &books) = 0;
|
||||
virtual void on_trades(const py_interop::PyTradeList &trades) = 0;
|
||||
virtual void on_securities(const std::vector<PySecurity> &securities) = 0;
|
||||
virtual void on_books(const std::vector<PyBook> &books) = 0;
|
||||
virtual void on_trades(const std::vector<PyTrade> &trades) = 0;
|
||||
};
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "python_md/md_sink_impl.h"
|
||||
#include "python_md/py_security_list.h"
|
||||
#include "python_md/py_trade_list.h"
|
||||
#include "python_md/py_security.h"
|
||||
#include "python_md/py_trade.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/utils/formatters/exception_formatter.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
#define ASSERT_FN(test, fn, ...) \
|
||||
@@ -18,13 +20,14 @@ namespace bts::md::py_interop {
|
||||
#define ERROR_FN(fn, ...) LOG_FN(bts::Error, fn, __VA_ARGS__)
|
||||
|
||||
#define _LOG(level, ...) LOG(OrderMan, level, __VA_ARGS__)
|
||||
#define DIAG(...) _LOG(bts::Diag, __VA_ARGS__)
|
||||
#define INFO(...) _LOG(bts::Info, __VA_ARGS__)
|
||||
#define ERROR(...) _LOG(bts::Error, __VA_ARGS__)
|
||||
|
||||
struct MdSinkImpl::PImpl {
|
||||
std::function<void(const PySecurityList &)> securities_callback;
|
||||
std::function<void(const PyBookList &)> books_callback;
|
||||
std::function<void(const PyTradeList &)> trades_callback;
|
||||
std::function<void(const vector<PySecurity> &)> securities_callback;
|
||||
std::function<void(const vector<PyBook> &)> books_callback;
|
||||
std::function<void(const vector<PyTrade> &)> trades_callback;
|
||||
};
|
||||
|
||||
MdSinkImpl::MdSinkImpl() : me(std::make_unique<PImpl>()) {}
|
||||
@@ -33,10 +36,12 @@ MdSinkImpl::MdSinkImpl(MdSinkImpl &&) = default;
|
||||
MdSinkImpl &MdSinkImpl::operator=(MdSinkImpl &&) = default;
|
||||
MdSinkImpl::~MdSinkImpl() = default;
|
||||
|
||||
void MdSinkImpl::on_books(const PyBookList &books) {
|
||||
DIAG_FN("on_books", "{}", books);
|
||||
void MdSinkImpl::on_books(const vector<PyBook> &books) {
|
||||
DIAG(
|
||||
"[py_md_sink_books.json][{}]",
|
||||
fmt::format("{}", fmt::join(books, ", ")));
|
||||
try {
|
||||
if (books.items().empty()) {
|
||||
if (books.empty()) {
|
||||
WARN_FN("on_books", "books empty");
|
||||
return;
|
||||
}
|
||||
@@ -48,10 +53,12 @@ void MdSinkImpl::on_books(const PyBookList &books) {
|
||||
}
|
||||
}
|
||||
|
||||
void MdSinkImpl::on_securities(const PySecurityList &securities) {
|
||||
DIAG_FN("on_securities", "{}", securities);
|
||||
void MdSinkImpl::on_securities(const vector<PySecurity> &securities) {
|
||||
DIAG(
|
||||
"[py_md_sink_secs.json][{}]",
|
||||
fmt::format("{}", fmt::join(securities, ", ")));
|
||||
try {
|
||||
if (securities.items().empty()) {
|
||||
if (securities.empty()) {
|
||||
WARN_FN("on_securities", "securities empty");
|
||||
return;
|
||||
}
|
||||
@@ -63,10 +70,12 @@ void MdSinkImpl::on_securities(const PySecurityList &securities) {
|
||||
}
|
||||
}
|
||||
|
||||
void MdSinkImpl::on_trades(const PyTradeList &trades) {
|
||||
DIAG_FN("on_trades", "{}", trades);
|
||||
void MdSinkImpl::on_trades(const vector<PyTrade> &trades) {
|
||||
DIAG(
|
||||
"[py_md_sink_trds.json][{}]",
|
||||
fmt::format("{}", fmt::join(trades, ", ")));
|
||||
try {
|
||||
if (trades.items().empty()) {
|
||||
if (trades.empty()) {
|
||||
WARN_FN("on_trades", "trades empty");
|
||||
return;
|
||||
}
|
||||
@@ -79,17 +88,17 @@ void MdSinkImpl::on_trades(const PyTradeList &trades) {
|
||||
}
|
||||
|
||||
void MdSinkImpl::set_books_callback(
|
||||
std::function<void(const PyBookList &)> callback) {
|
||||
std::function<void(const vector<PyBook> &)> callback) {
|
||||
me->books_callback = callback;
|
||||
}
|
||||
|
||||
void MdSinkImpl::set_trades_callback(
|
||||
std::function<void(const PyTradeList &)> callback) {
|
||||
std::function<void(const vector<PyTrade> &)> callback) {
|
||||
me->trades_callback = callback;
|
||||
}
|
||||
|
||||
void MdSinkImpl::set_securities_callback(
|
||||
std::function<void(const PySecurityList &)> callback) {
|
||||
std::function<void(const vector<PySecurity> &)> callback) {
|
||||
me->securities_callback = callback;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/md_sink.h"
|
||||
#include "python_md/py_book_list.h"
|
||||
#include "python_md/py_security_list.h"
|
||||
#include "python_md/py_trade_list.h"
|
||||
#include "python_md/py_book.h"
|
||||
#include "python_md/py_trade.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -18,14 +17,16 @@ class MdSinkImpl : public MdSink {
|
||||
|
||||
MdSinkImpl &operator=(MdSinkImpl &&);
|
||||
|
||||
void on_books(const PyBookList &books) override;
|
||||
void on_trades(const PyTradeList &trades) override;
|
||||
void on_securities(const PySecurityList &securities) override;
|
||||
void on_books(const std::vector<PyBook> &books) override;
|
||||
void on_trades(const std::vector<PyTrade> &trades) override;
|
||||
void on_securities(const std::vector<PySecurity> &securities) override;
|
||||
|
||||
void set_books_callback(std::function<void(const PyBookList &)> callback);
|
||||
void set_trades_callback(std::function<void(const PyTradeList &)> callback);
|
||||
void set_books_callback(
|
||||
std::function<void(const std::vector<PyBook> &)> callback);
|
||||
void set_trades_callback(
|
||||
std::function<void(const std::vector<PyTrade> &)> callback);
|
||||
void set_securities_callback(
|
||||
std::function<void(const PySecurityList &)> callback);
|
||||
std::function<void(const std::vector<PySecurity> &)> callback);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_book.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PyBookList {
|
||||
public:
|
||||
void append(const py_interop::PyBook &book);
|
||||
void clear();
|
||||
std::vector<py_interop::PyBook> &items();
|
||||
const std::vector<py_interop::PyBook> &items() const;
|
||||
constexpr std::size_t size() const;
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::vector<py_interop::PyBook> items_;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const PyBookList &l) noexcept;
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyBookList,
|
||||
bks,
|
||||
"[{}]",
|
||||
fmt::format("{}", fmt::join(bks.items(), ", ")));
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline void PyBookList::append(const py_interop::PyBook &book) {
|
||||
items_.push_back(book);
|
||||
}
|
||||
|
||||
inline void PyBookList::clear() { items_.clear(); }
|
||||
|
||||
constexpr std::size_t PyBookList::size() const { return items_.size(); }
|
||||
|
||||
inline std::vector<py_interop::PyBook> &PyBookList::items() { return items_; }
|
||||
inline const std::vector<py_interop::PyBook> &PyBookList::items() const {
|
||||
return items_;
|
||||
}
|
||||
|
||||
inline std::string PyBookList::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
inline std::ostream &operator<<(
|
||||
std::ostream &out, const PyBookList &l) noexcept {
|
||||
out << fmt::format("{}", l);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
@@ -1,59 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_contract_price_info.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PyContractPriceInfoList {
|
||||
public:
|
||||
void append(const PyContractPriceInfo &item);
|
||||
void clear();
|
||||
const std::vector<PyContractPriceInfo> &items() const;
|
||||
constexpr std::size_t size() const;
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::vector<PyContractPriceInfo> items_;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(
|
||||
std::ostream &out, const PyContractPriceInfoList &l) noexcept;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyContractPriceInfoList,
|
||||
l,
|
||||
"[{}]",
|
||||
fmt::format("{}", fmt::join(l.items(), ", ")));
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline void PyContractPriceInfoList::append(const PyContractPriceInfo &value) {
|
||||
items_.push_back(value);
|
||||
}
|
||||
|
||||
inline void PyContractPriceInfoList::clear() { items_.clear(); }
|
||||
|
||||
constexpr std::size_t PyContractPriceInfoList::size() const {
|
||||
return items_.size();
|
||||
}
|
||||
|
||||
inline const std::vector<PyContractPriceInfo> &
|
||||
PyContractPriceInfoList::items() const {
|
||||
return items_;
|
||||
}
|
||||
|
||||
inline std::string PyContractPriceInfoList::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_contract_quantity_info.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PyContractQuantityInfoList {
|
||||
public:
|
||||
void append(const PyContractQuantityInfo &item);
|
||||
void remove_at(int index);
|
||||
void clear();
|
||||
const std::vector<PyContractQuantityInfo> &items() const;
|
||||
constexpr std::size_t size() const;
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::vector<PyContractQuantityInfo> items_;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyContractQuantityInfoList,
|
||||
l,
|
||||
"[{}]",
|
||||
fmt::format("{}", fmt::join(l.items(), ", ")));
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline void PyContractQuantityInfoList::append(
|
||||
const PyContractQuantityInfo &value) {
|
||||
items_.push_back(value);
|
||||
}
|
||||
|
||||
inline void PyContractQuantityInfoList::remove_at(int index) {
|
||||
if (index >= 0 && static_cast<std::size_t>(index) < items_.size()) {
|
||||
items_.erase(items_.begin() + index);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PyContractQuantityInfoList::clear() { items_.clear(); }
|
||||
|
||||
constexpr std::size_t PyContractQuantityInfoList::size() const {
|
||||
return items_.size();
|
||||
}
|
||||
|
||||
inline const std::vector<PyContractQuantityInfo> &
|
||||
PyContractQuantityInfoList::items() const {
|
||||
return items_;
|
||||
}
|
||||
|
||||
inline std::string PyContractQuantityInfoList::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
inline std::ostream &operator<<(
|
||||
std::ostream &out, const PyContractQuantityInfoList &l) noexcept {
|
||||
out << fmt::format("{}", l);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_contract_price_info_list.h"
|
||||
#include "python_md/py_contract_quantity_info_list.h"
|
||||
#include "python_md/py_contract_price_info.h"
|
||||
#include "python_md/py_contract_quantity_info.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
@@ -16,24 +18,24 @@ class PyContractSpecification {
|
||||
public:
|
||||
constexpr PyContractSpecification() = default;
|
||||
|
||||
const PyContractPriceInfoList &price_infos() const;
|
||||
PyContractPriceInfoList &mutable_price_infos();
|
||||
void set_price_infos(PyContractPriceInfoList value);
|
||||
const std::vector<PyContractPriceInfo> &price_infos() const;
|
||||
std::vector<PyContractPriceInfo> &mutable_price_infos();
|
||||
void set_price_infos(std::vector<PyContractPriceInfo> value);
|
||||
|
||||
const PyContractQuantityInfoList &quantity_infos() const;
|
||||
PyContractQuantityInfoList &mutable_quantity_infos();
|
||||
void set_quantity_infos(PyContractQuantityInfoList value);
|
||||
const std::vector<PyContractQuantityInfo> &quantity_infos() const;
|
||||
std::vector<PyContractQuantityInfo> &mutable_quantity_infos();
|
||||
void set_quantity_infos(std::vector<PyContractQuantityInfo> value);
|
||||
|
||||
const PyContractQuantityInfoList ¬ional_quantity_infos() const;
|
||||
PyContractQuantityInfoList &mutable_notional_quantity_infos();
|
||||
void set_notional_quantity_infos(PyContractQuantityInfoList value);
|
||||
const std::vector<PyContractQuantityInfo> ¬ional_quantity_infos() const;
|
||||
std::vector<PyContractQuantityInfo> &mutable_notional_quantity_infos();
|
||||
void set_notional_quantity_infos(std::vector<PyContractQuantityInfo> value);
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
PyContractPriceInfoList price_infos_;
|
||||
PyContractQuantityInfoList quantity_infos_;
|
||||
PyContractQuantityInfoList notional_quantity_infos_;
|
||||
std::vector<PyContractPriceInfo> price_infos_;
|
||||
std::vector<PyContractQuantityInfo> quantity_infos_;
|
||||
std::vector<PyContractQuantityInfo> notional_quantity_infos_;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(
|
||||
@@ -48,10 +50,10 @@ std::ostream &operator<<(
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyContractSpecification,
|
||||
s,
|
||||
R"({{ "price_infos": {}, "quantity_infos": {}, "notional_quantity_infos": {} }})",
|
||||
s.price_infos(),
|
||||
s.quantity_infos(),
|
||||
s.notional_quantity_infos());
|
||||
R"({{ "price_infos": [{}], "quantity_infos": [{}], "notional_quantity_infos": [{}] }})",
|
||||
fmt::format("{}", fmt::join(s.price_infos(), ", ")),
|
||||
fmt::format("{}", fmt::join(s.quantity_infos(), ", ")),
|
||||
fmt::format("{}", fmt::join(s.notional_quantity_infos(), ", ")));
|
||||
|
||||
// template <>
|
||||
// struct fmt::formatter<bts::md::py_interop::PyContractSpecification> {
|
||||
@@ -75,41 +77,42 @@ FMT_IMPL(
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline const PyContractPriceInfoList &
|
||||
inline const std::vector<PyContractPriceInfo> &
|
||||
PyContractSpecification::price_infos() const {
|
||||
return price_infos_;
|
||||
}
|
||||
inline PyContractPriceInfoList &PyContractSpecification::mutable_price_infos() {
|
||||
inline std::vector<PyContractPriceInfo> &
|
||||
PyContractSpecification::mutable_price_infos() {
|
||||
return price_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_price_infos(
|
||||
PyContractPriceInfoList value) {
|
||||
std::vector<PyContractPriceInfo> value) {
|
||||
price_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const PyContractQuantityInfoList &
|
||||
inline const std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::quantity_infos() const {
|
||||
return quantity_infos_;
|
||||
}
|
||||
inline PyContractQuantityInfoList &
|
||||
inline std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::mutable_quantity_infos() {
|
||||
return quantity_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_quantity_infos(
|
||||
PyContractQuantityInfoList value) {
|
||||
std::vector<PyContractQuantityInfo> value) {
|
||||
quantity_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const PyContractQuantityInfoList &
|
||||
inline const std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::notional_quantity_infos() const {
|
||||
return notional_quantity_infos_;
|
||||
}
|
||||
inline PyContractQuantityInfoList &
|
||||
inline std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::mutable_notional_quantity_infos() {
|
||||
return notional_quantity_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_notional_quantity_infos(
|
||||
PyContractQuantityInfoList value) {
|
||||
std::vector<PyContractQuantityInfo> value) {
|
||||
notional_quantity_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using bts::md::py_interop::PyBook;
|
||||
using bts::md::py_interop::PySecurity;
|
||||
using bts::md::py_interop::PyTrade;
|
||||
using std::vector;
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
namespace py = pybind11;
|
||||
@@ -53,9 +58,9 @@ struct __attribute__((visibility("hidden"))) PyMdExecutor_PImpl {
|
||||
size_t thread_id = BTS_THIS_THREAD_ID;
|
||||
std::mutex instance_mx;
|
||||
std::optional<py::scoped_interpreter> interpreter{};
|
||||
std::function<void(const py_interop::PySecurityList &)> securities_callback;
|
||||
std::function<void(const py_interop::PyBookList &)> books_callback;
|
||||
std::function<void(const py_interop::PyTradeList &)> trades_callback;
|
||||
std::function<void(const vector<PySecurity> &)> securities_callback;
|
||||
std::function<void(const vector<PyBook> &)> books_callback;
|
||||
std::function<void(const vector<PyTrade> &)> trades_callback;
|
||||
|
||||
void start() {
|
||||
check_access();
|
||||
|
||||
@@ -2,37 +2,29 @@
|
||||
#include "python_md/md_sink.h"
|
||||
#include "python_md/md_sink_impl.h"
|
||||
#include "python_md/py_book_level.h"
|
||||
#include "python_md/py_book_list.h"
|
||||
#include "python_md/py_book_side.h"
|
||||
#include "python_md/py_contract_price_info.h"
|
||||
#include "python_md/py_contract_price_info_list.h"
|
||||
#include "python_md/py_contract_quantity_info.h"
|
||||
#include "python_md/py_contract_quantity_info_list.h"
|
||||
#include "python_md/py_contract_specification.h"
|
||||
#include "python_md/py_md_provider.h"
|
||||
#include "python_md/py_security.h"
|
||||
#include "python_md/py_security_list.h"
|
||||
#include "python_md/py_trade.h"
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl_bind.h>
|
||||
|
||||
using bts::md::py_interop::MdSinkImpl;
|
||||
using bts::md::py_interop::PyBook;
|
||||
using bts::md::py_interop::PyBookLevel;
|
||||
using bts::md::py_interop::PyBookList;
|
||||
using bts::md::py_interop::PyBookSide;
|
||||
using bts::md::py_interop::PyContractPriceInfo;
|
||||
using bts::md::py_interop::PyContractPriceInfoList;
|
||||
using bts::md::py_interop::PyContractQuantityInfo;
|
||||
using bts::md::py_interop::PyContractQuantityInfoList;
|
||||
using bts::md::py_interop::PyContractSpecification;
|
||||
using bts::md::py_interop::PyFuture;
|
||||
using bts::md::py_interop::PyOption;
|
||||
using bts::md::py_interop::PySecurity;
|
||||
using bts::md::py_interop::PySecurityList;
|
||||
using bts::md::py_interop::PySpot;
|
||||
using bts::md::py_interop::PyTrade;
|
||||
using bts::md::py_interop::PyTradeList;
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
@@ -80,12 +72,7 @@ PYBIND11_MODULE(python_md_module, m) {
|
||||
.PROP(PySecurity, future)
|
||||
.PROP(PySecurity, option)
|
||||
.def("__str__", &PySecurity::to_string);
|
||||
py::class_<PySecurityList>(m, "PySecurityList")
|
||||
.def(py::init<>())
|
||||
.DEF(PySecurityList, append)
|
||||
.DEF(PySecurityList, clear)
|
||||
.def("__len__", &PySecurityList::size)
|
||||
.def("__str__", &PySecurityList::to_string);
|
||||
py::bind_vector<std::vector<PySecurity>>(m, "PySecurityList");
|
||||
// book
|
||||
py::class_<PyBookLevel>(m, "PyBookLevel")
|
||||
.def(py::init<>())
|
||||
@@ -109,12 +96,7 @@ PYBIND11_MODULE(python_md_module, m) {
|
||||
.DEF(PyBook, set_asks)
|
||||
.def("__len__", &PyBook::size)
|
||||
.def("__str__", &PyBook::to_string);
|
||||
py::class_<PyBookList>(m, "PyBookList")
|
||||
.def(py::init<>())
|
||||
.DEF(PyBookList, append)
|
||||
.DEF(PyBookList, clear)
|
||||
.def("__len__", &PyBookList::size)
|
||||
.def("__str__", &PyBookList::to_string);
|
||||
py::bind_vector<std::vector<PyBook>>(m, "PyBookList");
|
||||
// trade
|
||||
py::class_<PyTrade>(m, "PyTrade")
|
||||
.def(py::init<>())
|
||||
@@ -125,12 +107,7 @@ PYBIND11_MODULE(python_md_module, m) {
|
||||
.PROP(PyTrade, quantity)
|
||||
.PROP(PyTrade, aggressor_side)
|
||||
.PROP(PyTrade, timestamp);
|
||||
py::class_<PyTradeList>(m, "PyTradeList")
|
||||
.def(py::init<>())
|
||||
.DEF(PyTradeList, append)
|
||||
.DEF(PyTradeList, clear)
|
||||
.def("__len__", &PyTradeList::size)
|
||||
.def("__str__", &PyTradeList::to_string);
|
||||
py::bind_vector<std::vector<PyTrade>>(m, "PyTradeList");
|
||||
// contract spec
|
||||
py::class_<PyContractSpecification>(m, "PyContractSpecification")
|
||||
.def(py::init<>())
|
||||
@@ -147,13 +124,8 @@ PYBIND11_MODULE(python_md_module, m) {
|
||||
.PROP(PyContractPriceInfo, cash_per_point)
|
||||
.PROP(PyContractPriceInfo, max_price)
|
||||
.def("__str__", &PyContractPriceInfo::to_string);
|
||||
py::class_<PyContractPriceInfoList>(m, "PyContractPriceInfoList")
|
||||
.def(py::init<>())
|
||||
.DEF(PyContractPriceInfoList, append)
|
||||
.DEF(PyContractPriceInfoList, clear)
|
||||
.DEF(PyContractPriceInfoList, items)
|
||||
.def("__len__", &PyContractPriceInfoList::size)
|
||||
.def("__str__", &PyContractPriceInfoList::to_string);
|
||||
py::bind_vector<std::vector<PyContractPriceInfo>>(
|
||||
m, "PyContractPriceInfoList");
|
||||
// quantity info
|
||||
py::class_<PyContractQuantityInfo>(m, "PyContractQuantityInfo")
|
||||
.def(py::init<>())
|
||||
@@ -164,13 +136,8 @@ PYBIND11_MODULE(python_md_module, m) {
|
||||
.PROP(PyContractQuantityInfo, multiplier)
|
||||
.PROP(PyContractQuantityInfo, max_price)
|
||||
.def("__str__", &PyContractQuantityInfo::to_string);
|
||||
py::class_<PyContractQuantityInfoList>(m, "PyContractQuantityInfoList")
|
||||
.def(py::init<>())
|
||||
.DEF(PyContractQuantityInfoList, append)
|
||||
.DEF(PyContractQuantityInfoList, clear)
|
||||
.DEF(PyContractQuantityInfoList, items)
|
||||
.def("__len__", &PyContractQuantityInfoList::size)
|
||||
.def("__str__", &PyContractQuantityInfoList::to_string);
|
||||
py::bind_vector<std::vector<PyContractQuantityInfo>>(
|
||||
m, "PyContractQuantityInfoList");
|
||||
// md sink
|
||||
py::class_<bts::md::py_interop::MdSink>(m, "MdSink")
|
||||
.DEF(bts::md::py_interop::MdSink, on_securities)
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_security.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/io/json_formatter.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PySecurityList {
|
||||
public:
|
||||
void append(const PySecurity &security);
|
||||
void clear();
|
||||
const std::vector<PySecurity> &items() const;
|
||||
constexpr std::size_t size() const;
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::vector<PySecurity> items_;
|
||||
};
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PySecurityList,
|
||||
l,
|
||||
"{}",
|
||||
bts::io::json_formatter(l.items()));
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline void PySecurityList::append(const PySecurity &security) {
|
||||
items_.push_back(security);
|
||||
}
|
||||
|
||||
inline void PySecurityList::clear() { items_.clear(); }
|
||||
|
||||
constexpr std::size_t PySecurityList::size() const { return items_.size(); }
|
||||
|
||||
inline const std::vector<PySecurity> &PySecurityList::items() const {
|
||||
return items_;
|
||||
}
|
||||
|
||||
inline std::string PySecurityList::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
@@ -1,52 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_md/py_trade.h"
|
||||
#include "spark/io/json_formatter.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PyTradeList {
|
||||
public:
|
||||
void append(const py_interop::PyTrade &trade);
|
||||
void clear();
|
||||
const std::vector<py_interop::PyTrade> &items() const;
|
||||
constexpr std::size_t size() const;
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::vector<py_interop::PyTrade> items_;
|
||||
};
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyTradeList,
|
||||
l,
|
||||
"{}",
|
||||
bts::io::json_formatter(l.items()));
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline void PyTradeList::append(const py_interop::PyTrade &trade) {
|
||||
items_.push_back(trade);
|
||||
}
|
||||
|
||||
inline void PyTradeList::clear() { items_.clear(); }
|
||||
|
||||
constexpr std::size_t PyTradeList::size() const { return items_.size(); }
|
||||
|
||||
inline const std::vector<py_interop::PyTrade> &PyTradeList::items() const {
|
||||
return items_;
|
||||
}
|
||||
|
||||
inline std::string PyTradeList::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
Reference in new issue
Block a user