SPARK-285 on_book done

This commit is contained in:
Taha Afzal committed 2017-11-29 12:15:03 -05:00
1 parent 2f2bbe60c1
commit 10d7d5a801
3 files changed
+90 -33

No files matched your search

@@ -778,17 +778,18 @@ void test_complete_quoter_state (const SingleLegQuoter& quoter,
Quantity out_quantity,
Quantity remaining_to_fill,
bool target_reached)
{
{
bts_assert (quoter.test_only_func_quoter_state() == quoter_state);
bts_assert (quoter.test_only_func_ended_by_spreader() == ended_by_spreader);
bts_assert (quoter.test_only_func_price_quantity_state().target_spread_price() == target_spread_price);
bts_assert (quoter.test_only_func_price_quantity_state().target_leg_quantity() == target_leg_quantity);
bts_assert (quoter.test_only_func_price_quantity_state().aggregated_filled_quantity() == aggregated_filled_quantity);
bts_assert (quoter.test_only_func_price_quantity_state().aggregated_hedged_reduction() == aggregated_hedged_reduction);
bts_assert (quoter.test_only_func_price_quantity_state().out_price() == out_price);
bts_assert (quoter.test_only_func_price_quantity_state().out_quantity() == out_quantity);
bts_assert (quoter.test_only_func_price_quantity_state().remaining_to_fill() == remaining_to_fill);
bts_assert (quoter.test_only_func_price_quantity_state().target_reached() == target_reached);
bts_assert (quoter.test_only_func_ended_by_spreader() == ended_by_spreader);
const QuoteLegPriceQuantityState& pq_state = quoter.test_only_func_price_quantity_state();
bts_assert (pq_state.target_spread_price() == target_spread_price);
bts_assert (pq_state.target_leg_quantity() == target_leg_quantity);
bts_assert (pq_state.aggregated_filled_quantity() == aggregated_filled_quantity);
bts_assert (pq_state.aggregated_hedged_reduction() == aggregated_hedged_reduction);
bts_assert (pq_state.out_price() == out_price);
bts_assert (pq_state.out_quantity() == out_quantity);
bts_assert (pq_state.remaining_to_fill() == remaining_to_fill);
bts_assert (pq_state.target_reached() == target_reached);
}
SpreaderManagerForTest create_spreader_manager_2_legs (Venue exchange_1, const std::string& symbol_1, uint32_t year_1, uint32_t month_1, uint32_t day_1, double size_mult_1, double price_mult_1, double lean_mult_1, Side side_1, double leg_delta_1, double tick_size_1,
Venue exchange_2, const std::string& symbol_2, uint32_t year_2, uint32_t month_2, uint32_t day_2, double size_mult_2, double price_mult_2, double lean_mult_2, Side side_2, double leg_delta_2, double tick_size_2)
@@ -1251,17 +1252,69 @@ TEST_CASE ("quoter_WORKING", "[spreader]")
// send out a fill
u.update (api::orderman::OrderStatus::OS_PARTIALLY_FILLED, Quantity (20), Price (2000), nullptr);
quoter.update_order_status (u);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(20), Quantity(0), Price(2000.25), Quantity(100), Quantity (80), false);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(20), Quantity(0), Price(2000.25), Quantity(100), Quantity (80), false);
LOG(OrderMan, Diag, "quoter_WORKING.full_size_update_order_status_non_terminal");
}
// SECTION("2. full_size_update_order_status_terminal")
// {
// // change book to accomodate full size
// double prices_full[] = {2000.0, 2000.25, 2000.5, 2000.75, 2001.0}; uint16_t sizes_full[] = {10, 30, 25, 15, 20};
// fire_book_update (prices_full, sizes_full, api::Side::SIDE_SELL, 0, sm, quoter);
// test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(0), Quantity(0), Price(2000.50), Quantity(100), Quantity (100), false);
// LOG(OrderMan, Diag, "quoter_WORKING.full_size_update_order_status_non_terminal");
// }
SECTION("3. on_book")
{
// to piggy back on the book test, the base
// is set as a partial fill of 10, and a hedge
// reduction of 15
u.update (api::orderman::OrderStatus::OS_PARTIALLY_FILLED, Quantity (10), Price (2000), nullptr);
quoter.update_order_status (u);
quoter.update_other_leg_fills (0, Quantity (15));
double prices_full_0[] = {2000.0, 2000.25, 2000.5, 2000.75, 2001.0}; uint16_t sizes_full_0[] = {10, 30, 25, 15, 20};
fire_book_update (prices_full_0, sizes_full_0, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2000.25), Quantity(85), Quantity (75), false);
// change the book and validate the price (full qty)
double prices_full_1[] = {2000.0, 2000.25, 2000.5, 2000.75, 2001.0}; uint16_t sizes_full_1[] = {75, 0, 0, 0, 0};
fire_book_update (prices_full_1, sizes_full_1, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(1999.5), Quantity(85), Quantity (75), false);
// change the book and validate the price again (full qty)
double prices_full_2[] = {2005.0, 2006, 2007, 2008, 2009}; uint16_t sizes_full_2[] = {1, 1, 1, 1, 71};
fire_book_update (prices_full_2, sizes_full_2, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2008.5), Quantity(85), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
// and again
double prices_full_3[] = {2000.0, 2001, 2002, 2003, 2004}; uint16_t sizes_full_3[] = {1, 1, 70, 2, 1};
fire_book_update (prices_full_3, sizes_full_3, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2003.5), Quantity(85), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
// now decrease the size in book so the full
// target remaining (75) is not there, this should
// result in a reduced order
double prices_full_4[] = {2000.0, 2001, 2002, 2003, 2004}; uint16_t sizes_full_4[] = {1, 1, 1, 1, 26};
fire_book_update (prices_full_4, sizes_full_4, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2003.5), Quantity(40), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
// another reduced size
double prices_full_5[] = {2000.0, 2001, 2002, 2003, 2004}; uint16_t sizes_full_5[] = {1, 0, 0, 0, 0};
fire_book_update (prices_full_5, sizes_full_5, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(1999.5), Quantity(11), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
// and another ...
double prices_full_6[] = {2000.0, 2001, 2002, 2003, 2004}; uint16_t sizes_full_6[] = {1, 1, 1, 1, 1};
fire_book_update (prices_full_6, sizes_full_6, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WORKING, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2003.5), Quantity(15), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
// blank out the book, this should result in cxl'ing the order
double prices_full_7[] = {2000.0, 2001, 2002, 2003, 2004}; uint16_t sizes_full_7[] = {0, 0, 0, 0, 0};
fire_book_update (prices_full_7, sizes_full_7, api::Side::SIDE_SELL, 0, sm, quoter);
test_complete_quoter_state (quoter, QuoterState::WAITING_FOR_CANCEL_ACK, false, spreader_price, spreader_quantity, Quantity(10), Quantity(15), Price(2003.5), Quantity(15), Quantity (75), false);
LOG(OrderMan, Diag, "quoter_WORKING.on_book");
}
SECTION("4. cancel_order")
{
quoter.cancel_order();
test_complete_quoter_state (quoter, QuoterState::WAITING_FOR_CANCEL_ACK, true, spreader_price, spreader_quantity, Quantity(0), Quantity(0), Price(2000.50), Quantity(40), Quantity (100), false);
LOG(OrderMan, Diag, "quoter_WORKING.cancel_order");
}
SECTION("5. terminate")
{
quoter.terminate ();
test_complete_quoter_state (quoter, QuoterState::END, true, spreader_price, spreader_quantity, Quantity(0), Quantity(0), Price(2000.50), Quantity(40), Quantity (100), false);
LOG(OrderMan, Diag, "quoter_WORKING.terminate");
}
}
//TEST_CASE ("Spreader Order", "[spreader]")
// void disabled_temp()
@@ -93,14 +93,14 @@ void SingleLegQuoter::_incorporate_other_leg_fill (size_t leg_index, Quantity fi
}
void SingleLegQuoter::_compute_price_quantity(Price& price, Quantity& quantity)
{
Quantity remaining_quantity = _price_quantity_state.remaining_to_fill();
if (_two_legged)
{
size_t other_leg_index = _this_leg_data.leg_index() == 0 ? 1 : 0;
SpreaderUtils::compute_price_quantity_2_legs (_price_quantity_state.target_spread_price(), _price_quantity_state.remaining_to_fill(),
SpreaderUtils::compute_price_quantity_2_legs (_price_quantity_state.target_spread_price(), remaining_quantity,
_this_leg_data, _spreader.get_leg_data(other_leg_index), _spreader.get_book(other_leg_index),
price, quantity);
// to adjust for what has already been filled
quantity = Quantity (quantity.value() + _price_quantity_state.aggregated_filled_quantity().value());
bts_assert (quantity.value() <= remaining_quantity.value());
}
else _compute_price_quantity_n_legs (price, quantity);
}
@@ -35,7 +35,8 @@ void QuoterWorkingStateWorker::on_book (bts::orderman::TickToTradeCorID corid, s
}
void QuoterWorkingStateWorker::cancel()
{
_quoter->_order.cancel ();
//TODO:temp
//_quoter->_order.cancel ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
}
void QuoterWorkingStateWorker::terminate()
@@ -67,35 +68,38 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToT
}
else
{
Price new_price; Quantity new_quantity;
_quoter->_compute_price_quantity (new_price, new_quantity);
if (new_quantity.value() == 0)
Price computed_price; Quantity computed_quantity;
_quoter->_compute_price_quantity (computed_price, computed_quantity);
if (computed_quantity.value() == 0)
{
// no size could be computed, go to wait state
_quoter->_order.cancel ();
// TODO:temp
//_quoter->_order.cancel ();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK();
}
else
{
if (new_quantity.value() != _quoter->_price_quantity_state.out_quantity().value())
// to adjust for what has already been filled
Quantity order_quantity = Quantity (computed_quantity.value() + _quoter->_price_quantity_state.aggregated_filled_quantity().value());
if (order_quantity.value() != _quoter->_price_quantity_state.out_quantity().value())
{
// this is a size change, size changes always go through regardless of the
// quoting parameters
_quoter->_price_quantity_state.update_out_price_quantity(new_price, new_quantity);
_quoter->_price_quantity_state.update_out_price_quantity(computed_price, order_quantity);
//TODO:temp disable for tests
//_quoter->_order.update(corid, new_price, new_quantity);
//_quoter->_order.update(corid, computed_price, order_quantity);
}
else
{
bool reprice = true;
if (_quoter->_this_leg_data.leg_params().quote_params().has_quote_mute_zone())
reprice = SpreaderUtils::reprice_quote_mute_zone(_quoter->_price_quantity_state.out_price().value(), new_price.value(), _quoter->_this_leg_data.trading_side(),
reprice = SpreaderUtils::reprice_quote_mute_zone(_quoter->_price_quantity_state.out_price().value(), computed_price.value(), _quoter->_this_leg_data.trading_side(),
_quoter->_this_leg_data.tick_size(), _quoter->_this_leg_data.leg_params().quote_params().quote_mute_zone());
if (reprice)
{
_quoter->_price_quantity_state.update_out_price_quantity(new_price, new_quantity);
_quoter->_price_quantity_state.update_out_price_quantity(computed_price, order_quantity);
//TODO:temp disable for tests
//_quoter->_order.update(corid, new_price, new_quantity);
//_quoter->_order.update(corid, computed_price, order_quantity);
}
}
}