Changed limit enforcing to use fills to seed limiter.
This commit is contained in:
1 parent
7f7e1b8483
commit
4875a6db25
4 files changed
+78
-38
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "lib/orderman/actors/order_manager/OrderServicesData.h"
|
||||
#include "lib/orderman/events/NewAdminDataEvent.h"
|
||||
#include "lib/orderman/events/OrderManagerReadyEvent.h"
|
||||
#include "lib/orderman/events/StoredFillEvent.h"
|
||||
#include "lib/orderman/events/StoredOrderEvent.h"
|
||||
#include "lib/orderman/order_factory/OrderFactory.h"
|
||||
#include "lib/orderman/orders/Order.h"
|
||||
@@ -18,7 +19,13 @@ namespace orderman {
|
||||
|
||||
using namespace mercury;
|
||||
|
||||
enum class OrderManager::State { WAIT_ADMIN, WAIT_SEC, WAIT_ORDERS, READY };
|
||||
enum class OrderManager::State {
|
||||
WAIT_ADMIN,
|
||||
WAIT_SEC,
|
||||
WAIT_FILLS,
|
||||
WAIT_ORDERS,
|
||||
READY
|
||||
};
|
||||
|
||||
struct OrderManager::OrderInfo {
|
||||
OrderInfo(Order &o, OrderServicesData &data)
|
||||
@@ -38,6 +45,7 @@ struct OrderManager::PImpl {
|
||||
State state;
|
||||
std::unordered_map<OrderKey, OrderInfo> orders;
|
||||
mercury::Actor::SubHandle stored_order_sub;
|
||||
mercury::Actor::SubHandle stored_fills_sub;
|
||||
OrderServicesData services_data;
|
||||
mercury::Stream<OrderManagerReadyEvent> pub_ready;
|
||||
};
|
||||
@@ -50,6 +58,26 @@ void OrderManager::init() {
|
||||
[this](auto const &admin_update) { this->on_admin_data(admin_update); });
|
||||
}
|
||||
|
||||
void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
|
||||
if (m.events) {
|
||||
|
||||
if (me->state == State::WAIT_ADMIN) {
|
||||
LOG(OrderMan, Info,
|
||||
"Order manager received admin data. Subscribing "
|
||||
"to security list now ");
|
||||
me->state = State::WAIT_SEC;
|
||||
subscribe<NewSecuritiesEvent>([this](auto const &sec_update) {
|
||||
this->on_securities(sec_update);
|
||||
});
|
||||
}
|
||||
|
||||
for (auto ev : *m.events) {
|
||||
me->services_data.order_router.update(*ev.admin_data);
|
||||
me->services_data.limiter.update(*ev.admin_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OrderManager::on_securities(
|
||||
const mercury::Update<NewSecuritiesEvent> &update) {
|
||||
if (update.events) {
|
||||
@@ -67,10 +95,30 @@ void OrderManager::on_securities(
|
||||
if (me->state == State::WAIT_SEC) {
|
||||
LOG(OrderMan, Info,
|
||||
"Order manager received initial set of {} "
|
||||
"securities. Waiting for orders now",
|
||||
"securities. Waiting for stored fills now",
|
||||
update.events->size());
|
||||
me->state = State::WAIT_FILLS;
|
||||
me->stored_fills_sub = subscribe<StoredFillEvent>(
|
||||
[this](auto const &fills) { this->on_fill_recovery(fills); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OrderManager::on_fill_recovery(
|
||||
const mercury::Update<StoredFillEvent> &update) {
|
||||
if (update.events) {
|
||||
if (me->state == State::WAIT_FILLS) {
|
||||
LOG(OrderMan, Info,
|
||||
"Order manager received initial set of {} "
|
||||
"stored fills. Waiting for stored orders now",
|
||||
update.events->size());
|
||||
// obtain recovered orders
|
||||
me->state = State::WAIT_ORDERS;
|
||||
|
||||
for (auto const &ev : *(update.events))
|
||||
me->services_data.limiter.add(*ev.security, ev.fill.account(),
|
||||
ev.fill.side(),
|
||||
Quantity(ev.fill.last_shares()));
|
||||
|
||||
me->stored_order_sub = subscribe<StoredOrderEvent>(
|
||||
[this](auto const &orders) { this->on_order_recovery(orders); });
|
||||
}
|
||||
@@ -111,6 +159,7 @@ void OrderManager::on_order_recovery(
|
||||
// signal that we are ready
|
||||
LOG(OrderMan, Info, "Order manager is ready");
|
||||
publish(me->pub_ready);
|
||||
me->state = State::READY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,24 +391,5 @@ void OrderManager::init_order_services() {
|
||||
std::make_unique<ContentSubscription<CreateOrderReplyEvent>>(*this);
|
||||
}
|
||||
|
||||
void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
|
||||
if (m.events) {
|
||||
|
||||
if (me->state == State::WAIT_ADMIN) {
|
||||
LOG(OrderMan, Info,
|
||||
"Order manager received admin data. Subscribing "
|
||||
"to security list now ");
|
||||
me->state = State::WAIT_SEC;
|
||||
subscribe<NewSecuritiesEvent>([this](auto const &sec_update) {
|
||||
this->on_securities(sec_update);
|
||||
});
|
||||
}
|
||||
|
||||
for (auto ev : *m.events) {
|
||||
me->services_data.order_router.update(*ev.admin_data);
|
||||
me->services_data.limiter.update(*ev.admin_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -18,6 +18,7 @@ class UpdateOrderEvent;
|
||||
class CancelOrderEvent;
|
||||
class CrackOrderEvent;
|
||||
class StoredOrderEvent;
|
||||
class StoredFillEvent;
|
||||
class CreateFIXBufferReplyEvent;
|
||||
class GatewayStatusChangeEvent;
|
||||
class NewAdminDataEvent;
|
||||
@@ -56,6 +57,7 @@ class OrderManager : public mercury::Actor {
|
||||
|
||||
private:
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &);
|
||||
void on_fill_recovery(const mercury::Update<StoredFillEvent> &);
|
||||
void on_order_recovery(const mercury::Update<StoredOrderEvent> &);
|
||||
void on_execution_report(const mercury::Update<NewExecutionReportEvent> &);
|
||||
void on_activate_order(const mercury::Update<ActivateOrderEvent> &);
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace api {
|
||||
namespace admin {
|
||||
class AdminData;
|
||||
}}}
|
||||
|
||||
}
|
||||
} // namespace api
|
||||
} // namespace bts
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
@@ -19,37 +21,42 @@ class Limiter {
|
||||
Limiter();
|
||||
void update(api::admin::AdminData const &);
|
||||
|
||||
void add_securities(std::vector<api::Security const*> const&secs);
|
||||
void add_securities(std::vector<api::Security const *> const &secs);
|
||||
void add_security(api::Security const &new_sec);
|
||||
|
||||
void add(api::Security const &, AccountID, api::Side, Quantity);
|
||||
void remove(api::Security const &, AccountID, api::Side, Quantity);
|
||||
|
||||
void add(api::Security const &, std::string const & /* account_name */,
|
||||
api::Side, Quantity) {}
|
||||
void remove(api::Security const &, std::string const & /* account_name */,
|
||||
api::Side, Quantity) {}
|
||||
|
||||
struct LimiterQueryResult {
|
||||
bool ok;
|
||||
std::string error_msg;
|
||||
};
|
||||
LimiterQueryResult can_trade(UserID user, AccountID into_account) const;
|
||||
LimiterQueryResult can_send_new_order(AccountID into_account,
|
||||
api::Security const&sec,
|
||||
api::Security const &sec,
|
||||
api::Side side,
|
||||
Quantity quantity) const;
|
||||
LimiterQueryResult can_update_order(AccountID account,
|
||||
api::Security const&sec,
|
||||
api::Side side,
|
||||
Quantity from, Quantity to) const;
|
||||
api::Security const &sec, api::Side side,
|
||||
Quantity from, Quantity to) const;
|
||||
~Limiter();
|
||||
// for testing purposes only
|
||||
LimitStore& limit_store();
|
||||
LimitStore &limit_store();
|
||||
|
||||
private:
|
||||
void _reset (const bts::api::admin::AdminData&);
|
||||
private:
|
||||
void _reset(const bts::api::admin::AdminData &);
|
||||
void _add_account_and_reset(AccountID account_id);
|
||||
void _add_security (const api::Security* security);
|
||||
bool _contains_security (const api::Security* security);
|
||||
void _add_security(const api::Security *security);
|
||||
bool _contains_security(const api::Security *security);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -118,7 +118,8 @@ void NativeOrder::on_init_recovered(OrderRecord const &rec,
|
||||
me->definition = def;
|
||||
me->state = rec.state();
|
||||
me->sec = serv.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
|
||||
me->previous_position_contribution = Quantity(rec.state().filled_quantity());
|
||||
|
||||
auto const &native_state = get_native_state(me->state);
|
||||
switch (me->state.status()) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user