Modfified IEMOrderMux interface
This commit is contained in:
1 parent
b2640d2203
commit
f650ff3ccf
3 files changed
+16
-39
No files matched your search
@@ -47,7 +47,7 @@ struct EMCallbackMsg {
|
||||
// didnt make it const since tbb::queue needs a copy cons
|
||||
emumba::deribit_connector::data_types::error ec;
|
||||
emumba::order_entry::order_key order_key;
|
||||
emumba::order_entry::order_state order_state;
|
||||
EMOrderState order_state;
|
||||
};
|
||||
|
||||
// Position callbacks from order_mux are copied here and placed in the tbb queue
|
||||
@@ -55,22 +55,6 @@ struct EMExchangePositionCallbackMsg {
|
||||
std::vector<emumba::order_entry::position> positions;
|
||||
};
|
||||
|
||||
struct FillState {
|
||||
double avg_fill_price = 0.0;
|
||||
double total_fills = 0.0;
|
||||
bool has_new_fills(double new_total_fills) const {
|
||||
return std::abs(total_fills - new_total_fills) > 0.0000001;
|
||||
}
|
||||
std::tuple<double, double> latest_fills(
|
||||
double new_avg_fill_price, double new_total_fills) {
|
||||
double last_fills = new_total_fills - total_fills;
|
||||
double last_fill_price = (new_total_fills * new_avg_fill_price) -
|
||||
(total_fills * avg_fill_price);
|
||||
last_fill_price /= last_fills;
|
||||
return {last_fill_price, last_fills};
|
||||
}
|
||||
};
|
||||
|
||||
struct EMExecutionGateway::PImpl {
|
||||
PImpl(md::SecurityOracle o) : sec_oracle(o) {
|
||||
LOG(OrderMan, Info, "EMExecutionGateway::PImpl constructor");
|
||||
@@ -93,7 +77,6 @@ struct EMExecutionGateway::PImpl {
|
||||
// that we need to build and fire the ExecutionReport (data that is not
|
||||
// provided by the EM order callback)
|
||||
std::unordered_map<EMOrderKey, CreateOrderMsg> order_map = {};
|
||||
std::unordered_map<int64_t, FillState> fill_map = {};
|
||||
// this is updated as we get exchange positions
|
||||
ExchangePosition exchange_position;
|
||||
// since we get callbacks from IEMOrderMuxer in a different thread we queue
|
||||
@@ -111,8 +94,8 @@ struct EMExecutionGateway::PImpl {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
api::orderman::NativeOrderStatus native_order_status(
|
||||
const emumba::order_entry::order_state &state) {
|
||||
switch (state.order_status) {
|
||||
const EMOrderState &state) {
|
||||
switch (state.status) {
|
||||
case emumba::order_entry::status::working:
|
||||
// TODO: check partially filled
|
||||
return api::orderman::NativeOrderStatus::NATIVE_ORDER_STATUS_NEW;
|
||||
@@ -404,31 +387,24 @@ void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) {
|
||||
er.order_status = native_order_status(em_cb.order_state);
|
||||
er.manual_order_indicator =
|
||||
api::orderman::ManualOrderIndicator::MANUAL_ORDER_INDICATOR_NO;
|
||||
std::string exch_oid = get_exchange_oid(em_cb.order_state);
|
||||
std::string exch_oid = std::to_string(em_cb.order_key.value());
|
||||
// TODO, should we put EM order or Deribit ?
|
||||
// (this is not used by EMNativeOrder so we are ok)
|
||||
auto &er_exch_oid = std::get<ExchangeOrderID>(er.exchange_order_id).value();
|
||||
to_array(exch_oid, &er_exch_oid);
|
||||
er.price.value() = em_cb.order_state.px.to_double(); // cr_msg.price;
|
||||
er.quantity = get_quantity(em_cb.order_state.qty);
|
||||
er.price.value() = em_cb.order_state.order_px;
|
||||
er.quantity = em_cb.order_state.order_qty;
|
||||
// fractional qty
|
||||
// fills
|
||||
FillState &fill_state = me->fill_map[key];
|
||||
double avg_fill_price = em_cb.order_state.avg_price.to_double();
|
||||
double total_fills = get_quantity(em_cb.order_state.total_fills);
|
||||
er.avg_price = Price(avg_fill_price);
|
||||
er.filled_quantity = total_fills;
|
||||
if (fill_state.has_new_fills(total_fills)) {
|
||||
er.avg_price.value() = em_cb.order_state.avg_filled_price;
|
||||
er.filled_quantity = em_cb.order_state.total_fills;
|
||||
if (!em_cb.order_state.trades.empty()) {
|
||||
er.exec_type = api::orderman::ExecType::EXEC_TYPE_PARTIAL_FILL;
|
||||
if (em_cb.order_state.order_status ==
|
||||
emumba::order_entry::status::completed) {
|
||||
if (em_cb.order_state.status == emumba::order_entry::status::completed) {
|
||||
er.exec_type = api::orderman::ExecType::EXEC_TYPE_FILL;
|
||||
}
|
||||
auto [last_price, last_shares] =
|
||||
fill_state.latest_fills(avg_fill_price, total_fills);
|
||||
er.last_price = Price(last_price);
|
||||
er.last_shares = Quantity(last_shares);
|
||||
fill_state = {avg_fill_price, total_fills};
|
||||
er.last_price = Price(em_cb.order_state.last_filled_price);
|
||||
er.last_shares = Quantity(em_cb.order_state.last_filled_qty);
|
||||
// TODO: this should be part of the update
|
||||
utils::Uuid guid;
|
||||
std::string fill_id = guid.to_text_string();
|
||||
|
||||
@@ -349,8 +349,8 @@ void EmMDListener::on_order_update(
|
||||
t->trade_price.to_double(), t->trade_quantity, t->exchange_order_id);
|
||||
}
|
||||
auto &ex_ord_state = me->order_state_map[order_key.value()];
|
||||
auto order_state_subsumed = ex_ord_state.update(order_state);
|
||||
me->order_update_cb(ec, order_key, order_state_subsumed);
|
||||
ex_ord_state.update(order_state);
|
||||
me->order_update_cb(ec, order_key, ex_ord_state);
|
||||
}
|
||||
|
||||
void EmMDListener::on_get_all_positions(
|
||||
|
||||
@@ -32,6 +32,7 @@ struct EMOrderState {
|
||||
const emumba::order_entry::order_state &o_state) {
|
||||
using namespace emumba::market_data;
|
||||
using namespace emumba::order_entry;
|
||||
status = o_state.order_status;
|
||||
last_filled_qty = 0;
|
||||
last_filled_price = 0;
|
||||
trades.clear();
|
||||
@@ -62,7 +63,7 @@ struct EMOrderState {
|
||||
using OnEMOrderUpdate = std::function<void(
|
||||
const emumba::deribit_connector::data_types::error &,
|
||||
const emumba::order_entry::order_key &,
|
||||
const emumba::order_entry::order_state &)>;
|
||||
const EMOrderState &)>;
|
||||
|
||||
using OnEMExchangePositionUpdate = std::function<void(
|
||||
const std::vector<emumba::order_entry::position const *> &)>;
|
||||
|
||||
Reference in new issue
Block a user