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,160 @@
|
||||
#pragma once
|
||||
|
||||
#include "python_interop/py_contract_specification.h"
|
||||
#include "python_interop/py_future.h"
|
||||
#include "python_interop/py_option.h"
|
||||
#include "python_interop/py_spot.h"
|
||||
#include "spark/io/json_formatter.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <fmt/format.h>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace bts::md::py_interop {
|
||||
|
||||
class PySecurity {
|
||||
public:
|
||||
constexpr std::uint32_t id() const;
|
||||
void set_id(std::uint32_t value);
|
||||
|
||||
const std::string &exchange_id() const;
|
||||
void set_exchange_id(std::string value);
|
||||
|
||||
const std::string &name() const;
|
||||
void set_name(std::string value);
|
||||
|
||||
const std::string &venue() const;
|
||||
void set_venue(std::string value);
|
||||
|
||||
const std::string ¤cy() const;
|
||||
void set_currency(std::string value);
|
||||
|
||||
const std::string &group() const;
|
||||
void set_group(std::string value);
|
||||
|
||||
const std::string &asset() const;
|
||||
void set_asset(std::string value);
|
||||
|
||||
const PySpot &spot() const;
|
||||
void set_spot(PySpot);
|
||||
constexpr bool is_spot() const;
|
||||
|
||||
const PyFuture &future() const;
|
||||
void set_future(PyFuture);
|
||||
constexpr bool is_future() const;
|
||||
|
||||
const PyOption &option() const;
|
||||
void set_option(PyOption);
|
||||
constexpr bool is_option() const;
|
||||
|
||||
const PyContractSpecification &contract_spec() const;
|
||||
void set_contract_spec(PyContractSpecification value);
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
std::uint32_t id_;
|
||||
std::string exchange_id_;
|
||||
std::string venue_;
|
||||
std::string group_;
|
||||
std::string asset_;
|
||||
std::string name_;
|
||||
std::string currency_;
|
||||
PyContractSpecification contract_spec_;
|
||||
std::variant<PySpot, PyFuture, PyOption> sec_;
|
||||
|
||||
friend struct fmt::formatter<PySecurity>;
|
||||
friend void to_json(nlohmann::json &j, const PySecurity &sec);
|
||||
friend void from_json(const nlohmann::json &j, PySecurity &sec);
|
||||
};
|
||||
|
||||
void to_json(nlohmann::json &j, const PySecurity &sec);
|
||||
void from_json(const nlohmann::json &j, PySecurity &sec);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
constexpr std::uint32_t PySecurity::id() const { return id_; }
|
||||
inline void PySecurity::set_id(std::uint32_t value) { id_ = value; }
|
||||
|
||||
inline const std::string &PySecurity::exchange_id() const {
|
||||
return exchange_id_;
|
||||
}
|
||||
inline void PySecurity::set_exchange_id(std::string value) {
|
||||
exchange_id_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::string &PySecurity::name() const { return name_; }
|
||||
inline void PySecurity::set_name(std::string value) {
|
||||
name_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::string &PySecurity::venue() const { return venue_; }
|
||||
inline void PySecurity::set_venue(std::string value) {
|
||||
venue_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::string &PySecurity::currency() const { return currency_; }
|
||||
inline void PySecurity::set_currency(std::string value) {
|
||||
currency_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::string &PySecurity::group() const { return group_; }
|
||||
inline void PySecurity::set_group(std::string value) {
|
||||
group_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const std::string &PySecurity::asset() const { return asset_; }
|
||||
inline void PySecurity::set_asset(std::string value) {
|
||||
asset_ = std::move(value);
|
||||
}
|
||||
|
||||
inline const PySpot &PySecurity::spot() const {
|
||||
if (std::holds_alternative<PySpot>(sec_)) {
|
||||
return std::get<PySpot>(sec_);
|
||||
}
|
||||
throw std::runtime_error{"PySecurity is not a spot"};
|
||||
}
|
||||
inline void PySecurity::set_spot(PySpot value) { sec_ = std::move(value); }
|
||||
constexpr bool PySecurity::is_spot() const {
|
||||
return std::holds_alternative<PySpot>(sec_);
|
||||
}
|
||||
|
||||
inline const PyFuture &PySecurity::future() const {
|
||||
if (std::holds_alternative<PyFuture>(sec_)) {
|
||||
return std::get<PyFuture>(sec_);
|
||||
}
|
||||
throw std::runtime_error{"PySecurity is not a future"};
|
||||
}
|
||||
inline void PySecurity::set_future(PyFuture value) { sec_ = std::move(value); }
|
||||
constexpr bool PySecurity::is_future() const {
|
||||
return std::holds_alternative<PyFuture>(sec_);
|
||||
}
|
||||
|
||||
inline const PyOption &PySecurity::option() const {
|
||||
if (std::holds_alternative<PyOption>(sec_)) {
|
||||
return std::get<PyOption>(sec_);
|
||||
}
|
||||
throw std::runtime_error{"PySecurity is not an option"};
|
||||
}
|
||||
inline void PySecurity::set_option(PyOption value) { sec_ = std::move(value); }
|
||||
constexpr bool PySecurity::is_option() const {
|
||||
return std::holds_alternative<PyOption>(sec_);
|
||||
}
|
||||
|
||||
inline const PyContractSpecification &PySecurity::contract_spec() const {
|
||||
return contract_spec_;
|
||||
}
|
||||
inline void PySecurity::set_contract_spec(PyContractSpecification value) {
|
||||
contract_spec_ = std::move(value);
|
||||
}
|
||||
|
||||
inline std::string PySecurity::to_string() const { return name_; }
|
||||
|
||||
} // namespace bts::md::py_interop
|
||||
|
||||
FMT_IMPL(bts::md::py_interop::PySecurity, s, "{}", bts::io::json_formatter(s));
|
||||
Reference in new issue
Block a user