Spreader tests pass while sending orders to sim

This commit is contained in:
Taha Afzal committed 2020-09-28 21:32:19 -04:00
1 parent ed3cc43e59
commit f83d57fc0c
3 files changed
+91 -6

No files matched your search

@@ -19,13 +19,18 @@ private:
public:
OrderChange last_change;
size_t n_updates = 0;
size_t key;
public:
TestSimServices ()
:
key(0){
}
std::vector<InstrumentDefinition const*> const &instruments() const override{
bts_assert(false);
return _instruments;
}
MDP3OrderKey generate_order_key() override{
return MDP3OrderKey(0);
return MDP3OrderKey(key++);
}
virtual MDP3TimeStamp now() const override{
return MDP3TimeStamp(0);
@@ -4164,7 +4169,6 @@ bts::spartan::mdp3::MBPUpdate get_book_update(
return rv;
}
TEST_CASE ("sim_spreader", "[spreader]"){
bts::orderman::OrderKey order_key(1);
// security
@@ -4197,7 +4201,7 @@ TEST_CASE ("sim_spreader", "[spreader]"){
// putting it together in the order def
bts::api::orderman::OrderDefinition order_def;
fill_spreader_order_definition(order_def, Side::SIDE_BUY, sec, params);
bts::spartan::mdp3::SimSpreader sim_spreader(order_def,sec,Price(-10),Quantity(25));
bts::spartan::mdp3::SimSpreader sim_spreader(order_def,sec,Price(-10),Quantity(1));
//ISimServices* sim_services = new TestSimServices();
TestSimServices sim_services;
sim_spreader.init(*(ISimServices*)&sim_services);
@@ -4210,7 +4214,7 @@ TEST_CASE ("sim_spreader", "[spreader]"){
},
asks =
{
{102,5},
{103,5},
{104,5},
{105,5}
};
@@ -4225,7 +4229,80 @@ TEST_CASE ("sim_spreader", "[spreader]"){
);
sim_spreader.on_time(bts::spartan::mdp3::MDP3TimeStamp());
REQUIRE(sim_services.n_updates==1);
}
REQUIRE(sim_services.last_change.order.side == api::Side::SIDE_SELL);
REQUIRE(sim_services.last_change.order.quantity == bts::spartan::mdp3::MDP3Quantity(1));
REQUIRE(
bts::securities::is_same(Price(sim_services.last_change.order.price.price()),
Price(113)));
// send multiple book updates
double p = 103;
for(int i=0; i<100; i++){
asks =
{
{p,5},
{p+1,5},
{p+2,5}
};
auto md_udpate_leg_1 = get_book_update(bids,asks,leg_1.security().id());
sim_spreader.on_notification(
{
bts::spartan::mdp3::MDP3TimeStamp{},
bts::spartan::mdp3::MDP3TimeStamp{},
md_udpate_leg_1
});
REQUIRE(sim_services.n_updates==i+1); // +1 because order_place is also counted
REQUIRE(sim_services.last_change.order.security ==
bts::spartan::mdp3::MDP3SecurityID(2));
REQUIRE(sim_services.last_change.order.side == api::Side::SIDE_SELL);
REQUIRE(sim_services.last_change.order.quantity == bts::spartan::mdp3::MDP3Quantity(1));
REQUIRE(
bts::securities::is_same(Price(sim_services.last_change.order.price.price()),
Price(p+10)));
p++;
}
//force a quoting leg fill
auto q_ord = sim_services.last_change.order;
sim_spreader.on_notification(
{
bts::spartan::mdp3::MDP3TimeStamp{},
bts::spartan::mdp3::MDP3TimeStamp{},
bts::spartan::mdp3::OrderUpdate{
q_ord.key,
bts::spartan::mdp3::OrderUpdate::FILLED,
q_ord.security,
q_ord.side,
bts::spartan::mdp3::MDP3Quantity(1),
md::IntPrice_from_double<7>(202)
}
});
// the above should have sent a hedge order, verify that
auto hedge_ord = sim_services.last_change.order;
REQUIRE(hedge_ord.security == bts::spartan::mdp3::MDP3SecurityID(1));
REQUIRE(hedge_ord.side == api::Side::SIDE_BUY);
REQUIRE(hedge_ord.quantity == bts::spartan::mdp3::MDP3Quantity(1));
REQUIRE(
bts::securities::is_same(Price(hedge_ord.price.price()),
Price(192)));
REQUIRE(sim_spreader.spreader().test_only_func_spreader_state() !=
SpreaderState::END);
sim_spreader.on_time(bts::spartan::mdp3::MDP3TimeStamp());
// send the hedge fill and it should go to end state
sim_spreader.on_notification(
{
bts::spartan::mdp3::MDP3TimeStamp{},
bts::spartan::mdp3::MDP3TimeStamp{},
bts::spartan::mdp3::OrderUpdate{
hedge_ord.key,
bts::spartan::mdp3::OrderUpdate::FILLED,
hedge_ord.security,
hedge_ord.side,
bts::spartan::mdp3::MDP3Quantity(1),
md::IntPrice_from_double<7>(192)
}
});
REQUIRE(sim_spreader.spreader().test_only_func_spreader_state() ==
SpreaderState::END);
}
}
class RV
@@ -74,7 +74,12 @@ SimSpreader::SimSpreader(const OrderDefinition& order_def,
:
me(new PImpl(order_def,sec,price,qty)){
}
const SpreaderOrder& SimSpreader::spreader() const{
return me->spreader;
}
// IAlgoModel /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void SimSpreader::init(ISimServices& sim_services){
me->sim_services = &sim_services;
me->sim_order_gateway.init(sim_services,me->spreader);
@@ -7,6 +7,7 @@
namespace bts { namespace api { namespace orderman {class OrderDefinition;}}}
namespace bts { namespace api { class OrderDefinition;}}
namespace bts { namespace orderman { class SpreaderOrder;}}
namespace bts::spartan::mdp3 {
@@ -21,9 +22,11 @@ public:
SimSpreader(const bts::api::orderman::OrderDefinition&,
const bts::api::Security&,
Price, Quantity);
const bts::orderman::SpreaderOrder& spreader() const;
// IAlgoModel
void init(ISimServices&) override;
void on_time(MDP3TimeStamp) override;
void on_notification(AlgoNotification const&) override;
void on_notification(AlgoNotification const&) override;
~SimSpreader(){}
};