diff --git a/src/data_files/documents/order_flow.txt b/src/data_files/documents/order_flow.txt new file mode 100644 index 000000000..9d629d24d --- /dev/null +++ b/src/data_files/documents/order_flow.txt @@ -0,0 +1,47 @@ +Order going out: +---------------- + +OrderServiceServer::create_order (Create) -> +ServiceBridge::create_order(Create) -> + publish(ActivateOrderEvent) +..... +..... +EMNativeOrder::activate (p, q, services) -> +OrderServices::queue_order_msg (CreateOrderMsg) -> +SessionServices::queue_order_msg(CreateOrderMsg) -> + _session_data->buffered_order_msgs->emplace_back(OrderMsg{order_op}) -> + +OrderManager has the handle to the same queue above (buffered_order_msgs) +In OrderManager::after_event it checks for messages and sends them to IExecutionGateway +(gw->send_msgs(queued_ops, osd->current_trace);) + + +EMExecutionGateway::send_msg(std::vector const &) +(this is where the order is actually sent out) + +Callbacks coming in: +-------------------- + +EMExecutionGateway::dispatch_incoming_fix_messages() -> +(EMExecutionGateway receives messages independently from the exchange and queues them, +in dispatch_incoming_fix_messages, it calls on_exe_report) + +EMExecutionGateway::on_exe_report(ExecutionReport) -> +OrderManager::publish(mercury::Stream + + +EMNativeOrder::_on_exe_report(const NewExecutionReportEvent &er) -> +EMNativeOrder::report_state() -> +OrderServices::report_state(OrderState) -> +OrderManager::publish(OrderStateUpdateEvent) -> + through the event system +OrderStore::on_order_state_update(mercury::Update const &) -> +OrderStore::publish(StoredOrderEvent) -> + through the event system +ServiceBridge::on(mercury::Update const &) -> +OrderServiceServer::on_orders(OrderRecord) +(goes out to the client) + +Fills: +------ +FillsStore listens to NewExecutionReportEvent, published by orderManager (above) diff --git a/src/lib/domain_model/common.h b/src/lib/domain_model/common.h index f0a034541..25f2c2bac 100644 --- a/src/lib/domain_model/common.h +++ b/src/lib/domain_model/common.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -12,8 +13,12 @@ struct CQuantity { constexpr static double err = 0.0000001; CQuantity() {} CQuantity(uint32_t whole_qty) : qty(whole_qty) {} + CQuantity(uint32_t int_qty, double fractional_qty) + : qty(int_qty + fractional_qty) {} uint32_t value() const { return static_cast(qty); } - double whole_value() const { return qty; } + double full_value() const { return qty; } + uint32_t int_part() { return static_cast(qty); } + double fractional_part() { return full_value() - int_part(); } static bool equal_d(double d1, double d2) { return std::abs(d1 - d2) <= err; } @@ -31,8 +36,8 @@ struct CQuantity { // qty = whole_qty; // return *this; // } - CQuantity &operator=(double whole_qty) noexcept { - qty = whole_qty; + CQuantity &operator=(double full_qty) noexcept { + qty = full_qty; return *this; } bool operator==(const CQuantity &rhs) const { return equal_d(qty, rhs.qty); } @@ -76,7 +81,7 @@ struct CQuantity { }; inline std::ostream &operator<<(std::ostream &out, CQuantity const &qty) { - out << qty.value(); + out << qty.full_value(); return out; } using Price = utils::ValueWrapper; diff --git a/src/lib/orderman/OrderMsg.h b/src/lib/orderman/OrderMsg.h index 0b53488c0..fef9326af 100644 --- a/src/lib/orderman/OrderMsg.h +++ b/src/lib/orderman/OrderMsg.h @@ -9,4 +9,24 @@ namespace bts::orderman { using OrderMsg = std::variant; +inline std::ostream &operator<<(std::ostream &out, OrderMsg const &msg) { + if (std::holds_alternative(msg)) { + const CreateOrderMsg &cr_msg = std::get(msg); + out << "Create Msg sec_id: " << cr_msg.security->id() + << " p: " << cr_msg.price.value() + << " q: " << cr_msg.quantity.full_value(); + } else if (std::holds_alternative(msg)) { + const CancelReplaceOrderMsg &cxlr_msg = + std::get(msg); + const CreateOrderMsg &cr_msg = cxlr_msg.create_fields; + out << "CancelReplace Msg sec_id: " << cr_msg.security->id() + << " p: " << cr_msg.price.value() + << " q: " << cr_msg.quantity.full_value(); + + } else if (std::holds_alternative(msg)) { + const CancelOrderMsg &cxl_msg = std::get(msg); + out << "Cancel Msg okey: " << cxl_msg.key.value(); + } + return out; +} } // namespace bts::orderman diff --git a/src/lib/orderman/OrderServiceServer.cpp b/src/lib/orderman/OrderServiceServer.cpp index 28f689bdb..858947f9f 100644 --- a/src/lib/orderman/OrderServiceServer.cpp +++ b/src/lib/orderman/OrderServiceServer.cpp @@ -304,6 +304,8 @@ void OrderServiceServer::on_orders( updated.reserve(orders.size()); for (auto const &rec : orders) { + LOG(OrderMan, Info, "OrderServiceServer::on_orders order: {}", + utils::pb::to_string(rec)); auto const &k = OrderKey(rec.key()); if (me->known_orders.count(k) == 0) { me->known_orders.insert(k); @@ -344,7 +346,8 @@ void OrderServiceServer::on_fills( void OrderServiceServer::create_order( const api::orderman::Create &c, const api::Response &r) { - + LOG(OrderMan, Info, "OrderServiceServer::create_order create: {}", + utils::pb::to_string(c)); if (!me->service_ready) { api::orderman::Response response; response.set_error_code(api::orderman::ORDER_ERROR_SERVER_NOT_READY); @@ -373,7 +376,8 @@ void OrderServiceServer::cancel_order( void OrderServiceServer::update_order( const api::orderman::Update &update, const api::Response &r) { - + LOG(OrderMan, Info, "OrderServiceServer::update_order update: {}", + utils::pb::to_string(update)); if (!me->service_ready) { api::orderman::Response response; response.set_order_key(update.order_key()); diff --git a/src/lib/orderman/OrderServices.cpp b/src/lib/orderman/OrderServices.cpp index 34ccc7066..1a539d170 100644 --- a/src/lib/orderman/OrderServices.cpp +++ b/src/lib/orderman/OrderServices.cpp @@ -1,4 +1,5 @@ #include "OrderServices.h" +#include "lib/logging/logging.h" #include "lib/orderman/ChildOrder.h" namespace bts::orderman { @@ -324,8 +325,9 @@ OrderOpResult OrderServices::check_is_attachable() { case ORDER_STATUS_PENDING_WORKING: case ORDER_STATUS_DISCONNECTED: case ORDER_STATUS_WORKING: - return OrderOpResult{ORDER_ERROR_INVALID_OP, - "Child order already has a working parent"}; + return OrderOpResult{ + ORDER_ERROR_INVALID_OP, + "Child order already has a working parent"}; break; case ORDER_STATUS_REJECTED_BY_SPARK: case ORDER_STATUS_COMPLETED: @@ -374,6 +376,8 @@ void OrderServices::cancel(OrderOpCallback const &on_order_op) { // Activate a child of this order void OrderServices::activate_child( Order &o, Price p, Quantity q, OrderOpCallback const &cb) { + LOG(OrderMan, Info, "OrderServices::activate_child key: {} p: {} q: {}", + o.key(), p, q); _data->owner.add_child_order(*this, o); o._services->activate(p, q, cb); } diff --git a/src/lib/orderman/actors/FillStore.cpp b/src/lib/orderman/actors/FillStore.cpp index b34a0f91d..6fabe9fc0 100644 --- a/src/lib/orderman/actors/FillStore.cpp +++ b/src/lib/orderman/actors/FillStore.cpp @@ -154,6 +154,8 @@ void FillStore::on_execution_report( u.events == nullptr ? 0 : u.events->size()); if (u.events) { for (auto const &ev : *u.events) { + 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_str(er.exchange_fill_id)); @@ -176,7 +178,7 @@ void FillStore::on_execution_report( fill.set_last_price(er.last_price.value()); fill.set_avg_price(er.avg_price.value()); fill.set_side(er.side); - fill.set_last_shares(er.last_shares.value()); + fill.set_last_shares(er.last_shares.full_value()); fill.set_fill_status(api::orderman::Fill::FILL_STATUS_ACTIVE); if (er.exec_type == api::orderman::EXEC_TYPE_TRADE_CORRECT) fill.set_fill_status( diff --git a/src/lib/orderman/actors/OrderStore.cpp b/src/lib/orderman/actors/OrderStore.cpp index 7b7dd8ab8..0ab897e50 100644 --- a/src/lib/orderman/actors/OrderStore.cpp +++ b/src/lib/orderman/actors/OrderStore.cpp @@ -100,7 +100,11 @@ void OrderStore::on_order_state_update( std::set modified_orders; if (u.events) for (auto const &ev : *u.events) { - + LOG(OrderMan, Info, + "OrderStore::on_order_state_update k: {} p: {} q: {} key_exists: " + "{}", + ev.key, ev.price, ev.quantity, + me->known_orders.find(ev.key) != me->known_orders.end()); auto &rec_info = me->known_orders[ev.key]; LOG(iLink3, Info, "Received order state update for {}", ev.key.value()); @@ -144,6 +148,9 @@ void OrderStore::store_and_publish_if_complete( auto &rec_info = me->known_orders[k]; auto &rec = rec_info.rec; if (rec.has_def() && rec.has_state()) { + LOG(OrderMan, Info, + "OrderStore::store_and_publish_if_complete rec: {}", + utils::pb::to_string(rec)); publish(me->order_stream, rec); if (rec_info.is_saved) { me->store->update( diff --git a/src/lib/orderman/actors/ServiceBridge.cpp b/src/lib/orderman/actors/ServiceBridge.cpp index 9ed3d561e..e3aec9ebf 100644 --- a/src/lib/orderman/actors/ServiceBridge.cpp +++ b/src/lib/orderman/actors/ServiceBridge.cpp @@ -195,7 +195,7 @@ void ServiceBridge::create_order(uint32_t rid, api::orderman::Create const &c) { me->known_orders.insert(order.key()); publish( me->activate_order_pub, rid, order, Price(c.price()), - Quantity(c.quantity())); + bts::orderman::get_create_quantity(c)); } else me->on_order_op_result(OrderOpResultEvent( null_order_key(), rid, diff --git a/src/lib/orderman/actors/order_manager/OrderManager.cpp b/src/lib/orderman/actors/order_manager/OrderManager.cpp index 64c359c2e..3c59844df 100644 --- a/src/lib/orderman/actors/order_manager/OrderManager.cpp +++ b/src/lib/orderman/actors/order_manager/OrderManager.cpp @@ -252,8 +252,10 @@ void OrderManager::on_activate_order( const mercury::Update &m) { if (m.events) for (auto const &ev : *m.events) { + LOG(OrderMan, Info, + "OrderManager::on_activate_order req_id: {} p: {} q: {}", + ev.req_id, ev.price, ev.quantity); auto order = ev.order; - auto const &def = order->def(); publish_order_def_update(order->key(), def); order->init_order_services(me->services_data); diff --git a/src/lib/orderman/events/OrderStateUpdateEvent.h b/src/lib/orderman/events/OrderStateUpdateEvent.h index 7a1869079..c2e777487 100644 --- a/src/lib/orderman/events/OrderStateUpdateEvent.h +++ b/src/lib/orderman/events/OrderStateUpdateEvent.h @@ -1,9 +1,12 @@ #pragma once #include "lib/api/services/OrderService.pb.h" +#include "lib/logging/logging.h" #include "lib/mercury/events/Event.h" #include "lib/orderman/order_factory/OrderFactory.h" +#include "lib/orderman/orderman_utils/orderman_common.h" #include "lib/tracing/PerfLog.h" +#include "lib/utils/PBUtils.h" #include @@ -35,11 +38,18 @@ class OrderStateUpdateEvent : public mercury::Event { definition = def; status = state.status(); price = state.price(); - quantity = state.quantity(); - filled_quantity = state.filled_quantity(); + quantity = + bts::orderman::get_quantity(state, StateQuantityType::OrderQuantity) + .full_value(); + filled_quantity = + bts::orderman::get_quantity(state, StateQuantityType::FilledQuantity) + .full_value(); last_price = state.last_price(); avg_price = state.avg_price(); - filled_at_attach_time_quantity = state.filled_at_attach_time_quantity(); + filled_at_attach_time_quantity = + bts::orderman::get_quantity( + state, StateQuantityType::FilledAtAttachQuantity) + .full_value(); last_msg = state.last_msg(); display_status = state.display_status(); @@ -72,11 +82,11 @@ class OrderStateUpdateEvent : public mercury::Event { // common state api::orderman::OrderStatus status; double price; - uint32_t quantity; - uint32_t filled_quantity; + double quantity; + double filled_quantity; double last_price; double avg_price; - uint32_t filled_at_attach_time_quantity; + double filled_at_attach_time_quantity; std::string last_msg; api::orderman::OrderState::DisplayStatus display_status; api::orderman::OrderState::CustomCase custom; @@ -100,11 +110,15 @@ class OrderStateUpdateEvent : public mercury::Event { api::orderman::OrderState result; result.set_status(status); result.set_price(price); - result.set_quantity(quantity); - result.set_filled_quantity(filled_quantity); + bts::orderman::set_quantity( + result, StateQuantityType::OrderQuantity, quantity); + bts::orderman::set_quantity( + result, StateQuantityType::FilledQuantity, filled_quantity); result.set_last_price(last_price); result.set_avg_price(avg_price); - result.set_filled_at_attach_time_quantity(filled_at_attach_time_quantity); + bts::orderman::set_quantity( + result, StateQuantityType::FilledAtAttachQuantity, + filled_at_attach_time_quantity); result.set_last_msg(last_msg); result.set_display_status(display_status); return result; @@ -202,8 +216,8 @@ class OrderStateUpdateEvent : public mercury::Event { st->set_last_transact_time_unix_ns(last_transact_time_unix_ns.value()); } - api::orderman::NativeOrderState const * - get_native_state(api::orderman::OrderState const &st) { + api::orderman::NativeOrderState const *get_native_state( + api::orderman::OrderState const &st) { switch (st.custom_case()) { case api::orderman::OrderState::kMarket: return &st.market().native_state(); diff --git a/src/lib/orderman/gateways/EMExecutionGateway.cpp b/src/lib/orderman/gateways/EMExecutionGateway.cpp index c4f8b8d77..87c3e0a8c 100644 --- a/src/lib/orderman/gateways/EMExecutionGateway.cpp +++ b/src/lib/orderman/gateways/EMExecutionGateway.cpp @@ -277,6 +277,7 @@ void EMExecutionGateway::send_msgs( LOG(OrderMan, Info, "EMExecutionGateway::send_msgs count: {}", msg_vec.size()); for (const auto &m : msg_vec) { + LOG(OrderMan, Info, "EMExecutionGateway::send_msgs {}", m); if (std::holds_alternative(m)) { const CreateOrderMsg &cr_msg = std::get(m); _send_create(cr_msg); @@ -309,9 +310,9 @@ bool EMExecutionGateway::_init() { me->order_mux->order_update_cb() = [this](const auto &er, const auto &key, const auto &state) { LOG(OrderMan, Info, - "EMExecutionGateway received order callback for " - "key: {}", - key.value()); + "EMExecutionGateway received order callback for key: {} " + "state: {}", + key.value(), state); me->order_cb_queue.push({er, key, state}); }; me->order_mux->exchange_position_update_cb() = @@ -335,7 +336,8 @@ bool EMExecutionGateway::_init() { // converts the CreateOrderMsg to emumba::order_entry::new_order and // sends it to EM gateway void EMExecutionGateway::_send_create(const CreateOrderMsg &c) { - LOG(OrderMan, Info, "EMExecutionGateway::_send_create key: {}", c.key); + LOG(OrderMan, Info, "EMExecutionGateway::_send_create key: {} p: {} q: {}", + c.key, c.price, c.quantity); emumba::order_entry::new_order new_order; // only assuming deribit for now, as we add exchanges we fix it here bts_assert_msg( @@ -348,7 +350,7 @@ void EMExecutionGateway::_send_create(const CreateOrderMsg &c) { new_order.order_def.time_in_frc = convert_tif(c.time_in_force); // price, qty new_order.px = emumba::market_data::price(c.price.value()); - new_order.qty.value() = c.quantity.whole_value(); + new_order.qty.value() = c.quantity.full_value(); // order_def.exchange_order emumba::order_entry::deribit_order_definition deribit_def; emumba::order_entry::deribit_order_def_optional deribit_def_optionals; @@ -386,12 +388,12 @@ void EMExecutionGateway::_send_cxl_replace( emumba::order_entry::order_key(em_key), emumba::market_data::price(cxl_rpl.create_fields.price.value()), emumba::market_data::quantity( - cxl_rpl.create_fields.quantity.whole_value())}; + cxl_rpl.create_fields.quantity.full_value())}; me->order_mux->update_order(update); } void EMExecutionGateway::_send_cxl(const CancelOrderMsg &cxl) { - LOG(OrderMan, Info, "EMExecutionGateway::_send_create key: {}", cxl.key); + LOG(OrderMan, Info, "EMExecutionGateway::_send_cxl key: {}", cxl.key); auto it = me->key_map.find(cxl.key); if (it == me->key_map.end()) { LOG(OrderMan, Error, @@ -407,6 +409,8 @@ void EMExecutionGateway::_send_cxl(const CancelOrderMsg &cxl) { void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) { // this is the only tricky part here because ... EMOrderKey key = em_cb.order_key.value(); + LOG(OrderMan, Info, "EMExecutionGateway::_process_cb_and_fire_er key: {} {}", + key, em_cb.order_state); auto it = me->order_map.find(key); if (it == me->order_map.end()) { LOG(OrderMan, Error, @@ -450,7 +454,7 @@ void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) { er.exec_type = api::orderman::ExecType::EXEC_TYPE_FILL; } er.last_price = Price(em_cb.order_state.last_filled_price); - er.last_shares = Quantity(em_cb.order_state.last_filled_qty); + er.last_shares = em_cb.order_state.last_filled_qty; // TODO: this should be part of the update utils::Uuid guid; std::string fill_id = guid.to_text_string(); diff --git a/src/lib/orderman/limiter/Limiter.cpp b/src/lib/orderman/limiter/Limiter.cpp index ebc156b9b..a0cba29a7 100644 --- a/src/lib/orderman/limiter/Limiter.cpp +++ b/src/lib/orderman/limiter/Limiter.cpp @@ -35,7 +35,7 @@ struct StaticLimiter { if (r.sec_tup().symbol() == sec.symbol() && r.sec_tup().venue() == sec.exchange() && r.sec_tup().type() == type(sec)) { - if (quantity.whole_value() <= r.clip_size()) + if (quantity.full_value() <= r.clip_size()) return Limiter::LimiterQueryResult{ "", Limiter::LimiterErrorCode::OK}; else diff --git a/src/lib/orderman/orderman_utils/ExecutionReport.cpp b/src/lib/orderman/orderman_utils/ExecutionReport.cpp index 61a07ca7d..f3ef4c8f0 100644 --- a/src/lib/orderman/orderman_utils/ExecutionReport.cpp +++ b/src/lib/orderman/orderman_utils/ExecutionReport.cpp @@ -23,10 +23,9 @@ std::string ExecutionReport::to_string() const { << " exec_type: " << bts::api::orderman::ExecType_Name(exec_type) << " order_status: " << bts::api::orderman::NativeOrderStatus_Name(order_status) - << " price: " << price.value() << " quantity: " << quantity.value() - << " filled_quantity: " << filled_quantity.value() - << " avg_price: " << avg_price.value() - << " last_shares: " << last_shares.value() + << " price: " << price.value() << " quantity: " << quantity + << " filled_quantity: " << filled_quantity + << " avg_price: " << avg_price.value() << " last_shares: " << last_shares << " last_price: " << last_price.value() << " msg: " << msg << " exchange: " << bts::api::Venue_Name(exchange); return rv.str(); diff --git a/src/lib/orderman/orderman_utils/orderman_common.h b/src/lib/orderman/orderman_utils/orderman_common.h index d9d693f3f..e55445427 100644 --- a/src/lib/orderman/orderman_utils/orderman_common.h +++ b/src/lib/orderman/orderman_utils/orderman_common.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -199,5 +200,77 @@ inline void set_last_transact_time( } #endif +enum StateQuantityType { + OrderQuantity = 0, + FilledQuantity = 1, + FilledAtAttachQuantity = 2 +}; + +Quantity inline get_quantity( + const bts::api::orderman::OrderState &state, StateQuantityType q_type) { + switch (q_type) { + case StateQuantityType::OrderQuantity: + return Quantity( + state.quantity(), state.has_fractional_quantity() + ? state.fractional_quantity().fraction() + : 0.0); + case StateQuantityType::FilledQuantity: + return Quantity( + state.filled_quantity(), + state.has_fractional_filled_quantity() + ? state.fractional_filled_quantity().fraction() + : 0.0); + case StateQuantityType::FilledAtAttachQuantity: + return Quantity( + state.filled_at_attach_time_quantity(), + state.has_fractional_filled_at_attach_time_quantity() + ? state.fractional_filled_at_attach_time_quantity().fraction() + : 0.0); + } + bts_assert(false); + return Quantity( + state.quantity(), state.has_fractional_quantity() + ? state.fractional_quantity().fraction() + : 0.0); +} + +inline void set_quantity( + bts::api::orderman::OrderState &state, + StateQuantityType q_type, + Quantity cqty) { + uint32_t int_qty = cqty.int_part(); + double fractional_qty = cqty.fractional_part(); + switch (q_type) { + case StateQuantityType::OrderQuantity: + state.set_quantity(int_qty); + state.mutable_fractional_quantity()->set_fraction(fractional_qty); + break; + case StateQuantityType::FilledQuantity: + state.set_filled_quantity(int_qty); + state.mutable_fractional_filled_quantity()->set_fraction(fractional_qty); + break; + case StateQuantityType::FilledAtAttachQuantity: + state.set_filled_at_attach_time_quantity(int_qty); + state.mutable_fractional_filled_at_attach_time_quantity()->set_fraction( + fractional_qty); + } +} + +inline void set_quantity( + bts::api::orderman::OrderState &state, + StateQuantityType q_type, + double qty) { + Quantity cqty; + cqty = qty; + set_quantity(state, q_type, cqty); +} + +inline Quantity get_create_quantity(const bts::api::orderman::Create &c) { + auto rv = Quantity( + c.quantity(), + c.has_fractional_quantity() ? c.fractional_quantity().fraction() : 0.0); + return rv; +} + } // namespace orderman } // namespace bts diff --git a/src/lib/orderman/orders/EMNativeOrder.cpp b/src/lib/orderman/orders/EMNativeOrder.cpp index 4a8cc75bd..d02ed7f3a 100644 --- a/src/lib/orderman/orders/EMNativeOrder.cpp +++ b/src/lib/orderman/orders/EMNativeOrder.cpp @@ -218,6 +218,7 @@ OrderOpResult EMNativeOrder::on_update(Price p, Quantity q) { api::orderman::Update update; update.set_price(p.value()); update.set_quantity(q.value()); + update.mutable_fractional_quantity()->set_fraction(q.fractional_part()); return on_update(update); } @@ -450,6 +451,8 @@ Quantity EMNativeOrder::working_position() { void EMNativeOrder::report_state() { update_working_position(); + LOG(OrderMan, Info, "EMNativeOrder::report_state state: {}", + utils::pb::to_string(me->state)); me->services->report_state(me->state); } @@ -460,9 +463,10 @@ OrderOpResult EMNativeOrder::_on_activate( Quantity q, bts::orderman::OrderServices & /*order_services*/) { + LOG(OrderMan, Info, "EMNativeOrder::_on_activate p: {} q: {}", p, q); // update state wrt price, qty, fills me->state.set_price(p.value()); - me->state.set_quantity(q.value()); + bts::orderman::set_quantity(me->state, StateQuantityType::OrderQuantity, q); me->state.set_filled_quantity(0); me->state.set_last_price(0); me->state.set_avg_price(0); @@ -558,6 +562,8 @@ OrderOpResult EMNativeOrder::_on_activate( }); LOG(OrderMan, Info, "EMNativeOrder::_on_activate sucessful key: {}", key()); + LOG(OrderMan, Info, "EMNativeOrder::_on_activate state: {}", + utils::pb::to_string(me->state)); return OrderOpResult{}; } @@ -596,7 +602,8 @@ NativeOrderType get_native_ord_type(const OrderDefinition &def) { void EMNativeOrder::_create_create_msg(CreateOrderMsg &c) { c.key = key(); c.price = Price(me->state.price()); - c.quantity = Quantity(me->state.quantity()); + c.quantity = + bts::orderman::get_quantity(me->state, StateQuantityType::OrderQuantity); c.security = me->sec; c.side = me->definition.side(); c.order_type = get_native_ord_type(me->definition); @@ -604,6 +611,8 @@ void EMNativeOrder::_create_create_msg(CreateOrderMsg &c) { c.order_type = api::orderman::NATIVE_ORDER_TYPE_LIMIT; c.manual_order_indicator = me->definition.manual_order_indicator(); c.routing_record = &me->routing_record; + LOG(OrderMan, Info, "EMNativeOrder::_create_create_msg c.qty: {}", + c.quantity); } void EMNativeOrder::_on_exe_report(const NewExecutionReportEvent &er) { @@ -628,7 +637,9 @@ void EMNativeOrder::_on_exe_report(const NewExecutionReportEvent &er) { auto _absorb_er = [this, &er, &er_status]() { // this is not set in on_update, but only set when the exchange ack's it me->state.set_price(er.data->price.value()); - me->state.set_quantity(er.data->quantity.value()); + // me->state.set_quantity(er.data->quantity.value()); + bts::orderman::set_quantity( + me->state, StateQuantityType::OrderQuantity, er.data->quantity); _absorb_fill(*er.data); transition(er_status); }; diff --git a/src/server/sparkd/md/platforms/emumba/IEMOrderMuxer.h b/src/server/sparkd/md/platforms/emumba/IEMOrderMuxer.h index 679969d79..c9b256e62 100644 --- a/src/server/sparkd/md/platforms/emumba/IEMOrderMuxer.h +++ b/src/server/sparkd/md/platforms/emumba/IEMOrderMuxer.h @@ -10,6 +10,7 @@ namespace bts::orderman { +// This is the order data passed by the EmMDListener via the order_update_cb struct EMOrderState { double order_px; double order_qty; @@ -60,6 +61,16 @@ struct EMOrderState { } }; +inline std::ostream &operator<<(std::ostream &out, EMOrderState const &s) { + out << "status: " << static_cast(s.status) << " pr: " << s.order_px + << " q: " << s.order_qty << " fills: " << s.total_fills + << " avg_filled_price: " << s.avg_filled_price + << " last_fills: " << s.last_filled_qty + << " last_filled_pr: " << s.last_filled_price + << " n_trades: " << s.trades.size(); + return out; +} + using OnEMOrderUpdate = std::function &)>; +// This is the order interface around the EMumba adapter, currently implemented +// by EmMDListener and used by the EMExecutionGateway +// EMExecutionGateway <-> EmMDListener::IEMOrderMuxer <-> external EMumba code class IEMOrderMuxer { public: // Orders ////////////////////////////////////////////////////////////////// diff --git a/src/server/sparkd/position/PositionServiceServer.cpp b/src/server/sparkd/position/PositionServiceServer.cpp index e8c31f104..c3e511409 100644 --- a/src/server/sparkd/position/PositionServiceServer.cpp +++ b/src/server/sparkd/position/PositionServiceServer.cpp @@ -257,6 +257,12 @@ void PositionServiceServer::reset_position( "PositionServiceServer::reset_position acct: {} n_recs: {}", reset_params.account(), reset_params.total_position().manual_fill().size()); + for (const auto &f : reset_params.total_position().manual_fill()) { + LOG(OrderMan, Info, + "PositionServiceServer::reset_position acct: {} fill: {}", + reset_params.account(), utils::pb::to_string(f)); + } + // find existing fills for this account and remove them auto all = me->manual_fills_store->retrieve_all()[manual_fills_ns]; ManualFillBatch fills_to_remove;