SPARK-285 state name change

This commit is contained in:
Taha Afzal committed 2017-11-24 09:55:24 -05:00
1 parent 9eed4d1275
commit 30db05a722
10 files changed
+28 -137

No files matched your search

@@ -1119,7 +1119,7 @@ TEST_CASE ("Quoter WAITING_FOR_FIRT_ACK_CANCELLED state", "[spreader]")
SpreaderOrderUpdateMessage u (bts::orderman::OrderKey(0));
u.update (api::orderman::OrderStatus::OS_PARTIALLY_FILLED, Quantity (70), Price (2000), nullptr);
quoter.update_order_status(u);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
LOG(OrderMan, Diag, "Quoter WAITING_FOR_FIRT_ACK_CANCELLED state update_order_status non terminal success");
}
@@ -1231,20 +1231,20 @@ TEST_CASE ("Quoter WAITING_FOR_CANCEL_ACK state", "[spreader]")
SpreaderOrderUpdateMessage u (bts::orderman::OrderKey(0));
u.update (api::orderman::OrderStatus::OS_PARTIALLY_FILLED, Quantity (70), Price (2000), nullptr);
quoter.update_order_status(u);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
SECTION("2. update_order_status non terminal")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
u.update (api::orderman::OrderStatus::OS_PARTIALLY_FILLED, Quantity (70), Price (2000), nullptr);
quoter.update_order_status(u);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
LOG(OrderMan, Diag, "Quoter WAITING_FOR_CANCEL_ACK state update_order_status non terminal success");
}
SECTION("2. update_order_status terminal")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
u.update (api::orderman::OrderStatus::OS_FILLED, Quantity (100), Price (2000), nullptr);
quoter.update_order_status(u);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::END);
@@ -1253,7 +1253,7 @@ TEST_CASE ("Quoter WAITING_FOR_CANCEL_ACK state", "[spreader]")
}
SECTION("3. on_book")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
// buying the spread => sell leg 2 => buy leg 1 => leg 1's sell market
Book leg_1_book;
// zero sizes
@@ -1263,51 +1263,51 @@ TEST_CASE ("Quoter WAITING_FOR_CANCEL_ACK state", "[spreader]")
spreader_manager.set_book (leg_1_book, 0);
quoter.on_book (bts::orderman::NullTickToTradeCorID, 0, leg_1_book);
// any
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
LOG(OrderMan, Diag, "Quoter WAITING_FOR_CANCEL_ACK on_book success");
}
SECTION("4. cancel_order")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
quoter.cancel_order();
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
LOG(OrderMan, Diag, "Quoter WAITING_FOR_CANCEL_ACK cancel_order success");
}
SECTION("5. terminate")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
quoter.terminate ();
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::END);
LOG(OrderMan, Diag, "Quoter WAITING_FOR_CANCEL_ACK terminate success");
}
SECTION("7. update_other_leg_fills")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
quoter.update_other_leg_fills (0, Quantity(10));
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(10), Price(2000.75), Quantity(100));
// another fill
quoter.update_other_leg_fills (0, Quantity(5));
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(15), Price(2000.75), Quantity(100));
// completely fill the other side
quoter.update_other_leg_fills (0, Quantity(15));
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(30), Price(2000.75), Quantity(100));
LOG(OrderMan, Diag, "Quoter WAITING_FOR_CANCEL_ACK update_other_leg_fills success");
}
SECTION("8. update_order_price_quantity")
{
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
spreader_price = Price (0.5); spreader_quantity = Quantity (200);
quoter.update_order_price_quantity (spreader_price, spreader_quantity);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
// on zero size, it should go to end state
spreader_price = Price (0.5); spreader_quantity = Quantity (0);
quoter.update_order_price_quantity (spreader_price, spreader_quantity);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL);
bts_assert (quoter.test_only_func_quoter_state () == QuoterState::WAITING_FOR_CANCEL_ACK);
_test_quoter_price_quantity (quoter.test_only_func_price_quantity_state (), spreader_price, spreader_quantity, Quantity(70), Quantity(0), Price(2000.75), Quantity(100));
LOG(OrderMan, Diag, "spreader WAITING_FOR_CANCEL_ACK update_order_price_quantity");
}
@@ -82,7 +82,7 @@ bool SingleLegQuoter::is_active_order() const
{
QuoterState state = _worker->state();
return state == QuoterState::WAITING_FOR_FIRST_ACK || state == QuoterState::WAITING_FOR_FIRST_ACK_CANCELLED ||
state == QuoterState::WORKING || state == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL || state == QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE;
state == QuoterState::WORKING || state == QuoterState::WAITING_FOR_CANCEL_ACK;
}
bool SingleLegQuoter::is_terminal_state () const {return _worker->state() == QuoterState::END;}
bool SingleLegQuoter::accept_modifications() const { return _worker->state() == QuoterState::WAITING_FOR_SIZE || _worker->state() == QuoterState::WORKING; }
@@ -151,7 +151,7 @@ void SingleLegQuoter::_transform_to_START ()
}
void SingleLegQuoter::_transform_to_WAITING_FOR_SIZE ()
{
bts_assert (_worker->state() == QuoterState::START || _worker->state() == QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE);
bts_assert (_worker->state() == QuoterState::START || _worker->state() == QuoterState::END);
_switch_state (&_waiting_for_size_state_worker);
}
void SingleLegQuoter::_transform_to_WAITING_FOR_FIRST_ACK ()
@@ -169,16 +169,11 @@ void SingleLegQuoter::_transform_to_WORKING()
bts_assert (_worker->state() == QuoterState::WAITING_FOR_FIRST_ACK);
_switch_state (&_working_state_worker);
}
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK_FINAL()
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK()
{
bts_assert (_worker->state() == QuoterState::WORKING || _worker->state() == QuoterState::WAITING_FOR_FIRST_ACK_CANCELLED);
_switch_state (&_waiting_for_cancel_ack_final_state_worker);
}
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE()
{
bts_assert (_worker->state() == QuoterState::WORKING);
_switch_state (&_waiting_for_cancel_ack_continue_state_worker);
}
void SingleLegQuoter::_transform_to_END()
{
bts_assert (_worker->state() != QuoterState::END);
+1 -5
View File
@@ -15,7 +15,6 @@
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckFinalStateWorker.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWorkingStateWorker.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckReturnStateWorker.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterEndStateWorker.h"
namespace bts {
@@ -63,7 +62,6 @@ private:
QuoterWaitingForFirstAckCancelledWorker _waiting_for_first_ack_cancelled_state_worker;
QuoterWaitingForCancelAckFinalStateWorker _waiting_for_cancel_ack_final_state_worker;
QuoterWorkingStateWorker _working_state_worker;
QuoterWaitingForCancelAckReturnStateWorker _waiting_for_cancel_ack_continue_state_worker;
QuoterEndStateWorker _end_state_worker;
public:
SingleLegQuoter(ISpreaderManager& order_bridge,
@@ -117,7 +115,6 @@ public:
friend QuoterWaitingForFirstAckCancelledWorker;
friend QuoterWaitingForCancelAckFinalStateWorker;
friend QuoterWorkingStateWorker;
friend QuoterWaitingForCancelAckReturnStateWorker;
friend QuoterEndStateWorker;
private:
void _incorporate_other_leg_fill (size_t leg_index, Quantity filled_quantity);
@@ -135,8 +132,7 @@ private:
void _transform_to_WAITING_FOR_FIRST_ACK ();
void _transform_to_WAITING_FOR_FIRST_ACK_CANCELLED();
void _transform_to_WORKING();
void _transform_to_WAITING_FOR_CANCEL_ACK_FINAL();
void _transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE();
void _transform_to_WAITING_FOR_CANCEL_ACK();
void _transform_to_END();
void _switch_state (IQuoterStateWorker* new_state);
};
@@ -9,8 +9,7 @@ enum class QuoterState
WAITING_FOR_FIRST_ACK,
WAITING_FOR_FIRST_ACK_CANCELLED,
WORKING,
WAITING_FOR_CANCEL_ACK_FINAL,
WAITING_FOR_CANCEL_ACK_CONTINUE,
WAITING_FOR_CANCEL_ACK,
END
};
}}
@@ -8,7 +8,7 @@
namespace bts{
namespace orderman{
QuoterState QuoterWaitingForCancelAckFinalStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK_FINAL;}
QuoterState QuoterWaitingForCancelAckFinalStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK;}
void QuoterWaitingForCancelAckFinalStateWorker::build_once (SingleLegQuoter* quoter)
{
_quoter = quoter;
@@ -18,7 +18,7 @@ private:
SingleLegQuoter* _quoter;
const std::string _state_text;
public:
QuoterWaitingForCancelAckFinalStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK_FINAL") {}
QuoterWaitingForCancelAckFinalStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK") {}
public:
QuoterState state () const override;
const std::string& state_text () const override {return _state_text;}
@@ -1,62 +0,0 @@
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
#include "server/sparkd/orderman/md/Book.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckReturnStateWorker.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
#include "server/sparkd/spreader/SingleLegQuoter.h"
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
namespace bts{
namespace orderman{
QuoterState QuoterWaitingForCancelAckReturnStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE;}
void QuoterWaitingForCancelAckReturnStateWorker::build_once (SingleLegQuoter* quoter)
{
_quoter = quoter;
}
void QuoterWaitingForCancelAckReturnStateWorker::init ()
{
bts_assert_msg (false, "QuoterWaitingForCancelAckReturnStateWorker::init is an illegal operation");
}
void QuoterWaitingForCancelAckReturnStateWorker::on_order_update (const SpreaderOrderUpdateMessage& u)
{
bts_assert (u.acknowledged());
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
if (u.terminal_status())
{
// order is in terminal status, this is most likely a fill,
// though in any case there is no action to take
// TODO : get new order from spreader
_quoter->_transform_to_WAITING_FOR_SIZE ();
}
else
_analyze_and_act ();
}
void QuoterWaitingForCancelAckReturnStateWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
{}
void QuoterWaitingForCancelAckReturnStateWorker::cancel()
{
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
}
void QuoterWaitingForCancelAckReturnStateWorker::terminate()
{
_quoter->_transform_to_END ();
}
void QuoterWaitingForCancelAckReturnStateWorker::on_time(const TimeStamp&)
{}
void QuoterWaitingForCancelAckReturnStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity filled_quantity)
{
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
_analyze_and_act ();
}
void QuoterWaitingForCancelAckReturnStateWorker::update_spreader_order (Price price, Quantity quantity)
{
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
_analyze_and_act ();
}
void QuoterWaitingForCancelAckReturnStateWorker::_analyze_and_act ()
{
if (_quoter->_price_quantity_state.target_reached())
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
}
}}
@@ -1,37 +0,0 @@
#pragma once
#include "server/sparkd/orderman/utils/orderman_utils.h"
#include "lib/utils/bts_chrono.h"
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
#include "server/sparkd/spreader/quoter/IQuoterStateWorker.h"
namespace bts {
namespace orderman {
class SpreaderOrderUpdateMessage;
class Book;
class SingleLegQuoter;
// if the market dissapears from a working order and the target
// has not been reached, then working->waiting_for_cancel_ack_return
// happen. here it waits for the cancels and goes back to working_for_size
class QuoterWaitingForCancelAckReturnStateWorker : public IQuoterStateWorker
{
private:
SingleLegQuoter* _quoter;
const std::string _state_text;
public:
QuoterWaitingForCancelAckReturnStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK_CONTINUE") {}
QuoterState state () const override;
const std::string& state_text () const override {return _state_text;}
void build_once (SingleLegQuoter* quoter) override;
void init () override;
void on_order_update (const SpreaderOrderUpdateMessage& order_update) override;
void on_book (bts::orderman::TickToTradeCorID corid, size_t leg_id, const bts::orderman::Book& book) override;
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void update_spreader_order (Price price, Quantity quantity) override;
private:
void _analyze_and_act ();
};
}}
@@ -28,7 +28,7 @@ void QuoterWaitingForFirstAckCancelledWorker::on_order_update (const SpreaderOrd
// got an ack, now cancel the order
// TODO: commenting out for the unit tests (no real order)
//_quoter->_order.cancel();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
}
}
void QuoterWaitingForFirstAckCancelledWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
@@ -33,7 +33,7 @@ void QuoterWorkingStateWorker::on_book (bts::orderman::TickToTradeCorID corid, s
void QuoterWorkingStateWorker::cancel()
{
_quoter->_order.cancel ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
}
void QuoterWorkingStateWorker::terminate()
{
@@ -60,7 +60,7 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToT
// ii. fills in other legs causing reduction here
// iii. quantity reduction in the spreader order by the user
_quoter->_order.cancel ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
}
else
{
@@ -72,7 +72,7 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToT
{
// no size could be computed, go to wait state
_quoter->_order.cancel ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK();
}
else
{