Added test for sim order with no book effects

This commit is contained in:
Taha Afzal committed 2020-10-27 14:38:03 -04:00
1 parent d0aa686693
commit 0e1da96e52
2 files changed
+80 -14

No files matched your search

@@ -188,17 +188,18 @@ void FifoSecurityMatcher::_on_order_not_affecting_books(
auto[new_level_qty_ret,new_ord_rem_ret] =
MatcherOrder::compute_cross(level_qty,new_ord_rem);
auto fill_size = level_qty - new_level_qty_ret;
new_ord_rem = new_ord_rem_ret;
res->push_back(OrderUpdate{
ord.key,
new_ord_rem > 0 ?
OrderUpdate::Status::PARTIALLY_FILLED :
OrderUpdate::Status::FILLED,
ord.security,
ord.side,
MDP3Quantity(fill_size),
pl.price()
});
new_ord_rem = new_ord_rem_ret;
if(res != nullptr)
res->push_back(OrderUpdate{
ord.key,
new_ord_rem > 0 ?
OrderUpdate::Status::PARTIALLY_FILLED :
OrderUpdate::Status::FILLED,
ord.security,
ord.side,
MDP3Quantity(fill_size),
pl.price()
});
}
else
break;
@@ -199,12 +199,16 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") {
auto order_key = 0;
auto priority = 0;
auto add_to_book = [&](uint32_t n_orders, api::Side side,
double price) -> void {
double price,
FifoSecurityMatcher* sec_me_arg = nullptr,
bool is_sim_order = false) -> void {
for (uint32_t i = 1; i <= n_orders; i++) {
auto o =
create_order(order_key++, sec_key, side, priority++, price, i);
sec_me.on_order_change(OrderChange{MDP3Order{},o,OrderChange::added});
o.is_sim_order = is_sim_order;
FifoSecurityMatcher* sec_me_ptr = sec_me_arg == nullptr ?
&sec_me : sec_me_arg;
(*sec_me_ptr).on_order_change(OrderChange{MDP3Order{},o,OrderChange::added});
}
};
SECTION("add") {
@@ -257,6 +261,67 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") {
}
}
}
SECTION("add_sim_no_effect") {
FifoSecurityMatcher sec_me_sim_no_effect(MDP3SecurityID(100),0,false);
// bids
auto n_levels = 10;
// bids
for (struct {
int i = 0;
double p = 15;
void inc() {
i++;
p += 0.01;
}
} lp;
lp.i < n_levels; lp.inc())
add_to_book((lp.i + 1) * 10, api::Side::SIDE_BUY, lp.p,&sec_me_sim_no_effect);
// asks
for (struct {
int i = 0;
double p = 15.10;
void inc() {
i++;
p += 0.01;
}
} lp;
lp.i < n_levels; lp.inc())
add_to_book((lp.i + 1) * 10, api::Side::SIDE_SELL, lp.p,&sec_me_sim_no_effect);
auto verify_bids = [&](){
Book bid_bk = sec_me_sim_no_effect.book(api::Side::SIDE_BUY);
double exp_price = 15.09;
for (int i = 0; i < n_levels; i++) {
auto exp_n_orders = 100 - i * 10;
auto exp_qty =
(static_cast<double>(exp_n_orders) / 2) * (1 + exp_n_orders);
verify_book_level(bid_bk.at(i), exp_price, exp_qty, exp_n_orders);
exp_price -= 0.01;
}
};
auto verify_asks = [&](){
Book ask_bk = sec_me_sim_no_effect.book(api::Side::SIDE_SELL);
double exp_price = 15.10;
for (int i = 0; i < n_levels; i++) {
auto exp_n_orders = (i + 1) * 10;
auto exp_qty =
(static_cast<double>(exp_n_orders) / 2) * (1 + exp_n_orders);
verify_book_level(ask_bk.at(i), exp_price, exp_qty, exp_n_orders);
exp_price += 0.01;
}
};
verify_bids();
verify_asks();
// bids: 15.00-15.09
// asks: 15.10-15.19
// add a passive order, should have no effect on the markets
add_to_book(100, api::Side::SIDE_BUY, 15.09,&sec_me_sim_no_effect,true);
verify_bids();
verify_asks();
// add an aggressive order
add_to_book(100, api::Side::SIDE_BUY, 15.19,&sec_me_sim_no_effect,true);
verify_bids();
verify_asks();
}
SECTION("remove") {
auto n_levels = 10;
// bids