ServiceBridge now periodically publishes the TheoEvent (with a flag indicating such). This helps the algos get the theos without waiting for the next update
This commit is contained in:
1 parent
1e0ac46e07
commit
29eef77099
7 files changed
+52
-12
No files matched your search
@@ -128,8 +128,8 @@ struct OrderServiceServer::PImpl {
|
||||
DynamicOrderRegistry const &d,
|
||||
metrics::MetricsContainer &stats,
|
||||
trace::PerfLog &log)
|
||||
: service_bridge(), service_ready(false), known_orders(), known_fills(),
|
||||
publish_orders(), publish_fills(),
|
||||
: context(ctx), service_bridge(), service_ready(false), known_orders(),
|
||||
known_fills(), publish_orders(), publish_fills(),
|
||||
exchange_pos_publisher(exchange_pos_publisher),
|
||||
open_orders_publisher(open_orders_publisher),
|
||||
admin_service(ctx.locate<api::admin::AdminService>()),
|
||||
@@ -139,6 +139,7 @@ struct OrderServiceServer::PImpl {
|
||||
dyn_order_registry(d), log(log), in_flight_order_ops(),
|
||||
current_req_op_id(0) {}
|
||||
|
||||
bts::api::ServiceContext &context;
|
||||
ServiceBridge *service_bridge;
|
||||
|
||||
std::vector<std::unique_ptr<ActorThread>> actor_threads;
|
||||
@@ -323,6 +324,11 @@ OrderServiceServer::OrderServiceServer(
|
||||
[this](auto const &update) {
|
||||
me->service_bridge->update_excess_liquidity_report(update);
|
||||
});
|
||||
// We wait long enough for the server to be fully ready. This is not great,
|
||||
// we should watch for some signal but right now I am not sure if such a
|
||||
// signal exist. We cant do it too early either or some other problem
|
||||
// happens. We will come to this later and fix it
|
||||
me->context.post([this]() { _do_work(); }, 300000);
|
||||
}
|
||||
|
||||
OrderServiceServer::~OrderServiceServer() {
|
||||
@@ -589,5 +595,10 @@ void OrderServiceServer::_on_exchange_open_orders(
|
||||
me->open_orders_publisher.flush();
|
||||
}
|
||||
|
||||
void OrderServiceServer::_do_work() {
|
||||
me->service_bridge->do_work();
|
||||
me->context.post([this]() { _do_work(); }, 500);
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -68,6 +68,7 @@ class OrderServiceServer : public api::orderman::OrderServiceBase {
|
||||
void on_order_op_result(OrderOpResultEvent const &);
|
||||
void _on_exchange_position(const ExchangePositionEvent &);
|
||||
void _on_exchange_open_orders(const ExchangeOpenOrdersEvent &);
|
||||
void _do_work();
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -83,6 +83,7 @@ struct ServiceBridge::PImpl {
|
||||
mercury::BrokerProxy &service_call_marshaller;
|
||||
std::promise<void> ready;
|
||||
bts::orderman::analytics::TheoCalculator theo_calculator = {};
|
||||
bool theos_set = false;
|
||||
};
|
||||
|
||||
ServiceBridge::ServiceBridge(
|
||||
@@ -356,13 +357,27 @@ void ServiceBridge::update_excess_liquidity_report(
|
||||
// updates the calculator and publishes the event (with a pointer to it)
|
||||
void ServiceBridge::set_precomputed_theos(
|
||||
const bts::api::orderman::PrecomputedTheos &precomputed_theos) {
|
||||
LOG(Gen, Info, "ServiceBridge::update_theos size: {}",
|
||||
precomputed_theos.theos_size());
|
||||
LOG(Gen, Info, "ServiceBridge::update_theos size: {} t_id: {} t_name: {}",
|
||||
precomputed_theos.theos_size(), os::get_thread_id(),
|
||||
os::get_thread_name());
|
||||
me->theo_calculator.set_data(precomputed_theos);
|
||||
me->service_call_marshaller.schedule_action([this]() {
|
||||
bts::orderman::analytics::ITheoCalculator const *theo_calc_ptr =
|
||||
&(me->theo_calculator);
|
||||
publish(me->theo_pub, theo_calc_ptr);
|
||||
publish(
|
||||
me->theo_pub, analytics::ITheoCalculator::Impetus::DATA,
|
||||
&(me->theo_calculator));
|
||||
me->theos_set = true;
|
||||
});
|
||||
}
|
||||
|
||||
void ServiceBridge::do_work() {
|
||||
LOG(Gen, Diag, "ServiceBridge::do_work t_id: {} t_name: {}",
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
if (!me->theos_set)
|
||||
return;
|
||||
me->service_call_marshaller.schedule_action([this]() {
|
||||
publish(
|
||||
me->theo_pub, analytics::ITheoCalculator::Impetus::PERIODIC_LATEJOIN,
|
||||
&(me->theo_calculator));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ class ServiceBridge : public mercury::Actor {
|
||||
api::position::Excess_liquidity_reportUpdate const &);
|
||||
void set_precomputed_theos(
|
||||
const bts::api::orderman::PrecomputedTheos &precomputed_theos);
|
||||
void do_work();
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace bts::orderman::analytics {
|
||||
// ITheoCalculator is passed to the algo, which can then used it to compute
|
||||
// theos.
|
||||
class ITheoCalculator {
|
||||
public:
|
||||
enum class Impetus { DATA = 0, PERIODIC_LATEJOIN, CLIENT_HEARTBEAT };
|
||||
|
||||
public:
|
||||
// computes the theo for a security with id sec_id and returns the result in
|
||||
// the last arg
|
||||
|
||||
@@ -11,11 +11,14 @@ namespace bts::orderman {
|
||||
// pointer safely
|
||||
class TheoEvent : public mercury::Event<TheoEvent> {
|
||||
public:
|
||||
bts::orderman::analytics::ITheoCalculator::Impetus impetus;
|
||||
bts::orderman::analytics::ITheoCalculator const *theo_calc;
|
||||
using SynopsisPolicy = mercury::CacheAll<TheoEvent>;
|
||||
TheoEvent(bts::orderman::analytics::ITheoCalculator const *theo_calc)
|
||||
: theo_calc(theo_calc) {
|
||||
LOG(OrderMan, Info, "TheoEvent::TheoEvent");
|
||||
TheoEvent(
|
||||
bts::orderman::analytics::ITheoCalculator::Impetus impetus,
|
||||
bts::orderman::analytics::ITheoCalculator const *theo_calc)
|
||||
: impetus(impetus), theo_calc(theo_calc) {
|
||||
LOG(OrderMan, Diag, "TheoEvent::TheoEvent");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -569,7 +569,9 @@ void AlgoWrapperOrder::unsubscribe_position() {
|
||||
}
|
||||
|
||||
void AlgoWrapperOrder::subscribe_theos() {
|
||||
LOG(OrderMan, Info, "AlgoWrapperOrder::subscribe_theos");
|
||||
LOG(OrderMan, Info,
|
||||
"AlgoWrapperOrder::subscribe_theos key: {} is_working: {}", order_key(),
|
||||
is_working());
|
||||
if (!is_working())
|
||||
return;
|
||||
bts_assert(!me->has_theo_sub);
|
||||
@@ -581,7 +583,9 @@ void AlgoWrapperOrder::subscribe_theos() {
|
||||
}
|
||||
|
||||
void AlgoWrapperOrder::unsubscribe_theos() {
|
||||
LOG(OrderMan, Info, "AlgoWrapperOrder::unsubscribe_theos");
|
||||
LOG(OrderMan, Info,
|
||||
"AlgoWrapperOrder::unsubscribe_theos key: {} is_working: {}",
|
||||
order_key(), is_working());
|
||||
if (!is_working())
|
||||
return;
|
||||
bts_assert(me->has_theo_sub);
|
||||
@@ -1054,6 +1058,8 @@ void AlgoWrapperOrder::cleanup() {
|
||||
c.second.order.cancel();
|
||||
if (me->has_timer_sub)
|
||||
unsubscribe_timer();
|
||||
if (me->has_theo_sub)
|
||||
unsubscribe_theos();
|
||||
me->pending_update.reset();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user