SPARK-331 Adding on_transition to Quoter
This commit is contained in:
1 parent
4af07c358b
commit
f51bbf0c3d
17 files changed
+53
-78
No files matched your search
@@ -21,7 +21,14 @@ SingleLegQuoter::SingleLegQuoter(ISpreaderManager& spreader,
|
||||
_child_order_state (child_order_state),
|
||||
_price_quantity_state(QuoteLegPriceQuantityState(Price(0), Quantity(0))),
|
||||
_is_permenantly_cancelled (false),
|
||||
_worker(nullptr)
|
||||
_worker(nullptr),
|
||||
_start_state_worker(this),
|
||||
_waiting_for_size_state_worker(this),
|
||||
_waiting_for_first_ack_state_worker(this),
|
||||
_waiting_for_first_ack_cancelled_state_worker(this),
|
||||
_waiting_for_cancel_ack_state_worker(this),
|
||||
_working_state_worker(this),
|
||||
_end_state_worker(this)
|
||||
{
|
||||
if (!_two_legged)
|
||||
{
|
||||
@@ -44,7 +51,14 @@ SingleLegQuoter::SingleLegQuoter(SingleLegQuoter&& other)
|
||||
_drivers_commited (other._drivers_commited),
|
||||
_price_quantity_state(other._price_quantity_state),
|
||||
_is_permenantly_cancelled (other._is_permenantly_cancelled),
|
||||
_worker(nullptr)
|
||||
_worker(nullptr),
|
||||
_start_state_worker(this),
|
||||
_waiting_for_size_state_worker(this),
|
||||
_waiting_for_first_ack_state_worker(this),
|
||||
_waiting_for_first_ack_cancelled_state_worker(this),
|
||||
_waiting_for_cancel_ack_state_worker(this),
|
||||
_working_state_worker(this),
|
||||
_end_state_worker(this)
|
||||
{
|
||||
// the move (or copy) cons is neededbecause the
|
||||
// quoter is stored in a vector. however we
|
||||
@@ -59,13 +73,13 @@ SingleLegQuoter::SingleLegQuoter(SingleLegQuoter&& other)
|
||||
void SingleLegQuoter::one_time_activate(Price price, Quantity quantity)
|
||||
{
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::update_order_status key: {} state: {} price: {} quantity: {}",
|
||||
_child_order_state.order_key().value(), _worker->state_text(), price.value(), quantity.value());
|
||||
_child_order_state.order_key().value(), (int)_worker->state(), price.value(), quantity.value());
|
||||
_worker->one_time_activate (price, quantity);
|
||||
}
|
||||
void SingleLegQuoter::update_order_status(const SpreaderChildOrderState& u)
|
||||
{
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::update_order_status key: {} state: {} order status: {} fills: {}",
|
||||
_child_order_state.order_key().value(), _worker->state_text(), static_cast<int>(u.status()), u.last_update_filled_quantity().value());
|
||||
_child_order_state.order_key().value(), (int)_worker->state(), static_cast<int>(u.status()), u.last_update_filled_quantity().value());
|
||||
_worker->on_order_update (u);
|
||||
}
|
||||
void SingleLegQuoter::on_book(bts::orderman2::TickToTradeCorID cid, size_t leg_index, const bts::orderman2::Book& book)
|
||||
@@ -75,26 +89,26 @@ void SingleLegQuoter::on_book(bts::orderman2::TickToTradeCorID cid, size_t leg_i
|
||||
void SingleLegQuoter::update_other_leg_fills(size_t leg_index, Quantity filled_quantity)
|
||||
{
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::update_other_leg_fills key: {} state: {} leg_index: {} filled_quantity: {}",
|
||||
_child_order_state.order_key().value(), _worker->state_text(), leg_index, filled_quantity.value());
|
||||
_child_order_state.order_key().value(), (int)_worker->state(), leg_index, filled_quantity.value());
|
||||
_worker->on_other_leg_quoter_fill (leg_index, filled_quantity);
|
||||
}
|
||||
void SingleLegQuoter::update_order_price_quantity(Price price, Quantity quantity)
|
||||
{
|
||||
Quantity this_leg_quantity = Quantity (SpreaderUtils::get_leg_quantity_from_spreader_quantity (_this_leg_data, quantity));
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::update_order_price_quantity key: {} state: {} price: {} spread quantity: {} leg quantity: {}",
|
||||
_child_order_state.order_key().value(), _worker->state_text(), price.value(), quantity.value(), this_leg_quantity.value());
|
||||
_child_order_state.order_key().value(), (int)_worker->state(), price.value(), quantity.value(), this_leg_quantity.value());
|
||||
_worker->update_spreader_order (price, this_leg_quantity);
|
||||
}
|
||||
void SingleLegQuoter::cancel_order()
|
||||
{
|
||||
_is_permenantly_cancelled = true;
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::cancel_order key: {}, state: {}", _child_order_state.order_key().value(), _worker->state_text());
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::cancel_order key: {}, state: {}", _child_order_state.order_key().value(), (int)_worker->state());
|
||||
_worker->cancel ();
|
||||
}
|
||||
void SingleLegQuoter::terminate ()
|
||||
{
|
||||
_is_permenantly_cancelled = true;
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::terminate key: {}, state: {}", _child_order_state.order_key().value(), _worker->state_text());
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::terminate key: {}, state: {}", _child_order_state.order_key().value(), (int)_worker->state());
|
||||
_worker->terminate ();
|
||||
}
|
||||
void SingleLegQuoter::on_time (const bts::TimeStamp& ts)
|
||||
@@ -184,8 +198,9 @@ void SingleLegQuoter::_transform_to_END()
|
||||
}
|
||||
void SingleLegQuoter::_switch_state (IQuoterStateWorker* new_state)
|
||||
{
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::_switch_state key: {}, {} -> {} ", _child_order_state.order_key().value(), (_worker == nullptr ? "NULL" : _worker->state_text()), new_state->state_text());
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::_switch_state key: {}, {} -> {} ",
|
||||
_child_order_state.order_key().value(), (_worker == nullptr ? -1 : (int)_worker->state()), (int)_worker->state());
|
||||
_worker = new_state;
|
||||
_worker->build_once (this);
|
||||
_worker->on_transition();
|
||||
}
|
||||
}}
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
QuoterWaitingForFirstAckCancelledWorker _waiting_for_first_ack_cancelled_state_worker;
|
||||
QuoterWaitingForCancelAckStateWorker _waiting_for_cancel_ack_state_worker;
|
||||
QuoterWorkingStateWorker _working_state_worker;
|
||||
QuoterEndStateWorker _end_state_worker;
|
||||
QuoterEndStateWorker _end_state_worker;
|
||||
public:
|
||||
SingleLegQuoter(ISpreaderManager& spreader,
|
||||
LegPropertyData this_leg_property,
|
||||
|
||||
@@ -16,9 +16,8 @@ class IQuoterStateWorker
|
||||
public:
|
||||
// state of this worker
|
||||
virtual QuoterState state () const = 0;
|
||||
virtual const std::string& state_text () const = 0;
|
||||
// called once at the start before everything else
|
||||
virtual void build_once (SingleLegQuoter* quoter) = 0;
|
||||
virtual void on_transition () = 0;
|
||||
// called only once before all the other calls
|
||||
virtual void one_time_activate (Price, Quantity) = 0;
|
||||
// called only when this quoter's order is updated
|
||||
|
||||
@@ -8,16 +8,16 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterEndStateWorker::state () const {return QuoterState::END;}
|
||||
void QuoterEndStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
void QuoterEndStateWorker::on_transition ()
|
||||
{
|
||||
bool is_final = quoter->_is_permenantly_cancelled || quoter->_price_quantity_state.target_reached ();
|
||||
bool is_final = _quoter->_is_permenantly_cancelled || _quoter->_price_quantity_state.target_reached ();
|
||||
if (!is_final)
|
||||
{
|
||||
// zeroing out any working state
|
||||
quoter->_price_quantity_state.cycle_back ();
|
||||
quoter->_spreader.setup_new_quoter_order(quoter->_this_leg_data.leg_index());
|
||||
_quoter->_price_quantity_state.cycle_back ();
|
||||
_quoter->_spreader.setup_new_quoter_order(_quoter->_this_leg_data.leg_index());
|
||||
// get the new order
|
||||
quoter->_transform_to_WAITING_FOR_SIZE ();
|
||||
_quoter->_transform_to_WAITING_FOR_SIZE ();
|
||||
}
|
||||
}
|
||||
void QuoterEndStateWorker::one_time_activate (Price, Quantity)
|
||||
|
||||
@@ -15,13 +15,11 @@ class SingleLegQuoter;
|
||||
class QuoterEndStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
const std::string _state_text;
|
||||
public:
|
||||
QuoterEndStateWorker () : _state_text ("END") {}
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterEndStateWorker (SingleLegQuoter* quoter) : _quoter(quoter){}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override;
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
@@ -7,10 +7,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterStartStateWorker::state () const {return QuoterState::START;}
|
||||
void QuoterStartStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterStartStateWorker::one_time_activate (Price price, Quantity quantity)
|
||||
{
|
||||
_on_price_quantity_set(price, quantity);
|
||||
|
||||
@@ -15,13 +15,11 @@ class SingleLegQuoter;
|
||||
class QuoterStartStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterStartStateWorker () : _state_text ("START") {}
|
||||
QuoterStartStateWorker (SingleLegQuoter* quoter) : _quoter(quoter) {}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
-4
@@ -8,10 +8,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForCancelAckStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK;}
|
||||
void QuoterWaitingForCancelAckStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::one_time_activate (Price, Quantity)
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForCancelAckStateWorker::one_time_activate is an illegal operation");
|
||||
|
||||
+3
-6
@@ -15,14 +15,11 @@ class SingleLegQuoter;
|
||||
class QuoterWaitingForCancelAckStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterWaitingForCancelAckStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK") {}
|
||||
public:
|
||||
QuoterWaitingForCancelAckStateWorker (SingleLegQuoter* quoter) :_quoter(quoter){}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
-4
@@ -9,10 +9,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForFirstAckCancelledWorker::state () const {return QuoterState::WAITING_FOR_FIRST_ACK_CANCELLED;}
|
||||
void QuoterWaitingForFirstAckCancelledWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForFirstAckCancelledWorker::one_time_activate (Price, Quantity)
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForFirstAckCancelledWorker::one_time_activate is an illegal operation");
|
||||
|
||||
+3
-5
@@ -17,13 +17,11 @@ class SingleLegQuoter;
|
||||
class QuoterWaitingForFirstAckCancelledWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterWaitingForFirstAckCancelledWorker () : _state_text ("WAITING_FOR_FIRST_ACK_CANCELLED") {}
|
||||
QuoterWaitingForFirstAckCancelledWorker (SingleLegQuoter* quoter) :_quoter(quoter) {}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
@@ -8,10 +8,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForFirstAckWorker::state () const {return QuoterState::WAITING_FOR_FIRST_ACK;}
|
||||
void QuoterWaitingForFirstAckWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForFirstAckWorker::one_time_activate (Price, Quantity)
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForFirstAckWorker::one_time_activate is an illegal operation");
|
||||
|
||||
@@ -16,13 +16,11 @@ class SingleLegQuoter;
|
||||
class QuoterWaitingForFirstAckWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterWaitingForFirstAckWorker () : _state_text ("WAITING_FOR_FIRST_ACK") {}
|
||||
QuoterWaitingForFirstAckWorker (SingleLegQuoter* quoter) :_quoter(quoter){}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
@@ -8,10 +8,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForSizeStateWorker::state () const {return QuoterState::WAITING_FOR_SIZE;}
|
||||
void QuoterWaitingForSizeStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForSizeStateWorker::one_time_activate (Price, Quantity)
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForSizeStateWorker::one_time_activate is an illegal operation");
|
||||
|
||||
@@ -16,13 +16,11 @@ class SingleLegQuoter;
|
||||
class QuoterWaitingForSizeStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterWaitingForSizeStateWorker () : _state_text ("WAITING_FOR_SIZE") {}
|
||||
QuoterWaitingForSizeStateWorker (SingleLegQuoter* quoter) :_quoter(quoter){}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
@@ -8,10 +8,6 @@ namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWorkingStateWorker::state () const {return QuoterState::WORKING;}
|
||||
void QuoterWorkingStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWorkingStateWorker::one_time_activate (Price, Quantity)
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWorkingStateWorker::one_time_activate is an illegal operation");
|
||||
|
||||
@@ -15,13 +15,11 @@ class SingleLegQuoter;
|
||||
class QuoterWorkingStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
SingleLegQuoter* const _quoter;
|
||||
public:
|
||||
QuoterWorkingStateWorker () : _state_text ("WORKING") {}
|
||||
QuoterWorkingStateWorker (SingleLegQuoter* quoter) :_quoter(quoter) {}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
virtual void on_transition () override {}
|
||||
void one_time_activate (Price, Quantity) override;
|
||||
void on_order_update (const SpreaderChildOrderState& order_update) override;
|
||||
void on_book (bts::orderman2::TickToTradeCorID corid, size_t leg_id, const bts::orderman2::Book& book) override;
|
||||
|
||||
Reference in new issue
Block a user