SPARK-1212, delayed spreader order cancelling when no active achild orders
This commit is contained in:
1 parent
660f203132
commit
0a2b6ce17e
2 files changed
+22
-2
No files matched your search
@@ -15,10 +15,13 @@ SpreaderOrder::SpreaderOrder()
|
||||
:
|
||||
_cancelled (false),
|
||||
_cancel_timeout (5000),// TODO:get it from config
|
||||
_check_termination_period (250), // should also be a setting/config like above
|
||||
_active(true),
|
||||
_bookkeeping_data_ptr(),
|
||||
_order_services(nullptr),
|
||||
_reported_state(),
|
||||
_curr_timestamp(),
|
||||
_last_check_termination_timestamp(),
|
||||
_state_worker(nullptr),
|
||||
_start_state_worker(this), _working_state_worker(this), _waiting_for_cancel_all_state_worker(this), _end_state_worker(this){
|
||||
_transform_to_START();
|
||||
@@ -81,6 +84,7 @@ void SpreaderOrder::_on_time(const bts::mercury::TimerEvent& t_event){
|
||||
_curr_timestamp = t_event.ts;
|
||||
if (!_active) return;
|
||||
_state_worker->on_time (_curr_timestamp);
|
||||
_send_check_termination(false);
|
||||
}
|
||||
void SpreaderOrder::_on_book_update(const BookUpdateEvent& book_event){
|
||||
if (!_active) return;
|
||||
@@ -133,7 +137,7 @@ void SpreaderOrder::_on_child_order_update(const OrderStateUpdateEvent& ord_ev){
|
||||
LOG(OrderMan, Error, "SpreaderOrder::_on_child_order_update unknown order key: {} sec_key: {} order_key: {} status: {} filled_qty: {} last_price: {} msg: {}",
|
||||
key(), sec_key, order_key, status, filled_qty, last_price, ord_ev.state.last_msg ());
|
||||
}
|
||||
_state_worker->on_check_termination ();
|
||||
_send_check_termination(true);
|
||||
_report_state();
|
||||
}
|
||||
// State Transformations ////////////////////
|
||||
@@ -314,4 +318,11 @@ bts::api::orderman::OrderStatus SpreaderOrder::_get_order_status () const{
|
||||
return bts::api::orderman::OrderStatus::ORDER_STATUS_INACTIVE;
|
||||
}
|
||||
}
|
||||
}}
|
||||
void SpreaderOrder::_send_check_termination(bool force){
|
||||
if(force ||
|
||||
ms_diff (_curr_timestamp, _last_check_termination_timestamp) >= _check_termination_period){
|
||||
_last_check_termination_timestamp = _curr_timestamp;
|
||||
_state_worker->on_check_termination();
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -49,6 +49,9 @@ private:
|
||||
bool _cancelled;
|
||||
// timeout before cancel waiting goes to end
|
||||
const int64_t _cancel_timeout;
|
||||
// period on which check termination calls are
|
||||
// sent to the state worker
|
||||
const int64_t _check_termination_period;
|
||||
// is false if created from disk
|
||||
const bool _active;
|
||||
// this is the main data
|
||||
@@ -60,6 +63,8 @@ private:
|
||||
bts::api::orderman::OrderState _reported_state;
|
||||
// timestamp of last the on_time call
|
||||
bts::TimeStamp _curr_timestamp;
|
||||
// spreader fires a periodic check
|
||||
bts::TimeStamp _last_check_termination_timestamp;
|
||||
// current state
|
||||
ISpreaderStateWorker* _state_worker;
|
||||
SpreaderStartStateWorker _start_state_worker;
|
||||
@@ -203,6 +208,10 @@ private:
|
||||
return ChildOrderError::MODIFY_ERROR;
|
||||
return ChildOrderError::NONE;
|
||||
}
|
||||
// the state worker's on_check_termination is sent
|
||||
// when there's an order update, as well as on
|
||||
// a periodic bases
|
||||
void _send_check_termination(bool force);
|
||||
// testing only //////////////////
|
||||
// this provides direct way to inject
|
||||
// data into the spreader, as well as
|
||||
|
||||
Reference in new issue
Block a user