refactor: Move TradeRecord into lib_domain
This commit is contained in:
1 parent
ffb1d9fd47
commit
47cc33afc7
11 files changed
+45
-28
No files matched your search
@@ -3,8 +3,8 @@
|
||||
#include "domain/book.h"
|
||||
#include "domain/security.h"
|
||||
#include "domain/security_state.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/domain/SecurityMarketDataStatistics.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "sparkd/md/MarketDataError.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "domain/security.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "domain/spot_security.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "python_md/md_sink.h"
|
||||
#include "python_md/py_book.h"
|
||||
#include "python_md/py_md_executor.h"
|
||||
@@ -15,7 +16,6 @@
|
||||
#include "python_md/py_trade.h"
|
||||
#include "spark/api/md/PyMarketDataProviderConfig.pb.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "spark/os/os.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "CCApiTradeAdaptor.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/utils/bts_fatal.h"
|
||||
#include "sparkd/md/ccapi/CCApiCorrelationID.h"
|
||||
#include "sparkd/md/ccapi/CCApiTradeRecord.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "domain/aggressor_side.h"
|
||||
#include "domain/price.h"
|
||||
#include "domain/quantity.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/io/JsonDumper.h"
|
||||
#include "spark/io/JsonReader.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "DeribitTradeAdaptor.h"
|
||||
#include "domain/aggressor_side.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "spark/utils/bts_fatal.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "OkxTradeAdaptor.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/io/JsonReader.h"
|
||||
#include "spark/md/IMarketDataListener.h"
|
||||
#include "spark/utils/bts_fatal.h"
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include "domain/security_common.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "domain/side.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/domain/DomainSecurityUtils.h"
|
||||
#include "spark/domain/SecurityMarketDataStatistics.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/md/GeneralMarketDataListener.h"
|
||||
@@ -159,7 +159,8 @@ void MDReplayer::_replay_message(const bts::co2::RecordedMDMessage &m) {
|
||||
break;
|
||||
}
|
||||
case (co2::RecordedMDMessage::MDRecordCase::kTrade): {
|
||||
bts::domain::TradeRecord tr(m.trade());
|
||||
bts::domain::TradeRecord tr =
|
||||
domain::DomainSecurityUtils::convert(m.trade());
|
||||
std::vector<domain::TradeRecord const *> trades;
|
||||
trades.push_back(&tr);
|
||||
me->listener->on_trades(trades);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "domain/aggressor_side.h"
|
||||
#include "domain/price.h"
|
||||
#include "domain/quantity.h"
|
||||
#include "domain/security_id.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/md/IntPrice.h"
|
||||
#include "spark/md/protos/co2.pb.h"
|
||||
#include "system/time_stamp.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace bts::domain {
|
||||
@@ -19,7 +18,7 @@ class TradeRecord {
|
||||
Quantity trade_quantity;
|
||||
Price trade_price;
|
||||
TradeRecord() {}
|
||||
inline TradeRecord(const bts::co2::TradeMessage &tm);
|
||||
// inline TradeRecord(const bts::co2::TradeMessage &tm);
|
||||
};
|
||||
|
||||
void from_json(const nlohmann::json &j, TradeRecord &tr);
|
||||
@@ -29,16 +28,6 @@ void to_json(nlohmann::json &j, const TradeRecord &tr);
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
inline TradeRecord::TradeRecord(const bts::co2::TradeMessage &tm)
|
||||
: sec_id(tm.key()), time_stamp(tm.time()),
|
||||
agg_side(
|
||||
tm.aggressor_side() == co2::AggressorSide::AGGRESSOR_SIDE_BUY
|
||||
? AggressorSide{AggressorSide::Buy}
|
||||
: AggressorSide{AggressorSide::Sell}),
|
||||
trade_quantity(tm.size()),
|
||||
trade_price(Price::from_double(
|
||||
bts::md::IntPrice(tm.mantissa(), tm.exponent()).price())) {}
|
||||
|
||||
inline void from_json(const nlohmann::json &j, TradeRecord &tr) {
|
||||
io::JsonReader jr{&j};
|
||||
// clang-format off
|
||||
@@ -49,8 +38,10 @@ inline void from_json(const nlohmann::json &j, TradeRecord &tr) {
|
||||
jr.read("qty", tr.trade_quantity);
|
||||
// clang-format on
|
||||
if (!success) {
|
||||
#ifdef LOG
|
||||
const auto j_str = j.dump(2);
|
||||
LOG(md, Error, "Failed to parse json to TradeRecord:\n{}", j_str);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
#include "DomainSecurityUtils.h"
|
||||
#include "domain/future_security.h"
|
||||
#include "domain/option_security.h"
|
||||
#include "domain/price.h"
|
||||
#include "domain/protobufs/venue.pb.h"
|
||||
#include "domain/security.h"
|
||||
#include "domain/spot_security.h"
|
||||
#include "domain/spread_security.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/md/IntPrice.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
#define DOMAIN_VENUE(x) bts::domain::protobufs::VENUE_##x
|
||||
#define DOMAIN_SEC_TYPE(x) bts::domain::protobufs::SECURITY_TYPE_##x
|
||||
|
||||
domain::TradeRecord DomainSecurityUtils::convert(
|
||||
const co2::TradeMessage &trade) {
|
||||
domain::TradeRecord rv;
|
||||
*rv.sec_id = trade.key();
|
||||
rv.time_stamp = core::TimeStamp::from_int64(trade.time());
|
||||
rv.agg_side =
|
||||
trade.aggressor_side() == co2::AggressorSide::AGGRESSOR_SIDE_BUY
|
||||
? AggressorSide::Buy
|
||||
: AggressorSide::Sell;
|
||||
*rv.trade_quantity = trade.size();
|
||||
rv.trade_price = bts::domain::Price::from_double(
|
||||
bts::md::IntPrice(trade.mantissa(), trade.exponent()).price());
|
||||
return rv;
|
||||
}
|
||||
|
||||
domain::protobufs::Venue DomainSecurityUtils::convert(bts::api::Venue venue) {
|
||||
switch (venue) {
|
||||
case bts::api::Venue::VENUE_GLBX:
|
||||
@@ -134,8 +152,9 @@ bts::domain::OptionSecurity DomainSecurityUtils::convert(
|
||||
opt.expiration_year(), opt.expiration_month(), opt.expiration_day());
|
||||
return {
|
||||
ts, Price::from_double(opt.strike()),
|
||||
opt.call_put() == bts::api::PUTORCALL_CALL ? bts::domain::protobufs::CallPut::CALL
|
||||
: bts::domain::protobufs::CallPut::PUT};
|
||||
opt.call_put() == bts::api::PUTORCALL_CALL
|
||||
? bts::domain::protobufs::CallPut::CALL
|
||||
: bts::domain::protobufs::CallPut::PUT};
|
||||
}
|
||||
|
||||
bts::domain::SpreadSecurity DomainSecurityUtils::convert(
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include "domain/protobufs/venue.pb.h"
|
||||
#include "domain/security.h"
|
||||
#include "domain/spread_security.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/md/protos/co2.pb.h"
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
@@ -15,14 +17,18 @@ class DomainSecurityUtils {
|
||||
static domain::Security convert(const bts::api::Security &sec);
|
||||
static domain::protobufs::Venue convert(bts::api::Venue venue);
|
||||
static bts::api::Venue convert(domain::protobufs::Venue venue);
|
||||
static bts::domain::protobufs::SecurityType convert(bts::api::SecurityType sec_type);
|
||||
static bts::api::SecurityType convert(bts::domain::protobufs::SecurityType sec_type);
|
||||
static bts::domain::protobufs::SecurityType convert(
|
||||
bts::api::SecurityType sec_type);
|
||||
static bts::api::SecurityType convert(
|
||||
bts::domain::protobufs::SecurityType sec_type);
|
||||
static bts::domain::FutureSecurity convert(
|
||||
const bts::api::FutureContract &fut);
|
||||
static bts::domain::OptionSecurity convert(
|
||||
const bts::api::OptionContract &opt);
|
||||
static bts::domain::SpreadSecurity convert(
|
||||
const bts::api::SpreadContract &spr);
|
||||
static domain::TradeRecord convert(const co2::TradeMessage &trade);
|
||||
|
||||
static bts::api::SecurityType get_type(const bts::api::Security &s);
|
||||
static std::string get_exchange_id(const bts::api::Security &s);
|
||||
static bool get_security_desc(
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#include "domain/side.h"
|
||||
#include "domain/spot_security.h"
|
||||
#include "domain/spread_security.h"
|
||||
#include "domain/trade_record.h"
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/domain/DomainSecurityUtils.h"
|
||||
#include "spark/domain/SecurityMarketDataStatistics.h"
|
||||
#include "spark/domain/TradeRecord.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/md/IntPrice.h"
|
||||
|
||||
Reference in new issue
Block a user