tests adjusted for avg price vs last price

This commit is contained in:
Taha Afzal committed 2018-02-15 16:05:01 -05:00
1 parent 11a01c895c
commit c60103d654
6 files changed
+32 -48

No files matched your search

@@ -146,12 +146,18 @@ public:
SpreaderBookkeepingData& test_only_func_spreader_full_data () {return _bookkeeping_data();}
int64_t test_cancel_timeout () {return _cancel_timeout;}
void test_only_on_book_update(const bts::orderman::BookUpdateEvent& b) {_on_book_update(b);}
void test_only_on_book_update(const bts::orderman::Book& b, bts::orderman::TickToTradeCorID corid)
void test_only_on_book_update(const bts::orderman::Book& b, bts::orderman::TickToTradeCorID corid) {_on_book_update(bts::orderman::BookUpdateEvent(b, corid));}
void test_only_on_child_order_update (bts::orderman::OrderKey order_key, bts::api::orderman::OrderStatus status, Quantity total_filled_qty, Price avg_price)
{
bts::orderman::BookUpdateEvent be(b, corid);
_on_book_update(be);
bts::api::orderman::OrderDefinition order_def;
order_def.set_security_key(0);
bts::api::orderman::OrderState order_state;
order_state.set_status(status);
order_state.set_filled_quantity(total_filled_qty.value());
order_state.set_last_price(avg_price.value());
OrderStateUpdateEvent ord_ev (order_key, OrderKey(0), order_def, order_state);
_on_child_order_update (ord_ev);
}
void test_only_on_child_order_update (bts::orderman::OrderKey, bts::api::orderman::OrderStatus, Quantity, Price) {}
void test_only_on_init_new(const bts::api::orderman::OrderDefinition& order_def, const SpreaderPreActivationOrderServices& pao_services) {_on_init_new(order_def, pao_services);}
void test_only_on_activate(Price price, Quantity quantity, SpreaderOrderServices& order_services) {_on_activate(price, quantity, order_services);}
void test_only_on_time (TimeStamp){}
@@ -111,19 +111,15 @@ public:
bts_assert(!_is_live || e.key == order_key());
bts_assert(e.state.filled_quantity() >= _filled_quantity.value());
_status = e.state.status();
_last_filled_quantity = Quantity(e.state.filled_quantity() - e.state.filled_quantity());
_last_filled_quantity = Quantity(e.state.filled_quantity() - _filled_quantity.value());
_last_filled_price = Price(e.state.last_price());
_filled_price = Price((_filled_quantity.value() * _filled_price.value() + _last_filled_quantity.value() * _last_filled_price.value())/e.state.filled_quantity());
_filled_quantity = Quantity(e.state.filled_quantity());
}
void on_order_update(api::orderman::OrderStatus status)
{
_last_filled_quantity = Quantity(0);
_status = status;
}
// the filled quantity and average price are the total
// over the course of the order (this is how the order
// infrastructure provides that data)
// (this is just to aupport testing since the interface changed after that)
void on_order_update(api::orderman::OrderStatus status,
Quantity filled_quantity,
Price filled_price)
@@ -44,39 +44,29 @@ void SpreaderWaitingForCancelAllStateWorker::on_time(const TimeStamp& ts)
_spreader->_transform_to_END ();
}
}
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_error(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_error(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus, Quantity, Price)
{
leg_data.order_update_message().on_order_update (status, filled_quantity, average_price);
leg_data.quoter().update_order_status (leg_data.order_update_message());
}
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status,
Quantity filled_quantity, Price average_price)
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus, Quantity, Price)
{
leg_data.order_update_message().on_order_update (status, filled_quantity, average_price);
leg_data.quoter().update_order_status (leg_data.order_update_message());
}
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_status_update(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status)
void SpreaderWaitingForCancelAllStateWorker::on_quoter_order_status_update(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus)
{
leg_data.order_update_message().on_order_update (status);
leg_data.quoter().update_order_status (leg_data.order_update_message());
}
void SpreaderWaitingForCancelAllStateWorker::on_hedger_order_error(bts::orderman::OrderKey order_key, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWaitingForCancelAllStateWorker::on_hedger_order_error(bts::orderman::OrderKey order_key, api::orderman::OrderStatus, Quantity, Price)
{
SpreaderHedgerData* hedger_data = _spreader->_bookkeeping_data().find_hedger_from_orderkey(order_key);
if (hedger_data != nullptr)
{
hedger_data->order_update_message().on_order_update(status, filled_quantity, average_price);
hedger_data->hedger().on_order_update(hedger_data->order_update_message());
}
}
void SpreaderWaitingForCancelAllStateWorker::on_hedger_order_update(bts::orderman::OrderKey order_key, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWaitingForCancelAllStateWorker::on_hedger_order_update(bts::orderman::OrderKey order_key, api::orderman::OrderStatus, Quantity, Price)
{
SpreaderHedgerData* hedger_data = _spreader->_bookkeeping_data().find_hedger_from_orderkey(order_key);
if (hedger_data != nullptr)
{
hedger_data->order_update_message().on_order_update(status, filled_quantity, average_price);
hedger_data->hedger().on_order_update(hedger_data->order_update_message());
}
}
void SpreaderWaitingForCancelAllStateWorker::on_check_termination()
{
@@ -77,15 +77,14 @@ void SpreaderWorkingStateWorker::on_time(const TimeStamp& ts)
}
}
}
void SpreaderWorkingStateWorker::on_quoter_order_error(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
{
leg_data.order_update_message().on_order_update(status, filled_quantity, average_price);
void SpreaderWorkingStateWorker::on_quoter_order_error(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus, Quantity, Price)
{
// this is because the error message could also have status changes
leg_data.quoter().update_order_status (leg_data.order_update_message());
_spreader->_cancel_orders (true, true);
_spreader->_transform_to_WAITING_FOR_CANCEL_ALL ();
}
void SpreaderWorkingStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWorkingStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus, Quantity, Price)
{
// this is the most complex part of the spreader. the following needs to be done
// 1. update the order state
@@ -94,7 +93,6 @@ void SpreaderWorkingStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLeg
// 4. launch a new hedger
// 5. init the hedger
SpreaderChildOrderState& order_update_message = leg_data.order_update_message();
order_update_message.on_order_update (status, filled_quantity, average_price);
leg_data.quoter().update_order_status (order_update_message);
if (order_update_message.last_update_filled_quantity().value() > 0)
{
@@ -113,30 +111,23 @@ void SpreaderWorkingStateWorker::on_quoter_order_fill(bts::orderman::SpreaderLeg
}
}
}
void SpreaderWorkingStateWorker::on_quoter_order_status_update(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus status)
void SpreaderWorkingStateWorker::on_quoter_order_status_update(bts::orderman::SpreaderLegData& leg_data, api::orderman::OrderStatus)
{
leg_data.order_update_message().on_order_update (status);
leg_data.quoter().update_order_status (leg_data.order_update_message());
}
void SpreaderWorkingStateWorker::on_hedger_order_error(bts::orderman::OrderKey order_key, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWorkingStateWorker::on_hedger_order_error(bts::orderman::OrderKey order_key, api::orderman::OrderStatus, Quantity, Price)
{
SpreaderHedgerData* hedger_data = _spreader->_bookkeeping_data().find_hedger_from_orderkey(order_key);
if (hedger_data != nullptr)
{
hedger_data->order_update_message().on_order_update(status, filled_quantity, average_price);
hedger_data->hedger().on_order_update(hedger_data->order_update_message());
}
_spreader->_cancel_orders (true, true);
_spreader->_transform_to_WAITING_FOR_CANCEL_ALL ();
}
void SpreaderWorkingStateWorker::on_hedger_order_update(bts::orderman::OrderKey order_key, api::orderman::OrderStatus status, Quantity filled_quantity, Price average_price)
void SpreaderWorkingStateWorker::on_hedger_order_update(bts::orderman::OrderKey order_key, api::orderman::OrderStatus, Quantity, Price)
{
SpreaderHedgerData* hedger_data = _spreader->_bookkeeping_data().find_hedger_from_orderkey(order_key);
if (hedger_data != nullptr)
{
hedger_data->order_update_message().on_order_update(status, filled_quantity, average_price);
hedger_data->hedger().on_order_update(hedger_data->order_update_message());
}
}
void SpreaderWorkingStateWorker::on_check_termination()
{
@@ -1529,7 +1529,7 @@ TEST_CASE ("spreader_WORKING", "[spreader]")
set_spreader_orders (spreader, new double[5] {1999, 1998, 1997, 1996, 1995}, new uint16_t[5] {50, 50, 10, 10, 30},
new double[5] {2000, 2001, 2002, 2003, 2004}, new uint16_t[5] {10, 15, 25, 50, 10},
new double[5] {2002, 2001, 2000, 1999, 1998}, new uint16_t[5] {20, 20, 20, 20, 20},
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {25, 25, 20, 20, 10});
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {25, 25, 20, 20, 10}, 0, 0, 0, 0);
// verify working orders
verify_complete_quoter_state (leg_data_1.quoter(), QuoterState::WORKING, false, spreader_price, Quantity (100), Quantity (0), Quantity(0), Price(1999), Quantity(100), Quantity(100), false);
verify_complete_quoter_state (leg_data_2.quoter(), QuoterState::WORKING, false, spreader_price, Quantity (100), Quantity (0), Quantity(0), Price(2002), Quantity(100), Quantity(100), false);
@@ -1857,7 +1857,7 @@ TEST_CASE ("spreader_WAITING_FOR_CANCEL_ACK", "[spreader]")
set_spreader_orders (spreader, new double[5] {1999, 1998, 1997, 1996, 1995}, new uint16_t[5] {50, 50, 10, 10, 30},
new double[5] {2000, 2001, 2002, 2003, 2004}, new uint16_t[5] {10, 15, 25, 50, 10},
new double[5] {2002, 2001, 2000, 1999, 1998}, new uint16_t[5] {20, 20, 20, 20, 20},
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {25, 25, 20, 20, 10});
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {25, 25, 20, 20, 10}, 0, 0, 0, 0);
// verify working orders
verify_complete_quoter_state (leg_data_1.quoter(), QuoterState::WORKING, false, spreader_price, Quantity (100), Quantity (0), Quantity(0), Price(1999), Quantity(100), Quantity(100), false);
verify_complete_quoter_state (leg_data_2.quoter(), QuoterState::WORKING, false, spreader_price, Quantity (100), Quantity (0), Quantity(0), Price(2002), Quantity(100), Quantity(100), false);
@@ -1943,7 +1943,7 @@ TEST_CASE ("spreader_WAITING_FOR_CANCEL_ACK", "[spreader]")
set_spreader_orders (spreader, new double[5] {1999, 1998, 1997, 1996, 1995}, new uint16_t[5] {1, 0, 0, 0, 0},
new double[5] {2000, 2001, 2002, 2003, 2004}, new uint16_t[5] {1, 1, 2, 0, 0},
new double[5] {2002, 2001, 2000, 1999, 1998}, new uint16_t[5] {1, 0, 0, 0, 0},
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {1, 0, 0, 0, 0});
new double[5] {2003, 2004, 2005, 2006, 2007}, new uint16_t[5] {1, 0, 0, 0, 0}, 30, 2000, 55, 2001);
validate_state ();
LOG(OrderMan, Diag, "spreader_WAITING_FOR_CANCEL_ACK.on_book");
}
@@ -2112,5 +2112,4 @@ TEST_CASE ("spreader_WAITING_FOR_CANCEL_ACK", "[spreader]")
// }
// };
}}
}}
@@ -397,7 +397,9 @@ void validate_book (const bts::orderman::Book& b1, const bts::orderman::Book& b2
void set_spreader_orders (SpreaderOrder& spreader, double* leg_1_bid_prices, uint16_t* leg_1_bid_sizes,
double* leg_1_ask_prices, uint16_t* leg_1_ask_sizes,
double* leg_2_bid_prices, uint16_t* leg_2_bid_sizes,
double* leg_2_ask_prices, uint16_t* leg_2_ask_sizes)
double* leg_2_ask_prices, uint16_t* leg_2_ask_sizes,
uint32_t leg_1_fills, double leg_1_filled_price,
uint32_t leg_2_fills, double leg_2_filled_price)
{
SpreaderBookkeepingData& bookkeeping_data = spreader.test_only_func_spreader_full_data ();
SpreaderLegData& leg_data_1 = bookkeeping_data.get_leg_data (0);
@@ -412,8 +414,8 @@ void set_spreader_orders (SpreaderOrder& spreader, double* leg_1_bid_prices, uin
leg_2_bid_prices, leg_2_bid_sizes,
leg_2_ask_prices, leg_2_ask_sizes, true);
spreader.test_only_on_book_update (bts::orderman::BookUpdateEvent(book_leg_2,bts::orderman::NullTickToTradeCorID));
spreader.test_only_on_child_order_update (leg_data_1.order_key(), api::orderman::OrderStatus::ORDER_STATUS_WORKING, Quantity (0), Price (0));
spreader.test_only_on_child_order_update (leg_data_2.order_key(), api::orderman::OrderStatus::ORDER_STATUS_WORKING, Quantity (0), Price (0));
spreader.test_only_on_child_order_update (leg_data_1.order_key(), api::orderman::OrderStatus::ORDER_STATUS_WORKING, Quantity (leg_1_fills), Price (leg_1_filled_price));
spreader.test_only_on_child_order_update (leg_data_2.order_key(), api::orderman::OrderStatus::ORDER_STATUS_WORKING, Quantity (leg_2_fills), Price (leg_2_filled_price));
}
/**********************************************************************/
/******************************misc************************************/