Deribit's option position request hooked up

This commit is contained in:
Taha Afzal committed 2023-06-06 18:30:38 +00:00
1 parent 4769f66eea
commit 6d95a645e3
8 files changed
+295 -23

No files matched your search

@@ -81,8 +81,7 @@ api::orderman::NativeOrderStatus native_order_status(const CCAPIOrderState &s) {
}
struct CCAPIExecutionGateway::PImpl {
PImpl(md::SecurityOracle o)
: sec_oracle(o), order_mux(new CCAPIDeribitOrderMux(o)) {
PImpl(md::SecurityOracle o) : sec_oracle(o) {
LOG(OrderMan, Info, "CCAPIExecutionGateway::PImpl constructor");
}
admin::AdminServiceUtils::ExchangeSubAccountResolver subaccount_resolver =
@@ -97,7 +96,7 @@ struct CCAPIExecutionGateway::PImpl {
OnExchangePositionState on_exchange_position_state;
OnExchangeOpenOrdersState on_exchange_open_orders;
// orders are sent out and callbacks received via IEMOrderMuxer
ICCAPIOrderMux *order_mux;
ICCAPIOrderMux *order_mux = nullptr;
size_t msg_seq_num = 0;
boost::object_pool<ExecutionReport> exe_report_pool;
std::unordered_map<OrderKey, CreateOrderMsg> order_map = {};
@@ -108,6 +107,7 @@ struct CCAPIExecutionGateway::PImpl {
bts::datetime::PTime last_pos_fire_time = bts::datetime::now();
uint32_t pos_fire_period_ms = 5000;
size_t dispatch_idx = 0;
bool inited() const { return order_mux != nullptr; }
};
CCAPIExecutionGateway::CCAPIExecutionGateway(md::SecurityOracle o)
@@ -130,6 +130,8 @@ void CCAPIExecutionGateway::start() {
// this is a periodic timer
void CCAPIExecutionGateway::dispatch_incoming_fix_messages() {
if (!me->inited())
return;
me->order_mux->dispatch_incoming_messages();
}
@@ -139,6 +141,8 @@ void CCAPIExecutionGateway::on_securities(
"CCAPIExecutionGateway::on_securities t_id: {} t_name: {} n_secs: {}",
os::get_thread_id(), os::get_thread_name(),
update.events == nullptr ? 0 : update.events->size());
if (!me->inited())
return;
me->order_mux->on_securities(update);
}
@@ -159,6 +163,8 @@ void CCAPIExecutionGateway::send_fix(const jetfix::OutFIXPtr &, trace::CorID) {
void CCAPIExecutionGateway::send_msgs(
std::vector<OrderMsg> const &msg_vec, trace::CorID) {
if (!me->inited())
return;
LOG(OrderMan, Info, "CCAPIExecutionGateway::send_msgs count: {}",
msg_vec.size());
for (const auto &m : msg_vec) {
@@ -215,10 +221,37 @@ OnExchangeOpenOrdersState &CCAPIExecutionGateway::on_exchange_open_orders() {
}
void CCAPIExecutionGateway::_init() {
if (me->order_mux != nullptr)
return;
LOG(OrderMan, Info, "CCAPIExecutionGateway::_init");
me->order_mux = new CCAPIDeribitOrderMux(me->sec_oracle);
me->order_mux->order_update_cb() =
[this](const CCAPIOrderState &order_state) {
_on_order_cb(order_state);
};
me->order_mux
->exchange_position_update_cb() = [this](const std::vector<CCAPIPosition>
&pos_vec) {
LOG(OrderMan, Info, "CCAPIExecutionGateway position cb sz: {}",
pos_vec.size());
ExchangePosition out_pos = {api::Venue::VENUE_DERIBIT, {}};
for (const CCAPIPosition &pos : pos_vec) {
auto sec_ptr = _find_sec(pos.venue, pos.exchange_sec_desc);
if (sec_ptr != nullptr) {
out_pos.total_exchange_positions.push_back(
ExchangePosition::UnitPosition{
pos.exchange_sec_desc, sec_ptr, "MAIN", 9, pos.position,
Price{pos.average_price}});
} else {
LOG(OrderMan, Error,
"CCAPIExecutionGateway could not resolve exchange: {} desc: {}",
api::Venue_Name(pos.venue), pos.exchange_sec_desc);
}
}
LOG(OrderMan, Info, "CCAPIExecutionGateway firing positions sz: {}",
out_pos.total_exchange_positions.size());
me->on_exchange_position_state(out_pos);
};
}
void CCAPIExecutionGateway::_on_order_cb(const CCAPIOrderState &s) {
@@ -287,4 +320,18 @@ void CCAPIExecutionGateway::_on_order_cb(const CCAPIOrderState &s) {
// _fire_leg_er(em_cb, er);
}
api::Security const *CCAPIExecutionGateway::_find_sec(
// TODO
api::Venue venue,
const std::string &exchange_security_desc) {
for (auto p : me->sec_oracle.get_securities()) {
if (p->exchange() == venue) {
bts_assert(venue == api::VENUE_DERIBIT);
if (p->deribit().security_desc() == exchange_security_desc)
return p;
}
}
return nullptr;
}
} // namespace bts::orderman