Enhanced the API to allow algos to implement custom cancel handling
This commit is contained in:
1 parent
3dda3e7f75
commit
ed23bc7e2b
2 files changed
+22
-4
No files matched your search
@@ -135,9 +135,9 @@ void AlgoWrapperOrder::on_init_new(OrderDefinition const &def,
|
||||
if (can_consume_attachment(me->definition.custom_def().custom_case())) {
|
||||
me->attach_target = OrderKey(me->definition.attach_target_order_key());
|
||||
me->definition.clear_attach_target_order_key();
|
||||
}
|
||||
else {
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK, "Algo does not support attachment");
|
||||
} else {
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
"Algo does not support attachment");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -290,9 +290,19 @@ orderman::OrderOpResult AlgoWrapperOrder::on_cancel() {
|
||||
|
||||
switch (me->status) {
|
||||
case Status::W_ATTACH:
|
||||
case Status::WORKING:
|
||||
terminate(ORDER_STATUS_CANCELED);
|
||||
break;
|
||||
case Status::WORKING:
|
||||
switch (me->algo->on_cancel()) {
|
||||
case IAlgoOrder::OnCancelResponse::HONOR:
|
||||
cancel();
|
||||
break;
|
||||
case IAlgoOrder::OnCancelResponse::IGNORE:
|
||||
LOG(OrderMan,Info,"Algo order with key {} ignored cancel request",
|
||||
key().value());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Status::COMPLETED:
|
||||
break;
|
||||
case Status::INACTIVE:
|
||||
|
||||
@@ -64,6 +64,14 @@ class IAlgoOrder {
|
||||
// implementation should validate the update and either apply it,
|
||||
// if valid or terminate with an error otherwise
|
||||
virtual void do_update(api::orderman::Update const &) {}
|
||||
|
||||
// Override this method to provide custom handling of a cancel
|
||||
// request. The default behaviour is to cancel both this order and
|
||||
// recursively any of its children. Algos may override this method
|
||||
// for example to detach from specific children before canceling or
|
||||
// to implement custom cleanup behaviour when canceled.
|
||||
enum class OnCancelResponse {IGNORE, HONOR};
|
||||
virtual OnCancelResponse on_cancel() {return OnCancelResponse::HONOR;}
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
Reference in new issue
Block a user