refactor: Use SmallString instead of std::array in ExchangeFillID
This commit is contained in:
1 parent
c1ba8c177e
commit
8774e55a40
14 files changed
+39
-19
No files matched your search
@@ -522,7 +522,7 @@ void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) {
|
||||
// TODO: this should be part of the update
|
||||
utils::Uuid guid;
|
||||
std::string fill_id = guid.to_text_string();
|
||||
to_array(fill_id, &er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(fill_id);
|
||||
} else {
|
||||
er.last_shares = Quantity(0);
|
||||
}
|
||||
@@ -581,7 +581,7 @@ void EMExecutionGateway::_fire_leg_er(
|
||||
l_er.msg_seq_num = me->msg_seq_num++;
|
||||
utils::Uuid guid;
|
||||
std::string fill_id = guid.to_text_string();
|
||||
to_array(fill_id, &l_er.exchange_fill_id.value());
|
||||
l_er.exchange_fill_id->copy_from(fill_id);
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::_fire_leg_er firing er: {}",
|
||||
l_er.to_string());
|
||||
me->on_exe_report(
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ bool OrderUpdate::to_execution_report(
|
||||
filled_quantity > 0 ? quote_asset_transacted_quantity / filled_quantity
|
||||
: 0.0;
|
||||
er.stop_price.value() = stop_price;
|
||||
copy_to_array<40>(std::to_string(trade_id), er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(std::to_string(trade_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ bool OrderUpdate::to_execution_report(
|
||||
filled_quantity > 0 ? quote_asset_transacted_quantity / filled_quantity
|
||||
: 0.0;
|
||||
er.stop_price.value() = stop_price;
|
||||
copy_to_array<40>(std::to_string(trade_id), er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(std::to_string(trade_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ bool OrderUpdate::to_execution_report(
|
||||
filled_quantity > 0 ? quote_asset_transacted_quantity / filled_quantity
|
||||
: 0.0;
|
||||
er.stop_price.value() = stop_price;
|
||||
copy_to_array<40>(std::to_string(trade_id), er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(std::to_string(trade_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -37,8 +37,7 @@ bool OrderUpdate::to_execution_report(
|
||||
er.last_price.value() = data.last_filled_price;
|
||||
er.avg_price.value() = data.avg_price;
|
||||
er.stop_price.value() = data.stop_price;
|
||||
copy_to_array<40>(
|
||||
std::to_string(data.trade_id), er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(std::to_string(data.trade_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ struct OkxExecutionGateway::PImpl {
|
||||
} else if (!(order.at("fillSz").get<std::string>() == "0")) {
|
||||
utils::Uuid guid;
|
||||
std::string fill_id = guid.to_text_string();
|
||||
to_array(fill_id, &report.exchange_fill_id.value());
|
||||
report.exchange_fill_id->copy_from(fill_id);
|
||||
}
|
||||
|
||||
// report.transact_time = ExchangeTimeStampVar(std::stoll(order.at("uTime").get<std::string>()));
|
||||
|
||||
@@ -171,7 +171,7 @@ void OnixFixListener::get_exe_report(Message msg, ExecutionReport &er) {
|
||||
|
||||
auto exec_id_str = msg.get(FIX42::Tags::ExecID);
|
||||
std::string fill_id = exec_id_str.valid() ? exec_id_str.toString() : bts::utils::Uuid().to_text_string();
|
||||
to_array(fill_id, &er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(fill_id);
|
||||
|
||||
auto last_px_str = msg.get(FIX42::Tags::LastPx);
|
||||
er.last_price = Price(last_px_str.valid() ? std::stod(last_px_str.toString()) : 0);
|
||||
|
||||
@@ -277,8 +277,8 @@ void FillStore::on_execution_report(
|
||||
LOG(OrderMan, Info, "FillStore::on_execution_report er: {}",
|
||||
ev.data->to_string());
|
||||
auto &er = *ev.data;
|
||||
auto fk = fmt::format(
|
||||
"{}:{}", er.order_key.value(), to_strn(er.exchange_fill_id));
|
||||
auto fk =
|
||||
fmt::format("{}:{}", er.order_key.value(), er.exchange_fill_id);
|
||||
auto is_known = me->known_fills.count(fk);
|
||||
if (er.exec_type == api::orderman::EXEC_TYPE_PARTIAL_FILL ||
|
||||
er.exec_type == api::orderman::EXEC_TYPE_FILL) {
|
||||
|
||||
@@ -373,7 +373,7 @@ void CCAPIExecutionGateway::_on_order_cb(const CCAPIOrderState &s) {
|
||||
auto &tr = s.cb_trades.back();
|
||||
er.last_price = Price(tr.last_exec_price);
|
||||
er.last_shares = Quantity::create_new(tr.last_exec_qty);
|
||||
to_array(tr.trade_id, &er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(tr.trade_id);
|
||||
} else {
|
||||
er.last_shares = Quantity(0);
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
*last_px_sec, Price(msg.get<fix::AvgPx>()))
|
||||
: Price(0);
|
||||
if (msg.has<fix::ExecID>())
|
||||
str_to(msg.get<fix::ExecID>(), &data->exchange_fill_id);
|
||||
data->exchange_fill_id->copy_from(msg.get<fix::ExecID>());
|
||||
orderman::ExchangeTimeStampStr t;
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &t);
|
||||
data->transact_time = t;
|
||||
|
||||
@@ -451,7 +451,7 @@ void ICEExecutionGateway::on_exe_report(
|
||||
: Price(0);
|
||||
if (msg.has<fix::ExecID>()) {
|
||||
auto execid = msg.get<fix::ExecID>();
|
||||
str_to(execid, &data->exchange_fill_id);
|
||||
data->exchange_fill_id->copy_from(msg.get<fix::ExecID>());
|
||||
if (msg.has<fix::Memo>())
|
||||
me->exec_id_to_memo[execid] = msg.get<fix::Memo>();
|
||||
}
|
||||
|
||||
@@ -789,7 +789,7 @@ void fill_execution_report(const SEGOrderState &seg_os, ExecutionReport &er) {
|
||||
if (!seg_os.last_filled_qty.is_zero()) {
|
||||
bts::utils::Uuid guid;
|
||||
std::string fill_id = guid.to_text_string();
|
||||
to_array(fill_id, &er.exchange_fill_id.value());
|
||||
er.exchange_fill_id->copy_from(fill_id);
|
||||
er.exec_type = api::orderman::EXEC_TYPE_PARTIAL_FILL;
|
||||
if (!seg_os.active()) {
|
||||
er.exec_type = api::orderman::EXEC_TYPE_FILL;
|
||||
|
||||
@@ -75,8 +75,7 @@ bool IL3Parser::parse_common(const T &msg, ExecutionReport *data) {
|
||||
|
||||
template <class T>
|
||||
void IL3Parser::parse_trade(const T &msg, ExecutionReport *data) {
|
||||
orderman::to_array(
|
||||
msg.getExecIDAsStringView(), &data->exchange_fill_id.value());
|
||||
data->exchange_fill_id->copy_from(msg.getExecIDAsStringView());
|
||||
switch (msg.ordStatus()) {
|
||||
case iLinkBinary::OrdStatusTrd::Filled:
|
||||
data->order_status =
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/core/small_string.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
using ExchangeFillID =
|
||||
utils::ValueWrapper<struct ExchangeFillIDTag, core::SmallString<40>>;
|
||||
|
||||
inline void to_json(nlohmann::json &j, const ExchangeFillID &id) {
|
||||
j = id.value();
|
||||
}
|
||||
|
||||
inline void from_json(const nlohmann::json &j, ExchangeFillID &id) {
|
||||
j.get_to(id.value());
|
||||
}
|
||||
|
||||
} // namespace bts::orderman
|
||||
|
||||
FMT_IMPL(bts::orderman::ExchangeFillID, a, "{}", a->to_string_view());
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
#include "spark/api/services/OrderService.pb.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/core/small_string.h"
|
||||
#include "spark/domain_model/common.h"
|
||||
#include "spark/orderman/account_id.h"
|
||||
#include "spark/orderman/account_name.h"
|
||||
#include "spark/orderman/order_key.h"
|
||||
#include "spark/orderman/orderman_utils/exchange_fill_id.h"
|
||||
#include "spark/orderman/orderman_utils/exchange_order_id.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
@@ -29,8 +31,6 @@ using UserID = utils::ValueWrapper<struct UserIDTag, uint32_t>;
|
||||
using OperatorID =
|
||||
utils::ValueWrapper<struct OperatorIDTag, std::array<char, 20>>;
|
||||
using GatewayName = utils::ValueWrapper<struct GatewayNameTag, std::string>;
|
||||
using ExchangeFillID =
|
||||
utils::ValueWrapper<struct ExchangeFillIDTag, std::array<char, 40>>;
|
||||
const uint16_t NullTickToTradeCorID = 0;
|
||||
const auto fix_buffer_pool_size = 10000;
|
||||
|
||||
|
||||
Reference in new issue
Block a user