cleanup
This commit is contained in:
1 parent
4093654258
commit
868c4e0e6d
6 files changed
+43
-42
No files matched your search
@@ -195,7 +195,7 @@ void SpreaderOrder::_transform_to_END(std::string* m)
|
||||
}
|
||||
void SpreaderOrder::_cancel_orders(bool cancel_quotes, bool cancel_hedges)
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
if (cancel_quotes)
|
||||
@@ -213,7 +213,7 @@ void SpreaderOrder::_cancel_orders(bool cancel_quotes, bool cancel_hedges)
|
||||
}
|
||||
bool SpreaderOrder::_all_quoter_orders_in_terminal_state()
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
if (leg_data.leg_property_data().is_active_quoting())
|
||||
@@ -225,7 +225,7 @@ bool SpreaderOrder::_all_quoter_orders_in_terminal_state()
|
||||
// same as _all_quoter_orders_in_terminal_state, for hedgers
|
||||
bool SpreaderOrder::_all_hedger_orders_in_terminal_state()
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
for (size_t h_idx = 0; h_idx < leg_data.n_hedgers(); h_idx++)
|
||||
@@ -239,7 +239,7 @@ bool SpreaderOrder::_all_hedger_orders_in_terminal_state()
|
||||
}
|
||||
void SpreaderOrder::_terminate_quoters ()
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
leg_data.quoter()->terminate();
|
||||
@@ -247,7 +247,7 @@ void SpreaderOrder::_terminate_quoters ()
|
||||
}
|
||||
void SpreaderOrder::_terminate_hedgers ()
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
for (size_t h_idx = 0; h_idx < leg_data.n_hedgers(); h_idx++)
|
||||
@@ -259,7 +259,7 @@ void SpreaderOrder::_terminate_hedgers ()
|
||||
}
|
||||
bool SpreaderOrder::_quoters_can_accept_modification ()
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _bookkeeping_data.get_leg_data(q_idx);
|
||||
if (leg_data.leg_property_data().is_active_quoting())
|
||||
@@ -288,7 +288,7 @@ void SpreaderOrder::_compute_hedge_price_quantity(size_t filled_leg_index,
|
||||
|
||||
SpreaderLegData& filled_leg_data = _bookkeeping_data.get_leg_data(filled_leg_index);
|
||||
SpreaderLegData& hedged_leg_data = _bookkeeping_data.get_leg_data(hedge_leg_index);
|
||||
if (_bookkeeping_data.count() == 2)
|
||||
if (_bookkeeping_data.n_legs() == 2)
|
||||
{
|
||||
SpreaderUtils::compute_hedge_price_size_2_legs (_bookkeeping_data.price(),
|
||||
filled_leg_data.leg_property_data(), fill_price, fill_quantity,
|
||||
|
||||
@@ -25,6 +25,25 @@ class NativeOrderFactory;
|
||||
|
||||
class SpreaderOrder : public SpreaderOrderBase, public ISpreaderManager
|
||||
{
|
||||
private:
|
||||
const int64_t _cancel_timeout;
|
||||
const bool _active;
|
||||
const bool _real_orders;
|
||||
std::string _msg; // this is the message that is reported (populated by the state workers)
|
||||
const api::orderman::CreateOrderRequest _create_order_request;
|
||||
SpreaderBookkeepingData _bookkeeping_data; // this is the main state
|
||||
bts::TimeStamp _curr_timestamp;
|
||||
ISpreaderStateWorker* _state_worker;
|
||||
friend class SpreaderStartStateWorker;
|
||||
friend class SpreaderWaitingForFirstConnStateWorker;
|
||||
friend class SpreaderWorkingStateWorker;
|
||||
friend class SpreaderWaitingForCancelAllStateWorker;
|
||||
friend class SpreaderEndStateWorker;
|
||||
SpreaderStartStateWorker _start_state_worker;
|
||||
SpreaderWaitingForFirstConnStateWorker _waiting_for_first_conn_state_worker;
|
||||
SpreaderWorkingStateWorker _working_state_worker;
|
||||
SpreaderWaitingForCancelAllStateWorker _waiting_for_cancel_all_state_worker;
|
||||
SpreaderEndStateWorker _end_state_worker;
|
||||
public:
|
||||
// old order recovered from disk
|
||||
SpreaderOrder(securities::ISecurityDB&,
|
||||
@@ -65,16 +84,16 @@ public:
|
||||
// called when an external error occurs (which could be a risk limit
|
||||
// breach or a system issue)
|
||||
void on_external_error(std::string const&);
|
||||
/************************ISpreaderManager*******************************/
|
||||
public:
|
||||
// ISpreaderManager members
|
||||
const orderman::Book& get_book(size_t leg_index) const override;
|
||||
const LegPropertyData& get_leg_data(size_t leg_index) const override;
|
||||
bts::orderman::SpreaderOrderBase::ChildOrder setup_new_quoter_order (const LegPropertyData& leg_property_data) override;
|
||||
void place_order (SpreaderOrderBase::ChildOrder& child_order, TickToTradeCorID cid, Price price, Quantity quantity) override;
|
||||
void modify_order (SpreaderOrderBase::ChildOrder& child_order, TickToTradeCorID cid, Price price, Quantity quantity) override;
|
||||
void cancel_order (SpreaderOrderBase::ChildOrder& child_order) override;
|
||||
/**************************Testing only***********************************/
|
||||
public:
|
||||
// this is exposed for testing reasons only
|
||||
SpreaderState test_only_func_spreader_state ();
|
||||
SpreaderLegData& test_only_func_spreader_leg_data (size_t index);
|
||||
SpreaderBookkeepingData& test_only_func_spreader_full_data ();
|
||||
@@ -85,15 +104,14 @@ private:
|
||||
void _transform_to_WORKING();
|
||||
void _transform_to_WAITING_FOR_CANCEL_ALL();
|
||||
void _transform_to_END(std::string* m = nullptr);
|
||||
// this cancels the quoters and hedger orders (through them)
|
||||
// can cancel the quotes or the hedges or both
|
||||
// this calls the cancel on quoter and hedger orders
|
||||
void _cancel_orders(bool cancel_quotes, bool cancel_hedges);
|
||||
// iterates through all quoters and returns true if they
|
||||
// are all in terminal state
|
||||
bool _all_quoter_orders_in_terminal_state();
|
||||
// same as _all_quoter_orders_in_terminal_state, for hedgers
|
||||
bool _all_hedger_orders_in_terminal_state();
|
||||
// sends all the quoters immedatly to the their terminal state
|
||||
// sends all the quoters immediatly to the their terminal state
|
||||
// abandoning everything they were doing
|
||||
void _terminate_quoters ();
|
||||
// same as the above for hedgers
|
||||
@@ -112,28 +130,11 @@ private:
|
||||
Price filled_price, Quantity filled_quantity,
|
||||
size_t hedged_leg_index,
|
||||
Price& hedge_price, Quantity& hedge_quantity);
|
||||
// sends the report out
|
||||
void _report_state (api::orderman::OrderStatus order_status, std::string* message = nullptr);
|
||||
// swtches to the state passed in the arg
|
||||
void _switch_state (ISpreaderStateWorker* new_state);
|
||||
// creates a new order and returns it
|
||||
bts::orderman::SpreaderOrderBase::ChildOrder _get_new_order (const LegPropertyData& leg_property_data, bool is_quote_order);
|
||||
private:
|
||||
const int64_t _cancel_timeout;
|
||||
const bool _active;
|
||||
const bool _real_orders;
|
||||
std::string _msg;
|
||||
const api::orderman::CreateOrderRequest _create_order_request;
|
||||
// these 2 constitute the state
|
||||
SpreaderBookkeepingData _bookkeeping_data;
|
||||
bts::TimeStamp _curr_timestamp;
|
||||
ISpreaderStateWorker* _state_worker;
|
||||
friend class SpreaderStartStateWorker;
|
||||
friend class SpreaderWaitingForFirstConnStateWorker;
|
||||
friend class SpreaderWorkingStateWorker;
|
||||
friend class SpreaderWaitingForCancelAllStateWorker;
|
||||
friend class SpreaderEndStateWorker;
|
||||
SpreaderStartStateWorker _start_state_worker;
|
||||
SpreaderWaitingForFirstConnStateWorker _waiting_for_first_conn_state_worker;
|
||||
SpreaderWorkingStateWorker _working_state_worker;
|
||||
SpreaderWaitingForCancelAllStateWorker _waiting_for_cancel_all_state_worker;
|
||||
SpreaderEndStateWorker _end_state_worker;
|
||||
};
|
||||
}}
|
||||
+2
-2
@@ -87,7 +87,7 @@ void SpreaderWaitingForFirstConnStateWorker::on_check_termination()
|
||||
{}
|
||||
void SpreaderWaitingForFirstConnStateWorker::_init_quoters ()
|
||||
{
|
||||
for (size_t index = 0; index < _spreader->_bookkeeping_data.count(); index++)
|
||||
for (size_t index = 0; index < _spreader->_bookkeeping_data.n_legs(); index++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _spreader->_bookkeeping_data.get_leg_data(index);
|
||||
if (leg_data.leg_property_data().is_active_quoting())
|
||||
@@ -123,7 +123,7 @@ bool SpreaderWaitingForFirstConnStateWorker::_can_resolve_securities ()
|
||||
}
|
||||
void SpreaderWaitingForFirstConnStateWorker::_subscribe_to_marketdata()
|
||||
{
|
||||
for (size_t index = 0; index < _spreader->_bookkeeping_data.count(); index++)
|
||||
for (size_t index = 0; index < _spreader->_bookkeeping_data.n_legs(); index++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _spreader->_bookkeeping_data.get_leg_data(index);
|
||||
bts::SecurityKey leg_key = bts::SecurityKey (leg_data.leg_property_data().security_key());
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ void SpreaderWorkingStateWorker::on_update(const api::orderman::UpdateSpreaderOr
|
||||
Price price (u.price()); Quantity quantity(u.quantity());
|
||||
_spreader->_bookkeeping_data.update_order (price, quantity);
|
||||
// updating all active quoters, nothing to do with the hedgers
|
||||
for (size_t q_idx = 0; q_idx < _spreader->_bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _spreader->_bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = _spreader->_bookkeeping_data.get_leg_data(q_idx);
|
||||
if (leg_data.leg_property_data().is_active_quoting())
|
||||
@@ -54,7 +54,7 @@ void SpreaderWorkingStateWorker::on_book(TickToTradeCorID cid, const Book& book)
|
||||
// updating md state (this is the only place where its done)
|
||||
md_leg.set_book(book);
|
||||
// sending md to all quoters
|
||||
for (size_t q_idx = 0; q_idx < bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& d = bookkeeping_data.get_leg_data(q_idx);
|
||||
if (d.leg_property_data().is_active_quoting())
|
||||
@@ -67,7 +67,7 @@ void SpreaderWorkingStateWorker::on_book(TickToTradeCorID cid, const Book& book)
|
||||
void SpreaderWorkingStateWorker::on_time(const TimeStamp& ts)
|
||||
{
|
||||
SpreaderBookkeepingData& bookkeeping_data = _spreader->_bookkeeping_data;
|
||||
for (size_t q_idx = 0; q_idx < bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
SpreaderLegData& leg_data = bookkeeping_data.get_leg_data(q_idx);
|
||||
if (leg_data.leg_property_data().is_active_quoting())
|
||||
@@ -99,7 +99,7 @@ void SpreaderWorkingStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLeg
|
||||
leg_data.quoter()->update_order_status (order_update_message);
|
||||
if (order_update_message.last_update_filled_quantity().value() > 0)
|
||||
{
|
||||
for (size_t q_idx = 0; q_idx < _spreader->_bookkeeping_data.count(); q_idx++)
|
||||
for (size_t q_idx = 0; q_idx < _spreader->_bookkeeping_data.n_legs(); q_idx++)
|
||||
{
|
||||
bts::orderman::SpreaderLegData other_leg_data = _spreader->_bookkeeping_data.get_leg_data (q_idx);
|
||||
if (q_idx != leg_data.leg_property_data().leg_index())
|
||||
|
||||
@@ -2013,7 +2013,7 @@ TEST_CASE ("spreader_WAITING_FOR_CANCEL_ACK", "[spreader]")
|
||||
spreader.on_disconnect ();
|
||||
verify_basic_spreader_state (spreader, SpreaderState::END, spreader_price, spreader_quantity);
|
||||
// all quoters should go to end state
|
||||
for (size_t i = 0; i < bookkeeping_data.count(); i++)
|
||||
for (size_t i = 0; i < bookkeeping_data.n_legs(); i++)
|
||||
{
|
||||
SpreaderLegData& leg_data = bookkeeping_data.get_leg_data (i);
|
||||
bts_assert (leg_data.quoter()->test_only_func_quoter_state() == QuoterState::END);
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
bts_assert(index < _leg_data.size());
|
||||
return _leg_data[index];
|
||||
}
|
||||
size_t count() { return _leg_data.size(); }
|
||||
size_t n_legs() const { return _leg_data.size(); }
|
||||
SpreaderLegData* find_leg_from_quoter_orderkey(orderman::OrderKey order_key)
|
||||
{
|
||||
for (auto q_it = _leg_data.begin(); q_it != _leg_data.end(); q_it++)
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Price price () {return _price;}
|
||||
Quantity quantity () {return _quantity;}
|
||||
Price price () const {return _price;}
|
||||
Quantity quantity () const {return _quantity;}
|
||||
void update_order (Price price, Quantity quantity)
|
||||
{
|
||||
_price = price;
|
||||
|
||||
Reference in new issue
Block a user