AlgoTestDriverBase - ChildTemplate impl, added OrderDefinition param to child_launching callback
This commit is contained in:
1 parent
6d357a74e1
commit
d8bdb69a7c
3 files changed
+28
-17
No files matched your search
@@ -10,6 +10,11 @@
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
struct ChildTemplate {
|
||||
api::orderman::OrderDefinition def;
|
||||
};
|
||||
|
||||
namespace test {
|
||||
using namespace api::orderman;
|
||||
|
||||
@@ -60,6 +65,7 @@ struct AlgoTestDriverBase::Impl : public RecursionCounter {
|
||||
AlgoState state;
|
||||
std::vector<ChildOrder> orders;
|
||||
std::vector<ChildOrder> detached_orders;
|
||||
std::vector<std::unique_ptr<ChildTemplate>> child_templates;
|
||||
|
||||
std::map<SecurityKey, Book> books;
|
||||
std::map<SecurityKey, Price> settlements;
|
||||
@@ -71,12 +77,15 @@ struct AlgoTestDriverBase::Impl : public RecursionCounter {
|
||||
bool sub_position = false;
|
||||
|
||||
// Callbacks
|
||||
std::vector<std::function<void(OrderKey)>> on_child_launching;
|
||||
std::vector<std::function<void(OrderKey, const OrderDefinition&, Quantity, Price)>> on_child_launching;
|
||||
std::vector<std::function<void(const ChildOrder&)>> on_child_changing;
|
||||
std::vector<std::function<void(const ChildOrder&, const ChildOrder&)>> on_child_changed;
|
||||
bool allow_overfill = false;
|
||||
|
||||
Impl(IAlgoOrder& o) : algo(o) {}
|
||||
~Impl() {
|
||||
child_templates.clear();
|
||||
}
|
||||
|
||||
OrderKey next_order() {
|
||||
_next_order.value() += 1;
|
||||
@@ -273,7 +282,7 @@ void AlgoTestDriverBase::fill(Price p, Quantity q) {
|
||||
}
|
||||
}
|
||||
|
||||
void AlgoTestDriverBase::on_child_launching(std::function<void(OrderKey)>&& cb) {
|
||||
void AlgoTestDriverBase::on_child_launching(std::function<void(OrderKey, const OrderDefinition&, Quantity, Price)>&& cb) {
|
||||
me->on_child_launching.push_back(cb);
|
||||
}
|
||||
void AlgoTestDriverBase::on_child_changing(std::function<void(const ChildOrder&)>&& cb) {
|
||||
@@ -282,18 +291,22 @@ void AlgoTestDriverBase::on_child_changing(std::function<void(const ChildOrder&)
|
||||
void AlgoTestDriverBase::on_child_changed(std::function<void(const ChildOrder&, const ChildOrder&)>&& cb) {
|
||||
me->on_child_changed.push_back(cb);
|
||||
}
|
||||
|
||||
void AlgoTestDriverBase::after_child_changed(std::function<void(const ChildOrder&, const ChildOrder&)>&& cb) {
|
||||
me->after_child_changed.push_back(cb);
|
||||
}
|
||||
bool AlgoTestDriverBase::allow_overfill() const { return me->allow_overfill; }
|
||||
void AlgoTestDriverBase::allow_overfill(bool value) { me->allow_overfill = value; }
|
||||
|
||||
//
|
||||
// Utility
|
||||
|
||||
ChildOrder mkchild(OrderKey key, Price price, Quantity qty, bool sub) {
|
||||
ChildOrder mkchild(OrderKey key, api::orderman::OrderDefinition def, Price price, Quantity qty, bool sub, ChildStatus status = ChildStatus::WORKING) {
|
||||
ChildOrder result = {};
|
||||
result.key = key;
|
||||
result.def = def;
|
||||
result.cstate.price = price;
|
||||
result.cstate.quantity = qty;
|
||||
result.cstate.status = status;
|
||||
result.subscribed = sub;
|
||||
return result;
|
||||
}
|
||||
@@ -325,8 +338,11 @@ std::vector<api::Security const *> AlgoTestDriverBase::known_securities() const
|
||||
bool AlgoTestDriverBase::is_attaching() const { return has_flag(me->flags, ATDFlags::IS_ATTACHING); }
|
||||
ChildTemplate& AlgoTestDriverBase::make_child_template(const api::orderman::OrderDefinition& def, size_t) {
|
||||
REQUIRE(def.custom_def().custom_case() != CustomOrderDefinition::CUSTOM_NOT_SET);
|
||||
ChildTemplate* t = nullptr;
|
||||
return *t;
|
||||
auto t = std::make_unique<ChildTemplate>();
|
||||
t->def = def;
|
||||
me->child_templates.emplace_back(std::move(t));
|
||||
return *(me->child_templates.back());
|
||||
|
||||
}
|
||||
TimeStamp AlgoTestDriverBase::get_time() const { return me->now; }
|
||||
|
||||
@@ -403,19 +419,14 @@ void AlgoTestDriverBase::unsubscribe_timer() { me->sub_timer = false; }
|
||||
void AlgoTestDriverBase::subscribe_position() { me->sub_position= true; }
|
||||
void AlgoTestDriverBase::unsubscribe_position() { me->sub_position = false; }
|
||||
|
||||
OrderKey AlgoTestDriverBase::launch_child(ChildTemplate&, Price price, Quantity qty, bool sub) {
|
||||
OrderKey key = me->next_order();
|
||||
me->orders.push_back(
|
||||
mkchild(key, price, qty, sub));
|
||||
for(const auto& cb : me->on_child_launching) cb(key);
|
||||
return key;
|
||||
OrderKey AlgoTestDriverBase::launch_child(ChildTemplate& ctemplate, Price price, Quantity qty, bool sub) {
|
||||
return launch_child(ctemplate.def, price, qty, sub);
|
||||
}
|
||||
OrderKey AlgoTestDriverBase::launch_child(api::orderman::OrderDefinition const & def, Price price, Quantity qty, bool sub) {
|
||||
OrderKey key = me->next_order();
|
||||
me->orders.push_back(
|
||||
mkchild(key, price, qty, sub));
|
||||
me->orders.back().def = {def};
|
||||
for(const auto& cb : me->on_child_launching) cb(key);
|
||||
mkchild(key, def, price, qty, sub));
|
||||
for(const auto& cb : me->on_child_launching) cb(key, def, qty, price);
|
||||
return key;
|
||||
}
|
||||
void AlgoTestDriverBase::update_child(OrderKey key, api::orderman::Update const & update) {
|
||||
|
||||
@@ -89,7 +89,7 @@ class AlgoTestDriverBase : private IAlgoServices {
|
||||
// Fill this quantity, start with the largest child order
|
||||
void fill(Price, Quantity);
|
||||
|
||||
void on_child_launching(std::function<void(OrderKey)>&&);
|
||||
void on_child_launching(std::function<void(OrderKey, const api::orderman::OrderDefinition&, Quantity, Price)>&&);
|
||||
void on_child_changing(std::function<void(const ChildOrder&)>&&);
|
||||
void on_child_changed(std::function<void(const ChildOrder&, const ChildOrder&)>&&);
|
||||
|
||||
|
||||
@@ -577,7 +577,7 @@ TEST_CASE("Increase then decrease", "[algo][splitter]") {
|
||||
|
||||
// Set up some instant fills
|
||||
bool applied_second_update = false;
|
||||
state.on_child_launching([&, update](const auto &) mutable {
|
||||
state.on_child_launching([&, update](const auto &, const auto&, auto, auto) mutable {
|
||||
if (!applied_second_update) {
|
||||
applied_second_update = true;
|
||||
update.mutable_custom()->mutable_splitter()->set_exposed_qty(350);
|
||||
|
||||
Reference in new issue
Block a user