SP-214 Wire StatusEvent to IAlgoOrder/IAlgoServices
This commit is contained in:
1 parent
8e2092c3e2
commit
23d4e7f78d
10 files changed
+69
-4
No files matched your search
@@ -499,6 +499,9 @@ void OrderManager::init_order_services() {
|
||||
std::function<void(SecurityKey)> on_ticker_sub = [this](SecurityKey k) {
|
||||
publish(me->services_data.md_request_pub, k, MDRequestType::TICKER);
|
||||
};
|
||||
std::function<void(SecurityKey)> on_status_sub = [this](SecurityKey k) {
|
||||
publish(me->services_data.md_request_pub, k, MDRequestType::STATUS);
|
||||
};
|
||||
std::function<void(SecurityKey)> on_settlement_sub = [this](SecurityKey k) {
|
||||
publish(me->services_data.settlement_request_pub, k);
|
||||
};
|
||||
@@ -517,6 +520,9 @@ void OrderManager::init_order_services() {
|
||||
me->services_data.ticker_subs =
|
||||
std::make_unique<ContentSubscription<TickerUpdateEvent>>(
|
||||
*this, on_ticker_sub, log);
|
||||
me->services_data.status_subs =
|
||||
std::make_unique<ContentSubscription<StatusUpdateEvent>>(
|
||||
*this, on_status_sub, log);
|
||||
me->services_data.settlement_subs =
|
||||
std::make_unique<ContentSubscription<SettlementUpdateEvent>>(
|
||||
*this, on_settlement_sub, log);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "lib/orderman/actors/order_manager/OrderServicesData.h"
|
||||
#include "lib/orderman/actors/order_manager/SessionServices.h"
|
||||
#include "lib/orderman/events/TickerUpdateEvent.h"
|
||||
#include "lib/orderman/events/StatusUpdateEvent.h"
|
||||
#include "lib/orderman/governor/Governor.h"
|
||||
#include "lib/orderman/orderman_utils/EventStream.h"
|
||||
#include "lib/orderman/orders/Order.h"
|
||||
@@ -93,6 +94,13 @@ class OrderServices {
|
||||
k, [this, cb](auto const &ev) { this->on_external_event(ev, cb); });
|
||||
}
|
||||
void unsubscribe_from_ticker(TickerSubID sid) { _ticker_updates.unsub(sid); }
|
||||
// Trading Status
|
||||
using StatusSubID = EventStream<StatusUpdateEvent>::SubID;
|
||||
template <class CB> StatusSubID subscribe_to_status(SecurityKey k, CB&& cb) {
|
||||
return _status_updates.sub(
|
||||
k, [this,cb](const auto& ev) { this->on_external_event(ev,cb); });
|
||||
}
|
||||
void unsubscribe_from_status(StatusSubID sid) { _status_updates.unsub(sid); }
|
||||
// Settlement
|
||||
using SettlementSubID = EventStream<SettlementUpdateEvent>::SubID;
|
||||
template <class CB>
|
||||
@@ -103,7 +111,6 @@ class OrderServices {
|
||||
void unsubscribe_from_settlements(SettlementSubID sid) {
|
||||
_settlement_updates.unsub(sid);
|
||||
}
|
||||
// Settlement
|
||||
|
||||
// Time
|
||||
template <class CB> void subscribe_to_time(CB &&cb) {
|
||||
@@ -285,6 +292,7 @@ class OrderServices {
|
||||
OrderStateUpdateEvent _last_state_update;
|
||||
EventStream<BookUpdateEvent> _book_updates;
|
||||
EventStream<TickerUpdateEvent> _ticker_updates;
|
||||
EventStream<StatusUpdateEvent> _status_updates;
|
||||
EventStream<SettlementUpdateEvent> _settlement_updates;
|
||||
EventStream<mercury::TimerEvent, mercury::NoKey> _time_change;
|
||||
boost::container::small_vector<SessionServices, 20> _sessions;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "lib/orderman/events/ActivateOrderEvent.h"
|
||||
#include "lib/orderman/events/BookUpdateEvent.h"
|
||||
#include "lib/orderman/events/TickerUpdateEvent.h"
|
||||
#include "lib/orderman/events/StatusUpdateEvent.h"
|
||||
#include "lib/orderman/events/CancelOrderEvent.h"
|
||||
#include "lib/orderman/events/CancelRejectEvent.h"
|
||||
#include "lib/orderman/events/DetachOrderEvent.h"
|
||||
@@ -87,6 +88,7 @@ class OrderServicesData {
|
||||
OrderFactory order_factory;
|
||||
std::unique_ptr<mercury::ContentSubscription<BookUpdateEvent>> md_subs;
|
||||
std::unique_ptr<mercury::ContentSubscription<TickerUpdateEvent>> ticker_subs;
|
||||
std::unique_ptr<mercury::ContentSubscription<StatusUpdateEvent>> status_subs;
|
||||
trace::CorID cor_id;
|
||||
std::unique_ptr<mercury::ContentSubscription<SettlementUpdateEvent>>
|
||||
settlement_subs;
|
||||
|
||||
@@ -9,13 +9,15 @@
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
struct StatusUpdateEvent : public mercury::Event<StatusUpdateEvent> {
|
||||
class StatusUpdateEvent : public mercury::Event<StatusUpdateEvent> {
|
||||
SecurityKey _key;
|
||||
public:
|
||||
using SynopsisPolicy = mercury::NoSynopsis;
|
||||
SecurityKey key;
|
||||
co2::TradingStatus status;
|
||||
trace::CorID trace;
|
||||
SecurityKey key() const { return _key; }
|
||||
StatusUpdateEvent(SecurityKey key, co2::TradingStatus status) :
|
||||
key(key), status(status), trace() { }
|
||||
_key(key), status(status), trace() { }
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -57,6 +57,7 @@ struct AlgoWrapperOrder::PImpl {
|
||||
|
||||
Map<SecurityKey, OrderServices::BookSubID> book_subs;
|
||||
Map<SecurityKey, OrderServices::TickerSubID> ticker_subs;
|
||||
Map<SecurityKey, OrderServices::StatusSubID> status_subs;
|
||||
Map<OrderKey, ChildRecord> children;
|
||||
bool has_timer_sub = false;
|
||||
|
||||
@@ -434,6 +435,26 @@ void AlgoWrapperOrder::unsubscribe_ticker(SecurityKey k) {
|
||||
if (auto it = me->ticker_subs.find(k); it != me->ticker_subs.end())
|
||||
me->services->unsubscribe_from_ticker(it->second);
|
||||
}
|
||||
|
||||
void AlgoWrapperOrder::subscribe_status(SecurityKey k) {
|
||||
if (!is_working()) return;
|
||||
bts_assert(me->status_subs.find(k) == me->status_subs.end());
|
||||
|
||||
me->status_subs[k] =
|
||||
me->services->subscribe_to_status(k, [this,k](const auto& ev) {
|
||||
ReportStateGuard _(*this);
|
||||
me->algo->on_status(k, ev.status);
|
||||
});
|
||||
}
|
||||
|
||||
void AlgoWrapperOrder::unsubscribe_status(SecurityKey k) {
|
||||
if (!is_working()) return;
|
||||
bts_assert(me->status_subs.find(k) != me->status_subs.end());
|
||||
auto it = me->status_subs.find(k);
|
||||
if (it != me->status_subs.end()) {
|
||||
me->services->unsubscribe_from_status(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
void AlgoWrapperOrder::subscribe_child_change(OrderKey k) {
|
||||
if (!is_working())
|
||||
|
||||
@@ -49,6 +49,9 @@ class AlgoWrapperOrder : public Order,
|
||||
void unsubscribe_timer() override;
|
||||
void subscribe_ticker(SecurityKey) override;
|
||||
void unsubscribe_ticker(SecurityKey) override;
|
||||
void subscribe_status(SecurityKey) override;
|
||||
void unsubscribe_status(SecurityKey) override;
|
||||
|
||||
OrderKey launch_child(ChildTemplate &, Price, Quantity,
|
||||
bool subscribe = true) override;
|
||||
OrderKey launch_child(api::orderman::OrderDefinition const &, Price,
|
||||
|
||||
@@ -41,6 +41,8 @@ class IAlgoOrder {
|
||||
// Trades stream for the specified security
|
||||
virtual void on_ticker(SecurityKey, TradeVector const&) {};
|
||||
|
||||
virtual void on_status(SecurityKey, co2::TradingStatus) {};
|
||||
|
||||
// A periodic timer has fired
|
||||
virtual void on_timer() {}
|
||||
|
||||
|
||||
@@ -48,6 +48,10 @@ class IAlgoServices : public IBeforeLaunchAlgoServices {
|
||||
virtual void subscribe_ticker(SecurityKey) = 0;
|
||||
virtual void unsubscribe_ticker(SecurityKey) = 0;
|
||||
|
||||
// Subscribe to security trading status
|
||||
virtual void subscribe_status(SecurityKey) = 0;
|
||||
virtual void unsubscribe_status(SecurityKey) = 0;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Child management
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@@ -64,6 +64,7 @@ struct AlgoTestDriverBase::Impl : public RecursionCounter {
|
||||
std::map<SecurityKey, Book> books;
|
||||
std::map<SecurityKey, bool> book_subs;
|
||||
std::map<SecurityKey, bool> ticker_subs;
|
||||
std::map<SecurityKey, bool> status_subs;
|
||||
bool sub_timer = false;
|
||||
|
||||
// Callbacks
|
||||
@@ -163,6 +164,12 @@ void AlgoTestDriverBase::update_ticker(SecurityKey key, const TradeVector& data)
|
||||
me->algo.on_ticker(key, data);
|
||||
}
|
||||
}
|
||||
void AlgoTestDriverBase::update_status(SecurityKey key, co2::TradingStatus status) {
|
||||
auto iter = me->status_subs.find(key);
|
||||
if (iter != me->ticker_subs.end() && iter->second) {
|
||||
me->algo.on_status(key,status);
|
||||
}
|
||||
}
|
||||
void AlgoTestDriverBase::advance_time(Duration d, uint32_t steps) {
|
||||
Duration dprime = d / steps;
|
||||
for (uint32_t s = 0; s < steps; ++s) {
|
||||
@@ -332,6 +339,13 @@ void AlgoTestDriverBase::unsubscribe_ticker(SecurityKey key) {
|
||||
me->ticker_subs.erase(key);
|
||||
}
|
||||
|
||||
void AlgoTestDriverBase::subscribe_status(SecurityKey key) {
|
||||
me->status_subs[key] = true;
|
||||
}
|
||||
void AlgoTestDriverBase::unsubscribe_status(SecurityKey key) {
|
||||
me->status_subs.erase(key);
|
||||
}
|
||||
|
||||
void AlgoTestDriverBase::subscribe_child_change(OrderKey k) {
|
||||
for (auto& child : me->orders) {
|
||||
if (child.key == k) {
|
||||
|
||||
@@ -71,6 +71,7 @@ class AlgoTestDriverBase : private IAlgoServices {
|
||||
|
||||
void update_book(const Book&);
|
||||
void update_ticker(SecurityKey, const TradeVector&);
|
||||
void update_status(SecurityKey, co2::TradingStatus);
|
||||
void advance_time(Duration, uint32_t steps=1);
|
||||
IAlgoOrder::OnCancelResponse cancel();
|
||||
|
||||
@@ -117,6 +118,8 @@ private:
|
||||
void unsubscribe_timer() override;
|
||||
void subscribe_ticker(SecurityKey) override;
|
||||
void unsubscribe_ticker(SecurityKey) override;
|
||||
void subscribe_status(SecurityKey) override;
|
||||
void unsubscribe_status(SecurityKey) override;
|
||||
|
||||
OrderKey launch_child(ChildTemplate &, Price, Quantity, bool) override;
|
||||
OrderKey launch_child(api::orderman::OrderDefinition const &, Price,
|
||||
|
||||
Reference in new issue
Block a user