spreader reports from the timer callback now

This commit is contained in:
Taha Afzal committed 2019-01-24 13:35:23 -05:00
1 parent 5e713d9008
commit 1ed85af40e
2 files changed
+33 -17

No files matched your search

@@ -17,6 +17,7 @@ namespace orderman {
SpreaderOrder::SpreaderOrder()
:
_cancelled (false),
_report_dirty(false),
_active(true),
_cancel_hedges_on_cancel(false),
_cw_helper(),
@@ -66,7 +67,11 @@ void SpreaderOrder::on_activate(Price price, Quantity quantity,
if (!_active) return;
SpreaderOrderServices spreader_order_services (&services);
_on_activate(price, quantity, spreader_order_services);
_report_state();
// the reason why this is immediatly reported (vs in the timer
// event) is that if this spreader was constructed through
// on_init_recovered, it wont subsribe to the timer event
// and hence the report wont go out
_comp_and_report_state();
}
void SpreaderOrder::on_update(Price price, Quantity quantity,trace::CorID const&){
if (!_active) return;
@@ -112,6 +117,10 @@ void SpreaderOrder::_on_time(const bts::mercury::TimerEvent& t_event){
if (_any_quoter_in_irrecoverable_error())
_state_worker->on_quoter_irrecoverable_error();
_keep_hedging_path_hot();
if(_report_dirty){
_report_dirty=false;
_comp_and_report_state();
}
}
void SpreaderOrder::_on_book_update(const BookUpdateEvent& book_event){
if (!_active) return;
@@ -394,7 +403,10 @@ void SpreaderOrder::_compute_hedge_price_quantity(size_t filled_leg_index,
Price(computed_hedge_price),
Quantity(hedge_quantity));
}
void SpreaderOrder::_report_state (bool report){
void SpreaderOrder::_report_state (bool report){
_report_dirty=_report_dirty||report;
}
void SpreaderOrder::_comp_and_report_state (){
if (_activated()){
SpreaderBookkeepingData& bookkeeping_data = _bookkeeping_data();
auto& reported_state = bookkeeping_data.reported_state();
@@ -413,17 +425,15 @@ void SpreaderOrder::_report_state (bool report){
reported_state.set_filled_quantity(filled_qty.value());
reported_state.set_avg_price(avg_filled_price.value());
}
if(report){
// if order is cons'ed from disc, with inited_new==false,
// we just publish what was given to us
LOG(OrderMan, Info, "SpreaderOrder::_report_state key:{} status:{} "
"price:{} qty:{} filled:{} avg_price:{}",
key(), status, reported_state.price(),
reported_state.quantity(),
reported_state.filled_quantity(),
reported_state.avg_price());
_order_services->report_state(reported_state);
}
// if order is cons'ed from disc, with inited_new==false,
// we just publish what was given to us
LOG(OrderMan, Info, "SpreaderOrder::_report_state key:{} status:{} "
"price:{} qty:{} filled:{} avg_price:{}",
key(), status, reported_state.price(),
reported_state.quantity(),
reported_state.filled_quantity(),
reported_state.avg_price());
_order_services->report_state(reported_state);
}
}
bts::api::orderman::OrderStatus SpreaderOrder::_get_order_status () const{
@@ -56,6 +56,8 @@ private:
//std::array<uint8_t,16> _non_filled_indices;
// if the order is _cancelled, this is set to true
bool _cancelled;
// is set to true when a report needs to be sent
bool _report_dirty;
// is false if created from disk
const bool _active;
// this is the main data
@@ -200,11 +202,11 @@ private:
// this means on_init_new or on_init_recovered
// has been called and we have the bookkeeping
// data built
bool _inited () const {
bool _inited() const {
return _bookkeeping_data_ptr != nullptr;
}
// this means on_activate has been called
bool _activated () {
bool _activated() {
return _order_services != nullptr;
}
void _on_init_new(const bts::api::orderman::OrderDefinition&,
@@ -240,8 +242,12 @@ private:
size_t hedged_leg_index,
Price& hedge_price,
double& hedge_quantity);
// sends the report out
void _report_state (bool report=true);
// this sets the report dirty bit, which
// is checked in the timer event and if dirty
// _comp_and_report_state is called
void _report_state (bool report=true);
// this acually sends the report out
void _comp_and_report_state();
SpreaderBookkeepingData& _bookkeeping_data(){
bts_assert (_bookkeeping_data_ptr != nullptr);
return *_bookkeeping_data_ptr;