AlgoWrapper was not publishing the filled fractional qtys, fixed now
This commit is contained in:
1 parent
a5874a59f0
commit
be9067b22e
1 file changed
+18
-15
@@ -1,4 +1,5 @@
|
||||
#include "lib/orderman/orders/algo/AlgoWrapperOrder.h"
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/orderman/ChildOrder.h"
|
||||
#include "lib/orderman/OrderBuilder.h"
|
||||
@@ -88,7 +89,7 @@ struct AlgoWrapperOrder::PImpl {
|
||||
void set_price_quantity(Price p, Quantity q) {
|
||||
is_state_dirty = true;
|
||||
_state.set_price(p.value());
|
||||
_state.set_quantity(q.value());
|
||||
set_quantity(_state, StateQuantityType::OrderQuantity, q);
|
||||
}
|
||||
|
||||
void set_fill_quantities(
|
||||
@@ -97,17 +98,18 @@ struct AlgoWrapperOrder::PImpl {
|
||||
Price avg_price,
|
||||
bool set_attach_time_fills) {
|
||||
is_state_dirty = true;
|
||||
_state.set_filled_quantity(total_fills.value());
|
||||
set_quantity(_state, StateQuantityType::FilledQuantity, total_fills);
|
||||
_state.set_last_price(last_price.value());
|
||||
_state.set_avg_price(avg_price.value());
|
||||
if (set_attach_time_fills) {
|
||||
LOG(OrderMan, Diag,
|
||||
"AlgoWrapperOrder {} setting fill at attach time to {}",
|
||||
_my_key.value(), total_fills.value());
|
||||
_state.set_filled_at_attach_time_quantity(total_fills.value());
|
||||
"AlgoWrapperOrder {} setting fill at attach time to {}", _my_key,
|
||||
total_fills);
|
||||
set_quantity(
|
||||
_state, StateQuantityType::FilledAtAttachQuantity, total_fills);
|
||||
} else
|
||||
LOG(OrderMan, Diag, "AlgoWrapperOrder {} settings fills to {}",
|
||||
_my_key.value(), total_fills.value());
|
||||
_my_key, total_fills);
|
||||
}
|
||||
|
||||
void set_ladder_visibility(bool is_visible) {
|
||||
@@ -683,25 +685,26 @@ void AlgoWrapperOrder::detach_all_children() {
|
||||
void AlgoWrapperOrder::update_fill_state(Quantity q, Price p) {
|
||||
if (!is_working() && !is_shutting_down())
|
||||
return;
|
||||
|
||||
auto previous_qty = me->state().filled_quantity();
|
||||
if (previous_qty > q.value()) {
|
||||
// q is the total fills, and p is the last filled price
|
||||
Quantity previous_qty =
|
||||
get_quantity(me->state(), StateQuantityType::FilledQuantity);
|
||||
if (previous_qty > q) {
|
||||
LOG(OrderMan, Error,
|
||||
"AlgoOrder {} is reporting a decrease in fill quantity "
|
||||
"from {} to {}. This should never happen. Canceling {}",
|
||||
key().value(), previous_qty, q.value(), key().value());
|
||||
key().value(), previous_qty, q, key().value());
|
||||
terminate_error("Internal algo error. Report fill size decreased");
|
||||
} else {
|
||||
auto new_avg_price = Price(0);
|
||||
if (q.value() > 0)
|
||||
if (q > 0)
|
||||
new_avg_price.value() =
|
||||
(me->state().filled_quantity() * me->state().avg_price() +
|
||||
(q.value() - previous_qty) * p.value()) /
|
||||
q.value();
|
||||
(previous_qty.full_value() * me->state().avg_price() +
|
||||
(q - previous_qty).full_value() * p.value()) /
|
||||
q.full_value();
|
||||
LOG(OrderMan, Diag,
|
||||
"AlgoWrapperOrder updated its fill state. Total fills: {} Is "
|
||||
"attaching: {}",
|
||||
q.value(), me->in_do_launch_attached);
|
||||
q, me->in_do_launch_attached);
|
||||
me->set_fill_quantities(q, p, new_avg_price, me->in_do_launch_attached);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user