TT CORE SDK  0.1
TT CORE SDK documentation
orders.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tt_core_sdk/tt_core_sdk.hpp>
4 #include <tt_core_sdk/enums.hpp>
5 
6 #include <string>
7 #include <cstdint>
8 #include <utility>
9 #include <functional>
10 #include <memory>
11 #include <vector>
12 #include <limits>
13 
14 namespace tt_core_sdk {
15 
17 class OrderHandle;
18 class OrderManager;
19 class ExecutionReportImpl;
20 class OrderCancelRejectImpl;
21 class OrderHandleImpl;
22 class OrderManagerImpl;
23 class SharedOrderManagerImpl;
24 class Instrument;
26 
32 {
33  std::shared_ptr<Instrument> instrument;
37  uint64_t account = 0;
38  uint64_t user_id = 0;
39  uint64_t broker_id = 0;
40  double price = std::numeric_limits<double>::quiet_NaN();
41  double trigger_price = std::numeric_limits<double>::quiet_NaN();
42  int32_t quantity = 0;
43  int32_t display_quantity = 0;
44 };
45 
51 {
52  uint32_t request_id = 0;
53  uint64_t request_time = 0;
54  double price = std::numeric_limits<double>::quiet_NaN();
55  double trigger_price = std::numeric_limits<double>::quiet_NaN();
56  int32_t quantity = 0;
57  int32_t display_quantity = 0;
58 };
59 
65 class OrderHandle : public std::enable_shared_from_this<OrderHandle>
66 {
67 public:
76  explicit OrderHandle (OrderManager& manager, const order_profile& profile);
77 
79  explicit OrderHandle (std::unique_ptr<OrderHandleImpl>&&);
80 
82  ~OrderHandle (void) noexcept;
83 
85  OrderHandle (const OrderHandle&) = delete;
86  OrderHandle& operator= (const OrderHandle&) = delete;
87  OrderHandle (OrderHandle&&) = delete;
88  OrderHandle& operator= (OrderHandle&&) = delete;
90 
93  const std::string& GetOrderId (void) const noexcept;
94 
96  double GetPrice (void) const noexcept;
97 
99  int32_t GetOrderQuantity (void) const noexcept;
100 
102  int32_t GetWorkingQuantity (void) const noexcept;
103 
108  void ChangeOrder (change_request& request);
109 
113  void ChangePrice (double price, uint32_t request_id = 0);
114 
118  void ChangeQuantity (int32_t quantity, uint32_t request_id = 0);
119 
124  void ChangePriceQuantity (double price, int32_t quantity, uint32_t request_id = 0);
125 
128  void DeleteOrder (uint32_t request_id = 0);
129 
130 private:
131  friend class OrderManager;
132  friend class OrderManagerImpl;
133  friend class SharedOrderManagerImpl;
134 
135  std::unique_ptr<OrderHandleImpl> m_impl;
136 };
137 
148 {
149 public:
151  explicit ExecutionReport (std::shared_ptr<ExecutionReportImpl>);
152 
154  ~ExecutionReport (void) noexcept;
155 
157  ExecutionReport (const ExecutionReport&) = default;
158  ExecutionReport& operator= (const ExecutionReport&) = default;
159  ExecutionReport (ExecutionReport&&) = default;
160  ExecutionReport& operator= (ExecutionReport&&) = default;
162 
164  bool IsPending (void) const noexcept;
165  bool IsFill (void) const noexcept;
166  bool IsFullFill (void) const noexcept;
167  bool IsDelete (void) const noexcept;
168  bool IsReject (void) const noexcept;
169  bool IsTriggerActivated (void) const noexcept;
171 
173  std::pair<bool, std::string> GetOrderId (void) const noexcept;
174  std::pair<bool, std::string> GetExecId (void) const noexcept;
175  std::pair<bool, order_status> GetOrderStatus (void) const noexcept;
176  std::pair<bool, exec_type> GetExecType (void) const noexcept;
177  std::pair<bool, order_type> GetOrderType (void) const noexcept;
178  std::pair<bool, order_side> GetSide (void) const noexcept;
179  std::pair<bool, time_in_force> GetTimeInForce (void) const noexcept;
180  std::pair<bool, double> GetPrice (void) const noexcept;
181  std::pair<bool, double> GetTriggerPrice (void) const noexcept;
182  std::pair<bool, int32_t> GetOrderQty (void) const noexcept;
183  std::pair<bool, int32_t> GetLeavesQty (void) const noexcept;
184  std::pair<bool, int32_t> GetCumQty (void) const noexcept;
185  std::pair<bool, int32_t> GetDisplayQty (void) const noexcept;
186  std::pair<bool, int32_t> GetRefreshQty (void) const noexcept;
188 
190  std::pair<bool, double> GetLastFillPrice (void) const noexcept;
191  std::pair<bool, int32_t> GetLastFillQty (void) const noexcept;
193 
195  std::pair<bool, uint64_t> GetUserId (void) const noexcept;
196  std::pair<bool, uint64_t> GetAccountId (void) const noexcept;
197  std::pair<bool, std::string> GetAccountName (void) const noexcept;
198  std::pair<bool, uint64_t> GetBrokerId (void) const noexcept;
200 
202  std::pair<bool, uint64_t> GetInstrumentId (void) const noexcept;
203  std::pair<bool, market> GetMarket (void) const noexcept;
205 
207  std::pair<bool, ord_rej_reason> GetOrderRejectReason (void) const noexcept;
208  std::pair<bool, reject_source> GetRejectSource (void) const noexcept;
209  std::pair<bool, reject_code> GetRejectCode (void) const noexcept;
210  std::pair<bool, std::string> GetText (void) const noexcept;
212 
213 private:
214  std::shared_ptr<ExecutionReportImpl> m_impl;
215 };
216 
225 {
226 public:
228  explicit OrderCancelReject (std::shared_ptr<OrderCancelRejectImpl>);
229 
231  ~OrderCancelReject (void) noexcept;
232 
234  OrderCancelReject (const OrderCancelReject&) = default;
235  OrderCancelReject& operator= (const OrderCancelReject&) = default;
236  OrderCancelReject (OrderCancelReject&&) = default;
237  OrderCancelReject& operator= (OrderCancelReject&&) = default;
239 
241  std::pair<bool, std::string> GetOrderId (void) const noexcept;
242  std::pair<bool, order_status> GetOrderStatus (void) const noexcept;
243  std::pair<bool, order_type> GetOrderType (void) const noexcept;
244  std::pair<bool, order_side> GetSide (void) const noexcept;
245  std::pair<bool, time_in_force> GetTimeInForce (void) const noexcept;
247 
249  std::pair<bool, uint64_t> GetUserId (void) const noexcept;
250  std::pair<bool, uint64_t> GetAccountId (void) const noexcept;
251  std::pair<bool, std::string> GetAccountName (void) const noexcept;
252  std::pair<bool, uint64_t> GetBrokerId (void) const noexcept;
254 
256  std::pair<bool, uint64_t> GetInstrumentId (void) const noexcept;
257  std::pair<bool, market> GetMarket (void) const noexcept;
259 
261  std::pair<bool, cxl_rej_reason> GetCancelRejectReason (void) const noexcept;
262  std::pair<bool, reject_source> GetRejectSource (void) const noexcept;
263  std::pair<bool, reject_code> GetRejectCode (void) const noexcept;
264  std::pair<bool, std::string> GetText (void) const noexcept;
266 
267 private:
268  std::shared_ptr<OrderCancelRejectImpl> m_impl;
269 };
270 
274 {
275  uint32_t request_id = 0;
276  std::shared_ptr<OrderHandle> handle;
278 
280  execution_report_response (uint32_t, std::shared_ptr<OrderHandle>&,
281  std::shared_ptr<ExecutionReportImpl>);
282 };
283 
287 {
288  uint32_t request_id = 0;
289  std::shared_ptr<OrderHandle> handle;
291 
293  order_cancel_reject_response (uint32_t, std::shared_ptr<OrderHandle>&,
294  std::shared_ptr<OrderCancelRejectImpl>);
295 };
296 
300 {
301  uint32_t request_id = 0;
302  std::shared_ptr<OrderHandle> handle;
303 };
304 
308 {
309  uint32_t request_id = 0;
310  std::shared_ptr<OrderHandle> handle;
311  std::string message;
312 };
313 
314 // TODO document
316 {
317  std::string order_id;
318  std::string exec_id;
319  uint64_t instrument_id;
320  uint64_t account_id;
321  uint64_t broker_id;
322  uint64_t connection_id;
323  double last_px;
324  int32_t last_qty;
325  int32_t order_qty;
326  int32_t exch_order_qty;
327  int32_t cum_qty;
328  int32_t exch_cum_qty;
329  int32_t leaves_qty;
331  uint64_t order_sequence;
332 
335  uint64_t time_sent;
337 };
338 
342 {
343  uint32_t request_id = 0;
345  bool download_complete = false;
346 };
347 
351 {
352  uint32_t request_id = 0;
353  std::vector<std::shared_ptr<OrderHandle>> book;
354 };
355 
356 // TODO
358 {
359  uint32_t request_id = 0;
360 };
361 
365 {
366  uint32_t request_id = 0;
367  std::string message;
368 };
369 
375 {
376 public:
377  virtual ~OrderEventListener (void) noexcept = default;
378 
380  virtual void OnExecutionReport (const execution_report_response&) = 0;
381 
383  virtual void OnOrderCancelReject (const order_cancel_reject_response&) = 0;
384 
386  virtual void OnOrderTimeout (const order_timeout_response&) = 0;
387 
389  virtual void OnRequestFailed (const request_failed_response&) = 0;
390 
394  virtual void OnFillDownload (fill_download_response&&) = 0;
395 
397  virtual void OnOrderBookDownload (orderbook_download_response&&) = 0;
398 
399  // TODO
400  //virtual void OnPositionDownload (const position_download_response&) = 0;
401 
403  virtual void OnDownloadFailed (download_failed_response&&) = 0;
404 };
405 
411 {
412 public:
414  OrderManager (void);
415 
417  ~OrderManager (void) noexcept;
418 
420  OrderManager (const OrderManager&) = delete;
421  OrderManager& operator= (const OrderManager&) = delete;
422  OrderManager (OrderManager&&) = default;
423  OrderManager& operator= (OrderManager&&) = default;
425 
433  void Subscribe (const std::shared_ptr<OrderEventListener>& listener) noexcept;
434 
440  void PlaceOrder (std::shared_ptr<OrderHandle>& handle, uint32_t request_id = 0);
441 
451  void DownloadFills (uint8_t days = 7,
452  market market_id = market::INVALID,
453  uint64_t account = 0,
454  uint32_t request_id = 0);
455 
459  void DownloadOrderBook (uint32_t request_id = 0);
460 
461 private:
462  friend class OrderHandle;
463  std::shared_ptr<OrderManagerImpl> m_impl;
464 };
465 
466 } // namespace tt_core_sdk
std::vector< std::shared_ptr< OrderHandle > > book
Container of orders in the book.
Definition: orders.hpp:353
std::string message
Message describing the failure.
Definition: orders.hpp:367
std::string message
Message describing the failure.
Definition: orders.hpp:311
Interface for listening to order events.
Definition: orders.hpp:374
POD definition of an order change request.
Definition: orders.hpp:50
Response delivered through OrderEventListener.
Definition: orders.hpp:350
Manages a set of orders and delivers order notifications.
Definition: orders.hpp:410
Response delivered through OrderEventListener.
Definition: orders.hpp:299
ExecutionReport er
Response details.
Definition: orders.hpp:277
fill_receipt fill
Fill receipt data.
Definition: orders.hpp:344
Response delivered through OrderEventListener.
Definition: orders.hpp:364
std::shared_ptr< Instrument > instrument
Definition: orders.hpp:33
Response delivered through OrderEventListener.
Definition: orders.hpp:341
POD definition of an order to provide when submitting.
Definition: orders.hpp:31
Response delivered through OrderEventListener.
Definition: orders.hpp:273
std::shared_ptr< OrderHandle > handle
Order tied to the response.
Definition: orders.hpp:276
Message receipt issued when a cancel or cancel/replace is rejected.
Definition: orders.hpp:224
std::shared_ptr< OrderHandle > handle
Order tied to the response.
Definition: orders.hpp:289
std::shared_ptr< OrderHandle > handle
Order tied to the response.
Definition: orders.hpp:310
uint64_t received_from_exchange
Definition: orders.hpp:334
OrderCancelReject ocr
Response details.
Definition: orders.hpp:290
Outbound order message receipt.
Definition: orders.hpp:147
std::shared_ptr< OrderHandle > handle
Order tied to the response.
Definition: orders.hpp:302
Response delivered through OrderEventListener.
Definition: orders.hpp:286
Represents the current state of the order.
Definition: orders.hpp:65
Response delivered through OrderEventListener.
Definition: orders.hpp:307