Routing ExchangePosition to OrderServiceServer
This commit is contained in:
1 parent
96d58942d0
commit
6ecccdee7f
22 files changed
+210
-21
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/config/protos/orderman_cfg.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/MDClient.h"
|
||||
#include "lib/md/MDConsumer.h"
|
||||
#include "lib/mercury/actors/Timer.h"
|
||||
@@ -19,6 +20,7 @@
|
||||
#include "lib/orderman/actors/SecuritySrc.h"
|
||||
#include "lib/orderman/actors/ServiceBridge.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderManager.h"
|
||||
#include "lib/orderman/events/ExchangePositionEvent.h"
|
||||
#include "lib/orderman/events/OrderOpResultEvent.h"
|
||||
#include "lib/orderman/order_factory/DynamicOrderRegistry.h"
|
||||
#include "lib/plugin/SparkServices.h"
|
||||
@@ -139,6 +141,8 @@ OrderServiceServer::OrderServiceServer(
|
||||
md::TradeSummarySignalDispatcher &tssd)
|
||||
: api::orderman::OrderServiceBase(ctx),
|
||||
me(new PImpl(ctx, mdc, d, stats, log)) {
|
||||
LOG(md, Info, "OrderServiceServer cons t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
me->publish_orders = make_orders_publisher();
|
||||
me->publish_fills = make_fills_publisher();
|
||||
|
||||
@@ -228,6 +232,10 @@ OrderServiceServer::OrderServiceServer(
|
||||
this->on_order_op_result(order_op_result);
|
||||
});
|
||||
},
|
||||
[](const ExchangePosition &exch_pos) {
|
||||
LOG(OrderMan, Info, "OrderServiceServer exchange position n_pos: {} ",
|
||||
exch_pos.total_exchange_positions.size());
|
||||
},
|
||||
me->dyn_order_registry, thread->executor.make_proxy(), mdc.oracle());
|
||||
|
||||
thread->executor.activate(me->service_bridge);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "lib/orderman/events/OrderDefinitionUpdateEvent.h"
|
||||
#include "lib/orderman/events/OrderStateUpdateEvent.h"
|
||||
#include "lib/orderman/events/StoredFillEvent.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/overloaded.h"
|
||||
@@ -39,7 +40,10 @@ struct FillStore::PImpl {
|
||||
md::SecurityOracle oracle;
|
||||
};
|
||||
|
||||
FillStore::FillStore(md::SecurityOracle o) : me(new PImpl(o)) {}
|
||||
FillStore::FillStore(md::SecurityOracle o) : me(new PImpl(o)) {
|
||||
LOG(OrderMan, Info, "FillStore cons t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
}
|
||||
|
||||
// returns the sod type of a non sod type fill
|
||||
auto sod_fill_kind(const api::orderman::Fill &fill) {
|
||||
@@ -82,7 +86,8 @@ auto leg_fill_kind(const api::Security &parent, const api::Security &child) {
|
||||
}
|
||||
|
||||
void FillStore::init() {
|
||||
|
||||
LOG(OrderMan, Info, "FillStore::init t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
// Subscribe to NewExecutionReportEvent for new fills
|
||||
subscribe<NewExecutionReportEvent>(
|
||||
[this](auto const &ev) { this->on_execution_report(ev); });
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "lib/api/service_helpers/PositionUtilities.h"
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/api/services/PositionService.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/mercury/broker/BrokerProxy.h"
|
||||
#include "lib/orderman/OrderRouter.h"
|
||||
#include "lib/orderman/events/AccountPnLUpdateEvent.h"
|
||||
@@ -10,6 +11,7 @@
|
||||
#include "lib/orderman/events/CancelOrderEvent.h"
|
||||
#include "lib/orderman/events/DetachOrderEvent.h"
|
||||
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
|
||||
#include "lib/orderman/events/ExchangePositionEvent.h"
|
||||
#include "lib/orderman/events/FilledPositionEvent.h"
|
||||
#include "lib/orderman/events/NewAdminDataEvent.h"
|
||||
#include "lib/orderman/events/OrderManagerReadyEvent.h"
|
||||
@@ -34,11 +36,13 @@ struct ServiceBridge::PImpl {
|
||||
OnOrders const &on_orders,
|
||||
OnFills const &on_fills,
|
||||
OnOrderOpResult const &on_order_op_result,
|
||||
OnExchangePosition const &on_exchange_position,
|
||||
DynamicOrderRegistry const &dyn_order_registry,
|
||||
mercury::BrokerProxy &service_call_marshaller,
|
||||
md::SecurityOracle o)
|
||||
: on_ready(on_ready), on_orders(on_orders), on_fills(on_fills),
|
||||
on_order_op_result(on_order_op_result), have_orders(false),
|
||||
on_order_op_result(on_order_op_result),
|
||||
on_exchange_position(on_exchange_position), have_orders(false),
|
||||
order_manager_ready(false), sec_db(o), order_router(),
|
||||
order_factory(sec_db, order_router, dyn_order_registry),
|
||||
known_orders(), service_call_marshaller(service_call_marshaller) {}
|
||||
@@ -47,6 +51,7 @@ struct ServiceBridge::PImpl {
|
||||
OnOrders on_orders;
|
||||
OnFills on_fills;
|
||||
OnOrderOpResult on_order_op_result;
|
||||
OnExchangePosition on_exchange_position;
|
||||
bool have_orders;
|
||||
bool order_manager_ready;
|
||||
securities::MapSecurityDB sec_db;
|
||||
@@ -71,6 +76,7 @@ ServiceBridge::ServiceBridge(
|
||||
OnOrders const &on_orders,
|
||||
OnFills const &on_fills,
|
||||
OnOrderOpResult const &on_order_op_result,
|
||||
OnExchangePosition const &on_exchange_position,
|
||||
DynamicOrderRegistry const &dyn_order_registry,
|
||||
mercury::BrokerProxy &service_call_marshaller,
|
||||
md::SecurityOracle o)
|
||||
@@ -79,9 +85,13 @@ ServiceBridge::ServiceBridge(
|
||||
on_orders,
|
||||
on_fills,
|
||||
on_order_op_result,
|
||||
on_exchange_position,
|
||||
dyn_order_registry,
|
||||
service_call_marshaller,
|
||||
o)) {}
|
||||
o)) {
|
||||
LOG(md, Info, "ServiceBridge cons t_id: {} t_name: {}", os::get_thread_id(),
|
||||
os::get_thread_name());
|
||||
}
|
||||
|
||||
ServiceBridge::~ServiceBridge() {}
|
||||
|
||||
@@ -93,6 +103,24 @@ void ServiceBridge::init() {
|
||||
subscribe<StoredOrderEvent>([this](auto const &u) { this->on(u); });
|
||||
subscribe<OrderManagerReadyEvent>([this](auto const &u) { this->on(u); });
|
||||
subscribe<OrderOpResultEvent>([this](auto const &u) { this->on(u); });
|
||||
subscribe<ExchangePositionEvent>(
|
||||
[this](mercury::Update<ExchangePositionEvent> const &u) {
|
||||
if (u.events == nullptr) {
|
||||
LOG(OrderMan, Warn,
|
||||
"ServiceBridge ExchangePositionEvent callback null events");
|
||||
return;
|
||||
}
|
||||
LOG(OrderMan, Info,
|
||||
"ServiceBridge ExchangePositionEvent callback sz: {}",
|
||||
u.events->size());
|
||||
for (const auto &ev : *(u.events)) {
|
||||
LOG(OrderMan, Info,
|
||||
"ServiceBridge received ExchangePositionEvent n_pos: {}",
|
||||
ev.position.total_exchange_positions.size());
|
||||
me->on_exchange_position(ev.position);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
me->activate_order_pub = make_stream<ActivateOrderEvent>();
|
||||
me->update_order_pub = make_stream<UpdateOrderEvent>();
|
||||
@@ -103,7 +131,7 @@ void ServiceBridge::init() {
|
||||
me->filled_position_pub = make_stream<FilledPositionEvent>();
|
||||
me->excess_liquidity_pub = make_stream<ExcessLiquidityUpdateEvent>();
|
||||
me->ready.set_value();
|
||||
}
|
||||
} // namespace orderman
|
||||
|
||||
void ServiceBridge::on(mercury::Update<StoredFillEvent> const &update) {
|
||||
if (update.events) {
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/mercury/events/Update.h"
|
||||
#include "lib/orderman/events/ExchangePositionEvent.h"
|
||||
#include "lib/orderman/orderman_utils/ExchangePosition.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
// fwds
|
||||
@@ -38,6 +42,7 @@ class OrderManagerReadyEvent;
|
||||
class NewAdminDataEvent;
|
||||
class OrderOpResultEvent;
|
||||
class DynamicOrderRegistry;
|
||||
class ExchangePositionEvent;
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
// end fwds
|
||||
@@ -49,21 +54,23 @@ namespace orderman {
|
||||
|
||||
class ServiceBridge : public mercury::Actor {
|
||||
public:
|
||||
template <class EV> using OnEv = std::function<void(EV const &)>;
|
||||
template <class EV>
|
||||
using OnEv = std::function<void(EV const &)>;
|
||||
|
||||
using OnReady = std::function<void()>;
|
||||
using OnOrders =
|
||||
std::function<void(std::vector<api::orderman::OrderRecord> const &)>;
|
||||
using OnFills =
|
||||
std::function<void(std::vector<api::orderman::Fill> const &)>;
|
||||
|
||||
using OnOrderOpResult = std::function<void(OrderOpResultEvent const &)>;
|
||||
using OnExchangePosition = std::function<void(const ExchangePosition &)>;
|
||||
|
||||
ServiceBridge(
|
||||
OnReady const &,
|
||||
OnOrders const &,
|
||||
OnFills const &,
|
||||
OnOrderOpResult const &,
|
||||
OnExchangePosition const &,
|
||||
DynamicOrderRegistry const &,
|
||||
mercury::BrokerProxy &service_call_marshaller,
|
||||
md::SecurityOracle o);
|
||||
@@ -79,8 +86,8 @@ class ServiceBridge : public mercury::Actor {
|
||||
void cancel_order(uint32_t rid, api::orderman::Cancel const &c);
|
||||
void detach_order(uint32_t rid, api::orderman::Detach const &c);
|
||||
|
||||
void
|
||||
update_admin_data(std::shared_ptr<api::admin::AdminData const> const &admin);
|
||||
void update_admin_data(
|
||||
std::shared_ptr<api::admin::AdminData const> const &admin);
|
||||
void update_account_pnl(api::position::Pnl_account_dataUpdate const &);
|
||||
void update_position(api::position::Position_dataUpdate const &);
|
||||
void update_excess_liquidity_report(
|
||||
@@ -97,6 +104,7 @@ class ServiceBridge : public mercury::Actor {
|
||||
void on(mercury::Update<OrderManagerReadyEvent> const &);
|
||||
void on(mercury::Update<NewAdminDataEvent> const &);
|
||||
void on(mercury::Update<OrderOpResultEvent> const &);
|
||||
// void on(mercury::Update<ExchangePositionEvent> const &);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
#include "OrderManager.h"
|
||||
|
||||
#include "lib/jetfix/common/OutFIX.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/mercury/events/TimerEvent.h"
|
||||
#include "lib/orderman/OrderServices.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderServicesData.h"
|
||||
#include "lib/orderman/events/AccountPnLUpdateEvent.h"
|
||||
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
|
||||
#include "lib/orderman/events/ExchangePositionEvent.h"
|
||||
#include "lib/orderman/events/FilledPositionEvent.h"
|
||||
#include "lib/orderman/events/NewAdminDataEvent.h"
|
||||
#include "lib/orderman/events/NewSecuritiesEvent.h"
|
||||
#include "lib/orderman/events/OrderManagerReadyEvent.h"
|
||||
#include "lib/orderman/events/StoredOrderEvent.h"
|
||||
#include "lib/orderman/gateways/IExecutionGateway.h"
|
||||
#include "lib/orderman/order_factory/OrderFactory.h"
|
||||
#include "lib/orderman/orderman_utils/ExchangePosition.h"
|
||||
#include "lib/orderman/orders/Order.h"
|
||||
#include "lib/orderman/securities/ISecurityDB.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/inplace_function.h"
|
||||
#include "lib/utils/thread_manager.h"
|
||||
|
||||
@@ -55,6 +60,8 @@ struct OrderManager::PImpl {
|
||||
OrderManager::OrderManager(
|
||||
DynamicOrderRegistry const &b, trace::PerfLog &l, md::SecurityOracle o)
|
||||
: me(new PImpl(*this, b, l, o)) {
|
||||
LOG(OrderMan, Info, "OrderManager cons t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
auto id_gen = &me->services_data.id_gen;
|
||||
auto done = &me->shutdown;
|
||||
me->background_thread =
|
||||
@@ -398,8 +405,8 @@ void OrderManager::on_timer(const mercury::Update<mercury::TimerEvent> &m) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<jetfix::OutFIXPtr> &
|
||||
OrderManager::free_buffers(std::string const &session_name) {
|
||||
std::vector<jetfix::OutFIXPtr> &OrderManager::free_buffers(
|
||||
std::string const &session_name) {
|
||||
auto &s = me->services_data.get_session(session_name);
|
||||
return s.free_buffers;
|
||||
}
|
||||
@@ -477,6 +484,15 @@ void OrderManager::init_order_services() {
|
||||
s->gw->on_gw_status_change() = [s_ptr, this, gw_name](bool b) {
|
||||
publish(s_ptr->gw_status_change_pub, gw_name, b);
|
||||
};
|
||||
s->exchange_position_pub = make_stream<ExchangePositionEvent>();
|
||||
s->gw->on_exchange_position_state() =
|
||||
[s_ptr, this](const ExchangePosition &exch_pos) {
|
||||
// bts_assert(s_ptr != nullptr);
|
||||
LOG(OrderMan, Info,
|
||||
"OrderManager on_exchange_position_state cb n_pos: {}",
|
||||
exch_pos.total_exchange_positions.size());
|
||||
publish(s_ptr->exchange_position_pub, exch_pos);
|
||||
};
|
||||
s->cancel_reject_pub = make_stream<CancelRejectEvent>(gw_name);
|
||||
s->gw->on_cancel_reject() = [s_ptr, this](auto const &cr) {
|
||||
publish(s_ptr->cancel_reject_pub, cr);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "lib/orderman/events/CreateOrderReplyEvent.h"
|
||||
#include "lib/orderman/events/CreateOrderRequestEvent.h"
|
||||
#include "lib/orderman/events/DetachOrderEvent.h"
|
||||
#include "lib/orderman/events/ExchangePositionEvent.h"
|
||||
#include "lib/orderman/events/GatewayStatusChangeEvent.h"
|
||||
#include "lib/orderman/events/MDRequestEvent.h"
|
||||
#include "lib/orderman/events/NewExecutionReportEvent.h"
|
||||
@@ -83,6 +84,7 @@ struct SessionServicesData {
|
||||
mercury::Stream<NewExecutionReportEvent> exe_report_pub;
|
||||
mercury::Stream<GatewayStatusChangeEvent> gw_status_change_pub;
|
||||
mercury::Stream<CancelRejectEvent> cancel_reject_pub;
|
||||
mercury::Stream<ExchangePositionEvent> exchange_position_pub;
|
||||
};
|
||||
|
||||
class OrderServicesData {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/api/services/AdminService.pb.h"
|
||||
|
||||
#include "lib/mercury/common/mercury_common.h"
|
||||
#include "lib/mercury/events/Event.h"
|
||||
#include "lib/mercury/synopsis/CacheLast.h"
|
||||
#include "lib/orderman/orderman_utils/ExchangePosition.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
class ExchangePositionEvent : public mercury::Event<ExchangePositionEvent> {
|
||||
public:
|
||||
using SynopsisPolicy = mercury::CacheLast;
|
||||
ExchangePosition position;
|
||||
ExchangePositionEvent(const ExchangePosition &position_arg)
|
||||
: position(position_arg){};
|
||||
};
|
||||
|
||||
} // namespace bts::orderman
|
||||
@@ -13,8 +13,10 @@
|
||||
#include "lib/orderman/events/NewAdminDataEvent.h"
|
||||
#include "lib/orderman/events/NewExecutionReportEvent.h"
|
||||
#include "lib/orderman/events/NewSecuritiesEvent.h"
|
||||
#include "lib/orderman/orderman_utils/ExchangePosition.h"
|
||||
#include "lib/orderman/orderman_utils/ExecutionReport.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/tracing/bts_trace.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
@@ -84,6 +86,7 @@ struct EMExecutionGateway::PImpl {
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
OnCancelReject on_cancel_reject;
|
||||
OnExchangePositionState on_exchange_position_state;
|
||||
api::admin::AdminData admin_data;
|
||||
TimeStamp connection_time;
|
||||
md::SecurityOracle sec_oracle;
|
||||
@@ -96,10 +99,13 @@ struct EMExecutionGateway::PImpl {
|
||||
// bts key to em keys
|
||||
std::unordered_map<OrderKey, int64_t> key_map = {};
|
||||
std::unordered_map<int64_t, FillState> fill_map = {};
|
||||
ExchangePosition exchange_position;
|
||||
tbb::concurrent_queue<EMCallbackMsg> em_cb_queue =
|
||||
tbb::concurrent_queue<EMCallbackMsg>();
|
||||
tbb::concurrent_queue<EMExchangePositionCallbackMsg> exch_pos_queue =
|
||||
tbb::concurrent_queue<EMExchangePositionCallbackMsg>();
|
||||
bts::datetime::PTime last_pos_fire_time = bts::datetime::now();
|
||||
uint32_t pos_fire_period_ms = 5000;
|
||||
};
|
||||
|
||||
api::orderman::NativeOrderStatus native_order_status(
|
||||
@@ -141,15 +147,18 @@ std::string get_exchange_oid(const emumba::order_entry::order_state &state) {
|
||||
|
||||
EMExecutionGateway::EMExecutionGateway(md::SecurityOracle o)
|
||||
: IExecutionGateway(), me(new PImpl(o)) {
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::EMExecutionGateway constructor");
|
||||
LOG(OrderMan, Info,
|
||||
"EMExecutionGateway::EMExecutionGateway constructor t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_application_name());
|
||||
}
|
||||
|
||||
EMExecutionGateway::~EMExecutionGateway() {}
|
||||
|
||||
void EMExecutionGateway::start() {
|
||||
_init();
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::start order_mux aquired: {}",
|
||||
me->order_mux != nullptr);
|
||||
LOG(OrderMan, Info,
|
||||
"EMExecutionGateway::start order_mux aquired: {} t_id: {} t_name: {}",
|
||||
me->order_mux != nullptr, os::get_thread_id(), os::get_thread_name());
|
||||
}
|
||||
|
||||
// this is a periodic timer
|
||||
@@ -163,16 +172,19 @@ void EMExecutionGateway::dispatch_incoming_fix_messages() {
|
||||
cb_msg.order_key.value());
|
||||
_process_cb_and_fire_er(cb_msg);
|
||||
}
|
||||
_test_pos_cb();
|
||||
}
|
||||
|
||||
void EMExecutionGateway::on_securities(
|
||||
const mercury::Update<NewSecuritiesEvent> &) {
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::on_securities");
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::on_securities t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
}
|
||||
|
||||
void EMExecutionGateway::on_admin_data(
|
||||
const mercury::Update<NewAdminDataEvent> &update) {
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::on_admin_data");
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::on_admin_data t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
if (update.events) {
|
||||
for (auto const &ev : *(update.events))
|
||||
me->admin_data.CopyFrom(*ev.admin_data);
|
||||
@@ -215,6 +227,9 @@ OnGwStatusChange &EMExecutionGateway::on_gw_status_change() {
|
||||
OnCancelReject &EMExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
OnExchangePositionState &EMExecutionGateway::on_exchange_position_state() {
|
||||
return me->on_exchange_position_state;
|
||||
}
|
||||
|
||||
bool EMExecutionGateway::_init() {
|
||||
if (me->order_mux == nullptr) {
|
||||
@@ -239,7 +254,6 @@ bool EMExecutionGateway::_init() {
|
||||
pos_cb.positions.push_back(*p_ptr);
|
||||
me->exch_pos_queue.push(pos_cb);
|
||||
};
|
||||
me->order_mux->get_positions();
|
||||
}
|
||||
}
|
||||
return me->order_mux != nullptr;
|
||||
@@ -377,5 +391,28 @@ void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) {
|
||||
me->on_exe_report(er, {});
|
||||
}
|
||||
|
||||
void EMExecutionGateway::_test_pos_cb() {
|
||||
if (me->order_mux == nullptr)
|
||||
return;
|
||||
auto msecs = bts::datetime::msecs_since(me->last_pos_fire_time);
|
||||
if (msecs < me->pos_fire_period_ms) {
|
||||
return;
|
||||
}
|
||||
me->last_pos_fire_time = bts::datetime::now();
|
||||
// make some thing up and publish
|
||||
if (me->exchange_position.total_exchange_positions.empty()) {
|
||||
me->exchange_position.exchange = bts::api::VENUE_DERIBIT;
|
||||
ExchangePosition::UnitPosition u = {};
|
||||
u.security = nullptr;
|
||||
u.position = 1.0;
|
||||
u.avg_filled_price = Price(20.0);
|
||||
u.exchange_sec_desc = "xyz";
|
||||
for (int i = 0; i < 10; i++) {
|
||||
me->exchange_position.total_exchange_positions.push_back(u);
|
||||
}
|
||||
}
|
||||
me->on_exchange_position_state(me->exchange_position);
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -36,6 +36,7 @@ class EMExecutionGateway : public IExecutionGateway {
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
OnExchangePositionState &on_exchange_position_state() override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
@@ -47,6 +48,8 @@ class EMExecutionGateway : public IExecutionGateway {
|
||||
void _send_cxl_replace(const CancelReplaceOrderMsg &);
|
||||
void _send_cxl(const CancelOrderMsg &);
|
||||
void _process_cb_and_fire_er(const EMCallbackMsg &);
|
||||
// temp
|
||||
void _test_pos_cb();
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -46,6 +46,7 @@ struct FakeExecutionGateway::PImpl {
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
OnCancelReject on_cancel_reject;
|
||||
orderman::OnExchangePositionState on_exchange_position_state;
|
||||
api::admin::AdminData admin_data;
|
||||
TimeStamp connection_time;
|
||||
md::SecurityOracle sec_oracle;
|
||||
@@ -185,6 +186,9 @@ OnGwStatusChange &FakeExecutionGateway::on_gw_status_change() {
|
||||
OnCancelReject &FakeExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
OnExchangePositionState &FakeExecutionGateway::on_exchange_position_state() {
|
||||
return me->on_exchange_position_state;
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -22,6 +22,7 @@ class FakeExecutionGateway : public IExecutionGateway {
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
OnExchangePositionState &on_exchange_position_state() override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
|
||||
@@ -46,6 +46,7 @@ struct GLBXExecutionGateway::PImpl {
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
OnCancelReject on_cancel_reject;
|
||||
orderman::OnExchangePositionState on_exchange_position_state;
|
||||
trace::PerfLog &perf_log;
|
||||
md::SecurityOracle sec_oracle;
|
||||
};
|
||||
@@ -117,6 +118,10 @@ OnCancelReject &GLBXExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
|
||||
OnExchangePositionState &GLBXExecutionGateway::on_exchange_position_state() {
|
||||
return me->on_exchange_position_state;
|
||||
}
|
||||
|
||||
void GLBXExecutionGateway::on_exe_report(
|
||||
const jetfix::fix::ExecutionReportMsg &msg) {
|
||||
OrderKey ok;
|
||||
|
||||
@@ -26,6 +26,7 @@ class GLBXExecutionGateway : public IExecutionGateway {
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
OnExchangePositionState &on_exchange_position_state() override;
|
||||
|
||||
private:
|
||||
BTS_NO_COPY(GLBXExecutionGateway);
|
||||
|
||||
@@ -56,6 +56,7 @@ struct GLBXiLink3ExecutionGateway::PImpl {
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
orderman::OnCancelReject on_cancel_reject;
|
||||
orderman::OnExchangePositionState on_exchange_position_state;
|
||||
trace::PerfLog &perf_log;
|
||||
IL3SecDB db;
|
||||
GatewayName gw_name;
|
||||
@@ -295,6 +296,11 @@ orderman::OnCancelReject &GLBXiLink3ExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
|
||||
orderman::OnExchangePositionState &
|
||||
GLBXiLink3ExecutionGateway::on_exchange_position_state() {
|
||||
return me->on_exchange_position_state;
|
||||
}
|
||||
|
||||
log::CharPtrWrapper GLBXiLink3ExecutionGateway::state_name(State st) {
|
||||
switch (st) {
|
||||
case State::WAITING_FOR_SECURITIES:
|
||||
|
||||
@@ -32,6 +32,7 @@ class GLBXiLink3ExecutionGateway : public IExecutionGateway {
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
orderman::OnExchangePositionState &on_exchange_position_state() override;
|
||||
|
||||
private:
|
||||
enum class State;
|
||||
|
||||
@@ -54,6 +54,7 @@ struct ICEExecutionGateway::PImpl {
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
OnCancelReject on_cancel_reject;
|
||||
orderman::OnExchangePositionState on_exchange_position_state;
|
||||
trace::PerfLog &perf_log;
|
||||
api::admin::AdminData admin_data;
|
||||
std::atomic<int> nusers;
|
||||
@@ -267,6 +268,10 @@ OnCancelReject &ICEExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
|
||||
OnExchangePositionState &ICEExecutionGateway::on_exchange_position_state() {
|
||||
return me->on_exchange_position_state;
|
||||
}
|
||||
|
||||
bool ICEExecutionGateway::process_memo(
|
||||
const jetfix::fix::ICEExecutionReportMsg &msg,
|
||||
OrderKey *ok,
|
||||
|
||||
@@ -26,6 +26,7 @@ class ICEExecutionGateway : public IExecutionGateway {
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
OnExchangePositionState &on_exchange_position_state() override;
|
||||
|
||||
private:
|
||||
BTS_NO_COPY(ICEExecutionGateway);
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
#include "lib/mercury/events/Update.h"
|
||||
#include "lib/orderman/OrderMsg.h"
|
||||
#include "lib/orderman/orderman_utils/ExchangePosition.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/utils/bts_no_copy.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
@@ -28,6 +30,7 @@ using OnGwStatusChange = std::function<void(bool)>;
|
||||
using OnExeReport =
|
||||
std::function<void(ExecutionReport const &, trace::CorID const &)>;
|
||||
using OnCancelReject = std::function<void(CancelReject const &)>;
|
||||
using OnExchangePositionState = std::function<void(ExchangePosition const &)>;
|
||||
|
||||
// fix execution gateway for a single FIX session
|
||||
class IExecutionGateway {
|
||||
@@ -44,6 +47,7 @@ class IExecutionGateway {
|
||||
virtual OnExeReport &on_exe_report() = 0;
|
||||
virtual OnGwStatusChange &on_gw_status_change() = 0;
|
||||
virtual OnCancelReject &on_cancel_reject() = 0;
|
||||
virtual OnExchangePositionState &on_exchange_position_state() = 0;
|
||||
|
||||
private:
|
||||
BTS_NO_COPY(IExecutionGateway);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/mercury/common/mercury_common.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/utils/overloaded.h"
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
class ExchangePosition {
|
||||
public:
|
||||
class UnitPosition {
|
||||
public:
|
||||
std::string exchange_sec_desc;
|
||||
api::Security const *security;
|
||||
Quantity position;
|
||||
Price avg_filled_price;
|
||||
};
|
||||
api::Venue exchange;
|
||||
std::vector<UnitPosition> total_exchange_positions;
|
||||
};
|
||||
} // namespace bts::orderman
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "lib/orderman/orders/glbx/iLink2OrderEncoder.h"
|
||||
#include "lib/orderman/orders/glbx/iLink3OrderEncoder.h"
|
||||
#include "lib/orderman/securities/ISecurityDB.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
@@ -100,7 +101,10 @@ struct EMNativeOrder::PImpl {
|
||||
RoutingRecord routing_record;
|
||||
};
|
||||
|
||||
EMNativeOrder::EMNativeOrder() : me(new PImpl()) {}
|
||||
EMNativeOrder::EMNativeOrder() : me(new PImpl()) {
|
||||
LOG(OrderMan, Info, "EMNativeOrder::EMNativeOrder t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_application_name());
|
||||
}
|
||||
|
||||
EMNativeOrder::~EMNativeOrder() {}
|
||||
|
||||
@@ -174,6 +178,9 @@ void EMNativeOrder::on_init_recovered(
|
||||
me->state = rec.state();
|
||||
me->sec = serv.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
me->previous_working_position = Quantity(0);
|
||||
LOG(OrderMan, Info,
|
||||
"EMNativeOrder::on_init_recovered key: {} t_id: {} t_name: {}", key(),
|
||||
os::get_thread_id(), os::get_application_name());
|
||||
transition(
|
||||
OrderStatus::ORDER_STATUS_ERROR, "Recovered Orders are not handled");
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ struct EmMDListener::PImpl {
|
||||
bool active_get_pos_call = false;
|
||||
bool active_get_open_orders_call = false;
|
||||
std::unordered_map<int64_t, emumba::order_entry::order_state>
|
||||
order_state_map = {};
|
||||
order_state_map = {};
|
||||
explicit PImpl(EmumbaSecurityIndex &index_a, MDProducer &md_producer_a)
|
||||
: index(index_a), md_producer(md_producer_a) {}
|
||||
};
|
||||
|
||||
@@ -72,8 +72,8 @@ struct EmumbaMain::PImpl {
|
||||
};
|
||||
|
||||
EmumbaMain::EmumbaMain() : me(std::make_unique<PImpl>()) {
|
||||
LOG(md, Info, "EmumbaMain::EmumbaMain constructed on t_id:{}",
|
||||
os::get_thread_id());
|
||||
LOG(md, Info, "EmumbaMain::EmumbaMain constructed on t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
}
|
||||
|
||||
EmumbaMain::~EmumbaMain() {}
|
||||
|
||||
Reference in new issue
Block a user