From cb2b15f10bc107ff7dc0570ebe88dcfbed1a8e37 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Thu, 3 Apr 2025 23:23:56 +0000 Subject: [PATCH] Adding IOC to SimExecution --- .../gateways/sim/SimExecutionGateway.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/lib/orderman/gateways/sim/SimExecutionGateway.cpp b/src/lib/orderman/gateways/sim/SimExecutionGateway.cpp index f77d1b82f..1f64ef60d 100644 --- a/src/lib/orderman/gateways/sim/SimExecutionGateway.cpp +++ b/src/lib/orderman/gateways/sim/SimExecutionGateway.cpp @@ -14,6 +14,8 @@ #include "lib/md/MDProducer.h" #include "lib/md/PriceSize.h" #include "lib/md/Shm/MDStructure.h" +#include "lib/orderman/CancelOrderMsg.h" +#include "lib/orderman/CreateOrderMsg.h" #include "lib/orderman/OrderMsg.h" #include "lib/orderman/events/NewAdminDataEvent.h" #include "lib/orderman/events/NewSecuritiesEvent.h" @@ -180,6 +182,10 @@ struct SEGOrderState { last_filled_qty = 0; last_filled_price = Price(os::nan()); } + bool is_ioc() const { + return crt_msg.time_in_force == + api::orderman::TimeInForce::TIME_IN_FORCE_IOC; + } }; struct SEGTradeEntry { @@ -226,8 +232,10 @@ struct SEGSecurityData { const CancelReplaceOrderMsg &cxlr_msg = std::get(msg); SEGOrderState *seg_os = find_order(cxlr_msg.create_fields.key); - if(seg_os == nullptr){ - LOG(OrderMan, Info, "SimExecutionGateway::apply_order_action tried updating unkown order"); + if (seg_os == nullptr) { + LOG(OrderMan, Info, + "SimExecutionGateway::apply_order_action tried updating unkown " + "order"); return {ActionResult::NoOp, nullptr}; } auto action_result = seg_os->apply_change(cxlr_msg); @@ -235,8 +243,10 @@ struct SEGSecurityData { } else if (std::holds_alternative(msg)) { const CancelOrderMsg &cxl_msg = std::get(msg); SEGOrderState *seg_os = find_order(cxl_msg.key); - if(seg_os == nullptr){ - LOG(OrderMan, Info, "SimExecutionGateway::apply_order_action tried canceling unkown order"); + if (seg_os == nullptr) { + LOG(OrderMan, Info, + "SimExecutionGateway::apply_order_action tried canceling " + "unkown order"); return {ActionResult::NoOp, nullptr}; } auto action_result = seg_os->apply_cxl(cxl_msg); @@ -578,6 +588,14 @@ bts::orderman::Book SimExecutionGateway::_match_order( if (crosses_opp_side) { return _cross_order(book, seg_os); } else { + if (seg_os.is_ioc()) { + CancelOrderMsg cxl_msg; + cxl_msg.key = seg_os.ord_key(); + seg_os.apply_cxl(cxl_msg); + _push_execution_report(seg_os); + // generate cancel execution report + return book; + } return _work_order(book, seg_os); } } @@ -651,7 +669,8 @@ SEGSecurityData *SimExecutionGateway::_find_add_security_entry( void SimExecutionGateway::_push_execution_report(const SEGOrderState &seg_os) { ExecutionReport er; fill_execution_report(seg_os, er); - me->buffered_exec_reps.push(std::make_shared(std::move(er))); + me->buffered_exec_reps.push( + std::make_shared(std::move(er))); } void SimExecutionGateway::_write_book(SecurityKey key) {