1212#include " flox/book/events/book_update_event.h"
1313#include " flox/book/events/trade_event.h"
1414#include " flox/engine/symbol_registry.h"
15+ #include " flox/execution/order_tracker.h"
16+ #include " flox/position/abstract_position_manager.h"
1517#include " flox/strategy/abstract_signal_handler.h"
1618#include " flox/strategy/abstract_strategy.h"
1719#include " flox/strategy/signal.h"
1820#include " flox/strategy/symbol_context.h"
1921#include " flox/strategy/symbol_state_map.h"
2022
23+ #include < atomic>
24+ #include < optional>
2125#include < set>
2226#include < stdexcept>
2327#include < vector>
@@ -52,6 +56,8 @@ class Strategy : public IStrategy
5256 SubscriberId id () const override { return _id; }
5357
5458 void setSignalHandler (ISignalHandler* handler) noexcept { _signalHandler = handler; }
59+ void setOrderTracker (OrderTracker* tracker) noexcept { _orderTracker = tracker; }
60+ void setPositionManager (IPositionManager* pm) noexcept { _positionManager = pm; }
5561
5662 void onTrade (const TradeEvent& ev) final
5763 {
@@ -99,6 +105,25 @@ class Strategy : public IStrategy
99105
100106 const std::vector<SymbolId>& symbols () const noexcept { return _symbols; }
101107
108+ // Position and order status queries
109+ Quantity position (SymbolId sym) const
110+ {
111+ return _positionManager ? _positionManager->getPosition (sym) : Quantity{};
112+ }
113+
114+ Quantity position () const { return position (_symbols[0 ]); }
115+
116+ std::optional<OrderEventStatus> getOrderStatus (OrderId orderId) const
117+ {
118+ return _orderTracker ? _orderTracker->getStatus (orderId) : std::nullopt ;
119+ }
120+
121+ std::optional<OrderState> getOrder (OrderId orderId) const
122+ {
123+ return _orderTracker ? _orderTracker->get (orderId) : std::nullopt ;
124+ }
125+
126+ // Signal emission
102127 void emit (const Signal& signal)
103128 {
104129 if (_signalHandler)
@@ -107,22 +132,53 @@ class Strategy : public IStrategy
107132 }
108133 }
109134
110- void emitMarketBuy (SymbolId symbol, Quantity qty) { emit (Signal::marketBuy (symbol, qty)); }
111- void emitMarketSell (SymbolId symbol, Quantity qty) { emit (Signal::marketSell (symbol, qty)); }
112- void emitLimitBuy (SymbolId symbol, Price price, Quantity qty)
135+ OrderId emitMarketBuy (SymbolId symbol, Quantity qty)
136+ {
137+ OrderId id = nextOrderId ();
138+ emit (Signal::marketBuy (symbol, qty, id));
139+ return id;
140+ }
141+
142+ OrderId emitMarketSell (SymbolId symbol, Quantity qty)
143+ {
144+ OrderId id = nextOrderId ();
145+ emit (Signal::marketSell (symbol, qty, id));
146+ return id;
147+ }
148+
149+ OrderId emitLimitBuy (SymbolId symbol, Price price, Quantity qty)
113150 {
114- emit (Signal::limitBuy (symbol, price, qty));
151+ OrderId id = nextOrderId ();
152+ emit (Signal::limitBuy (symbol, price, qty, id));
153+ return id;
115154 }
116- void emitLimitSell (SymbolId symbol, Price price, Quantity qty)
155+
156+ OrderId emitLimitSell (SymbolId symbol, Price price, Quantity qty)
117157 {
118- emit (Signal::limitSell (symbol, price, qty));
158+ OrderId id = nextOrderId ();
159+ emit (Signal::limitSell (symbol, price, qty, id));
160+ return id;
119161 }
162+
120163 void emitCancel (OrderId orderId) { emit (Signal::cancel (orderId)); }
121164 void emitCancelAll (SymbolId symbol) { emit (Signal::cancelAll (symbol)); }
122165
166+ void emitModify (OrderId orderId, Price newPrice, Quantity newQty)
167+ {
168+ emit (Signal::modify (orderId, newPrice, newQty));
169+ }
170+
123171 private:
172+ OrderId nextOrderId () noexcept
173+ {
174+ static std::atomic<OrderId> s_globalOrderId{1 };
175+ return s_globalOrderId++;
176+ }
177+
124178 SubscriberId _id;
125179 ISignalHandler* _signalHandler{nullptr };
180+ OrderTracker* _orderTracker{nullptr };
181+ IPositionManager* _positionManager{nullptr };
126182 std::vector<SymbolId> _symbols;
127183 std::set<SymbolId> _symbolSet;
128184 mutable SymbolStateMap<SymbolContext> _contexts;
0 commit comments