buffer cancel and updates because ice sucks

This commit is contained in:
Kevin Darby committed 2019-10-10 17:43:28 -04:00
1 parent 6b30c42c0d
commit 2677144bfa
2 files changed
+45 -35

No files matched your search

+44 -35
View File
@@ -626,6 +626,11 @@ OrderOpResult ICENativeOrder::on_update(api::orderman::Update const &update)
if (me->state.last_msg().size())
me->state.set_last_msg("");
LOG(OrderMan, Warn,
"ICE may not honor this update if we recently issued an unacknowledged cancelreplace {}. Update: {}@{}. Buffering",
key().value(), q.value(), p.value());
me->buffered_update.emplace(p, q);
// early return so we skip report_state (for speed)
return OrderOpResult{};
}
@@ -730,6 +735,11 @@ OrderOpResult ICENativeOrder::on_cancel()
me->cancel_clordid_bm = encoding.overwrite( me->cancel_clordid_bm, cancel_clorid, count_digits(cancel_clorid) );
me->services->queue_fix(*me->session_services, jetfix::MessageTypes::Cancel,me->cancel_encoding);
me->buffered_cancel = true;
LOG(OrderMan, Warn,
"ICE May not honor this cancel if we'd previously issued an unacknowledged cancelreplace "
"Buffering cancel to be safe",
key().value());
break;
}
@@ -865,6 +875,8 @@ void ICENativeOrder::on_exe_report(const NewExecutionReportEvent &er)
// terminal states, nothing can change them
case ORDER_STATUS_COMPLETED:
case ORDER_STATUS_CANCELED:
me->buffered_cancel = false;
me->buffered_update.reset();
break;
// receiving an execution report does does not mean
@@ -881,30 +893,20 @@ void ICENativeOrder::on_exe_report(const NewExecutionReportEvent &er)
transition(external_status);
if (external_status == ORDER_STATUS_WORKING)
{
if (me->buffered_cancel)
{
LOG(OrderMan, Warn,
"Applying buffered cancel to order {}, on first ack",
key().value());
on_cancel();
}
else if (me->buffered_update.has_value())
{
auto [p, q] = me->buffered_update.value();
me->buffered_update.reset();
LOG(OrderMan, Warn,
"Applying buffered update ({}@{}) to order {}, on "
"first ack",
q.value(),p.value(),
key().value());
on_update(p, q);
}
handle_buffered_state("first ack");
}
}
break;
case ORDER_STATUS_WORKING:
{
transition(external_status);
auto [p, q] = me->buffered_update.value();
if(er.data->price.value() == p.value() && er.data->quantity.value() == q.value())
me->buffered_update.reset();
handle_buffered_state("working");
}
break;
case ORDER_STATUS_INACTIVE:
@@ -927,6 +929,28 @@ void ICENativeOrder::on_exe_report(const NewExecutionReportEvent &er)
}
}
void ICENativeOrder::handle_buffered_state(const std::string& condition)
{
if (me->buffered_cancel)
{
LOG(OrderMan, Warn,
"Applying buffered cancel to order {}, on ",
condition,
key().value());
on_cancel();
}
else if (me->buffered_update.has_value())
{
auto [p, q] = me->buffered_update.value();
//me->buffered_update.reset();
LOG(OrderMan, Warn,
"Applying buffered update ({}@{}) to order {}, on ",
condition,
q.value(),p.value(), key().value());
on_update(p, q);
}
}
void ICENativeOrder::on_cancel_reject(const orderman::CancelRejectEvent &cr)
{
auto &state = me->state;
@@ -963,6 +987,7 @@ void ICENativeOrder::on_gateway_status(const GatewayStatusChangeEvent &ev)
case ORDER_STATUS_CANCELED:
case ORDER_STATUS_ERROR:
case ORDER_STATUS_PENDING_WORKING:
break;
case ORDER_STATUS_WORKING:
break;
case ORDER_STATUS_DISCONNECTED:
@@ -971,23 +996,7 @@ void ICENativeOrder::on_gateway_status(const GatewayStatusChangeEvent &ev)
transition(map_external_status(native_state.native_status()));
if (me->state.status() == ORDER_STATUS_WORKING)
{
if (me->buffered_cancel)
{
LOG(OrderMan, Warn,
"Applying buffered cancel to order {}, on re-connection",
key().value());
on_cancel();
}
else if (me->buffered_update.has_value())
{
auto [p, q] = me->buffered_update.value();
me->buffered_update.reset();
LOG(OrderMan, Warn,
"Applying buffered update ({}@{}) to order {}, on "
"re-connection",
q.value(),p.value(), key().value());
on_update(p, q);
}
handle_buffered_state("re-connection");
}
break;
}
+1
View File
@@ -38,6 +38,7 @@ class ICENativeOrder : public NativeOrderBase {
void warm_up_activate(OrderServicesData &, OrderServices &) override;
void init_recovered_common(const api::orderman::OrderRecord &,
const PreActivationOrderServices &);
void handle_buffered_state(const std::string& condition);
private: