From 32038f89480ecaf92c85dcfaa84564993a2daedb Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Wed, 8 May 2019 16:36:11 -0400 Subject: [PATCH] Fixed algo API bug that could lead to lost order updates. --- .../orderman/orders/algo/AlgoWrapperOrder.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp b/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp index e53aa650f..b14e7c7ef 100644 --- a/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp +++ b/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp @@ -458,10 +458,21 @@ void AlgoWrapperOrder::detach_child(OrderKey child) { key().value(), child.value())); } +void AlgoWrapperOrder::detach_all_children() { + if (!is_working()) + return; + for (auto &[_, c] : me->children) { + (void)_; + c.order.mark_detached_from_parent(); + } + me->children.clear(); +} + void AlgoWrapperOrder::update_fill_state(Quantity q, Price p) { if (!is_working()) return; + ReportStateGuard _(*this); auto previous_qty = me->state().filled_quantity(); if (previous_qty > q.value()) { LOG(OrderMan, Error, @@ -483,13 +494,14 @@ void AlgoWrapperOrder::update_fill_state(Quantity q, Price p) { void AlgoWrapperOrder::cancel(std::string const &msg) { if (!is_working()) return; + ReportStateGuard _(*this); terminate(ORDER_STATUS_CANCELED, msg); } void AlgoWrapperOrder::terminate_error(std::string const &msg) { if (!is_working() && me->status != Status::W_ATTACH) return; - + ReportStateGuard _(*this); // If we attached and an error was signaled we do not want to // cancel our child because that child might be a long running // order with a good queue position that we want to preserve @@ -498,19 +510,10 @@ void AlgoWrapperOrder::terminate_error(std::string const &msg) { terminate(ORDER_STATUS_ERROR, msg); } -void AlgoWrapperOrder::detach_all_children() { - if (!is_working()) - return; - for (auto &[_, c] : me->children) { - (void)_; - c.order.mark_detached_from_parent(); - } - me->children.clear(); -} - void AlgoWrapperOrder::complete() { if (!is_working()) return; + ReportStateGuard _(*this); terminate(ORDER_STATUS_COMPLETED); }