refactor: Consolidate all py interop into single lib
It was just too hard trying to make it work with separate libs. The main issue was getting the python md and execution modules to recognize PySecurityList and other types defined in the core module.
This commit is contained in:
1 parent
7c9330650d
commit
bdd5e08b60
87 files changed
+1093
-2926
No files matched your search
@@ -0,0 +1,158 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_interop/py_contract_price_info.h"
|
||||
#include "python_interop/py_contract_quantity_info.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
/**
|
||||
* Quantity and price metadata for a particular contract.
|
||||
*/
|
||||
class PyContractSpecification {
|
||||
public:
|
||||
constexpr PyContractSpecification() = default;
|
||||
|
||||
const std::vector<PyContractPriceInfo> &price_infos() const;
|
||||
std::vector<PyContractPriceInfo> &mutable_price_infos();
|
||||
void set_price_infos(std::vector<PyContractPriceInfo> value);
|
||||
|
||||
const std::vector<PyContractQuantityInfo> &quantity_infos() const;
|
||||
std::vector<PyContractQuantityInfo> &mutable_quantity_infos();
|
||||
void set_quantity_infos(std::vector<PyContractQuantityInfo> 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:
|
||||
std::vector<PyContractPriceInfo> price_infos_;
|
||||
std::vector<PyContractQuantityInfo> quantity_infos_;
|
||||
std::vector<PyContractQuantityInfo> notional_quantity_infos_;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const PyContractSpecification &spec);
|
||||
friend void from_json(
|
||||
const nlohmann::json &j, PyContractSpecification &spec);
|
||||
};
|
||||
|
||||
std::ostream &operator<<(
|
||||
std::ostream &out, const PyContractSpecification &opt) noexcept;
|
||||
|
||||
void to_json(nlohmann::json &j, const PyContractSpecification &spec);
|
||||
void from_json(const nlohmann::json &j, PyContractSpecification &spec);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
FMT_IMPL(
|
||||
bts::md::py_interop::PyContractSpecification,
|
||||
s,
|
||||
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> {
|
||||
// constexpr auto parse(fmt ::format_parse_context &ctx)
|
||||
// -> decltype(ctx.end()) {
|
||||
// return ctx.end();
|
||||
// }
|
||||
// template <typename FormatContext>
|
||||
// auto format(
|
||||
// const bts::md::py_interop::PyContractSpecification &spec,
|
||||
// FormatContext &ctx) const -> decltype(ctx.out()) {
|
||||
// return fmt::format_to(
|
||||
// ctx.out(),
|
||||
// R"({{ "price_infos": [{}], "quantity_infos": [{}], "notional_quantity_infos": [{}] }})",
|
||||
// fmt::format("{}", fmt::join(spec.price_infos().items(), ", ")),
|
||||
// fmt::format("{}", fmt::join(spec.quantity_infos().items(), ", ")),
|
||||
// fmt::format(
|
||||
// "{}", fmt::join(spec.notional_quantity_infos().items(), ", ")));
|
||||
// }
|
||||
// };
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
inline const std::vector<PyContractPriceInfo> &
|
||||
PyContractSpecification::price_infos() const {
|
||||
return price_infos_;
|
||||
}
|
||||
inline std::vector<PyContractPriceInfo> &
|
||||
PyContractSpecification::mutable_price_infos() {
|
||||
return price_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_price_infos(
|
||||
std::vector<PyContractPriceInfo> value) {
|
||||
price_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::quantity_infos() const {
|
||||
return quantity_infos_;
|
||||
}
|
||||
inline std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::mutable_quantity_infos() {
|
||||
return quantity_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_quantity_infos(
|
||||
std::vector<PyContractQuantityInfo> value) {
|
||||
quantity_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::notional_quantity_infos() const {
|
||||
return notional_quantity_infos_;
|
||||
}
|
||||
inline std::vector<PyContractQuantityInfo> &
|
||||
PyContractSpecification::mutable_notional_quantity_infos() {
|
||||
return notional_quantity_infos_;
|
||||
}
|
||||
inline void PyContractSpecification::set_notional_quantity_infos(
|
||||
std::vector<PyContractQuantityInfo> value) {
|
||||
notional_quantity_infos_ = std::move(value);
|
||||
}
|
||||
|
||||
inline std::string PyContractSpecification::to_string() const {
|
||||
return fmt::format("{}", *this);
|
||||
}
|
||||
|
||||
inline void to_json(nlohmann::json &j, const PyContractSpecification &spec) {
|
||||
j["price_infos"] = spec.price_infos();
|
||||
j["quantity_infos"] = spec.quantity_infos();
|
||||
j["notional_quantity_infos"] = spec.notional_quantity_infos();
|
||||
}
|
||||
|
||||
inline void from_json(const nlohmann::json &j, PyContractSpecification &spec) {
|
||||
auto it = j.find("price_infos");
|
||||
if (it != j.end()) {
|
||||
it->get_to(spec.price_infos_);
|
||||
}
|
||||
it = j.find("quantity_infos");
|
||||
if (it != j.end()) {
|
||||
it->get_to(spec.quantity_infos_);
|
||||
}
|
||||
it = j.find("notional_quantity_infos");
|
||||
if (it != j.end()) {
|
||||
it->get_to(spec.notional_quantity_infos_);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::ostream &operator<<(
|
||||
std::ostream &out, const PyContractSpecification &spec) noexcept {
|
||||
out << fmt::format("{}", spec);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
Reference in new issue
Block a user