TT CORE SDK  0.1
TT CORE SDK documentation
prices.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tt_core_sdk/enums.hpp>
4 
5 #include <string>
6 #include <cstdint>
7 #include <bitset>
8 #include <atomic>
9 #include <memory>
10 
11 namespace tt_core_sdk {
12 
14 class InProcessComposerImpl;
15 class InProcessUnifierImpl;
16 class PriceClientTCP;
17 class Instrument;
19 
22 struct PriceSnap
23 {
24  static constexpr size_t MAX_DEPTH_LEVEL = 10;
25 
28  struct depth_snap
29  {
30  size_t count;
31 
34  struct depth_level
35  {
36  double price;
37  int32_t quantity;
38  int32_t implied_quantity;
39  int32_t order_count;
41  };
42 
44 
48 
51  double open_price;
52  double close_price;
53  double high_price;
54  double low_price;
57  double volume;
59 
62  uint64_t seq_no;
63  uint64_t conflation_no;
64  uint64_t exchange_time;
65 
68  uint64_t exchange_time_ns;
70  uint64_t mdrc_recv_time; // eReceivedByServer
72  uint64_t client_recv_time;
73  uint64_t queue_up_time;
74  uint64_t dequeue_time;
76  uint64_t after_parse_time;
77  uint64_t after_cache_time;
78  uint64_t after_merge_time;
81 
82 };
83 
86 struct TimeSale
87 {
90  enum class trade_type
91  {
92  HIT,
93  TAKE,
94  UNKNOWN
95  };
96 
100 
103 
107 
110  bool is_otc;
111  bool is_implied;
112  bool is_leg;
113 
118 };
119 
127 using Filter = std::bitset<30>;
128 
130 static constexpr Filter PRICE_FILTER_NONE { 0 };
131 static constexpr Filter PRICE_FILTER_MARKET_STATE { 1 };
132 static constexpr Filter PRICE_FILTER_ASK0 { 1 << 1 };
133 static constexpr Filter PRICE_FILTER_ASK1 { 1 << 2 };
134 static constexpr Filter PRICE_FILTER_ASK2 { 1 << 3 };
135 static constexpr Filter PRICE_FILTER_ASK3 { 1 << 4 };
136 static constexpr Filter PRICE_FILTER_ASK4 { 1 << 5 };
137 static constexpr Filter PRICE_FILTER_ASK5 { 1 << 6 };
138 static constexpr Filter PRICE_FILTER_ASK6 { 1 << 7 };
139 static constexpr Filter PRICE_FILTER_ASK7 { 1 << 8 };
140 static constexpr Filter PRICE_FILTER_ASK8 { 1 << 9 };
141 static constexpr Filter PRICE_FILTER_ASK9 { 1 << 10 };
142 static constexpr Filter PRICE_FILTER_BID0 { 1 << 11 };
143 static constexpr Filter PRICE_FILTER_BID1 { 1 << 12 };
144 static constexpr Filter PRICE_FILTER_BID2 { 1 << 13 };
145 static constexpr Filter PRICE_FILTER_BID3 { 1 << 14 };
146 static constexpr Filter PRICE_FILTER_BID4 { 1 << 15 };
147 static constexpr Filter PRICE_FILTER_BID5 { 1 << 16 };
148 static constexpr Filter PRICE_FILTER_BID6 { 1 << 17 };
149 static constexpr Filter PRICE_FILTER_BID7 { 1 << 18 };
150 static constexpr Filter PRICE_FILTER_BID8 { 1 << 19 };
151 static constexpr Filter PRICE_FILTER_BID9 { 1 << 20 };
152 static constexpr Filter PRICE_FILTER_OPEN { 1 << 21 };
153 static constexpr Filter PRICE_FILTER_CLOSE { 1 << 22 };
154 static constexpr Filter PRICE_FILTER_HIGH { 1 << 23 };
155 static constexpr Filter PRICE_FILTER_LOW { 1 << 24 };
156 static constexpr Filter PRICE_FILTER_LAST_TRADE_PRICE { 1 << 25 };
157 static constexpr Filter PRICE_FILTER_LAST_TRADE_QTY { 1 << 26 };
158 static constexpr Filter PRICE_FILTER_VOLUME { 1 << 27 };
159 static constexpr Filter PRICE_FILTER_SETTLEMENT { 1 << 28 };
160 static constexpr Filter PRICE_FILTER_TIME_SALES { 1 << 29 };
161 static constexpr Filter PRICE_FILTER_NO_IMPLIES { 1 << 30 };
162 static constexpr Filter PRICE_FILTER_ALL_ASK { 0x7FE };
163 static constexpr Filter PRICE_FILTER_ALL_BID { 0x1FF800 };
164 static constexpr Filter PRICE_FILTER_ALL_DEPTH { 0x1FFFFE };
165 static constexpr Filter PRICE_FILTER_ALL_PRICE_FIELD { 0x1FFFFFFF };
166 static constexpr Filter PRICE_FILTER_ALL { 0x3FFFFFFF };
167 static constexpr Filter PRICE_FILTER_PNL { 0x12400803 };
168 //static constexpr Filter PRICE_FILTER_INSIDE_MARKET { PRICE_FILTER_ASK0 | PRICE_FILTER_BID0 };
170 
176 {
177 public:
178  virtual ~PriceEventListener (void) noexcept = default;
179 
183  virtual void OnPriceUpdate (const PriceSnap& snap) = 0;
184 
188  virtual void OnTimeSalesUpdate (const TimeSale& ts) = 0;
189 
192  virtual void OnError (const std::string& error) = 0;
193 };
194 
198 {
199  uint64_t instr_id;
200  uint64_t user_id;
201 };
202 
210 {
211 public:
215  PriceSubscription (void);
216 
219  ~PriceSubscription (void) noexcept;
220 
222  PriceSubscription (const PriceSubscription&) = delete;
223  PriceSubscription& operator= (const PriceSubscription&) = delete;
225  PriceSubscription& operator= (PriceSubscription&&) noexcept;
227 
229  uint64_t Id (void) const noexcept { return m_id; }
230 
234  bool IsValid (void) const noexcept;
235 
242  void Pause (void);
243  bool Resume (void);
244  void Cancel (void);
246 
251  Filter GetFilter (void) const noexcept;
252  void SetFilter (const Filter& filter) noexcept;
253  void AddFilter (const Filter& additional_filter) noexcept;
254 
256 private:
258  friend class PriceLibImpl;
259  friend class InProcessComposerImpl;
260  friend class InProcessUnifierImpl;
261  friend class InProcessPriceTCPImpl;
262  friend class PriceClientTCP;
263 
264  using FilterPtr = std::shared_ptr<std::atomic<Filter>>;
265  PriceSubscription (uint64_t, const price_sub_key&, FilterPtr&&);
266 
267  uint64_t m_id = 0;
268  price_sub_key m_key;
269  FilterPtr m_filter;
271 };
272 
283 PriceSubscription CreatePriceSubscription (const std::shared_ptr<Instrument>& instr,
284  const Filter& filter,
285  const std::shared_ptr<PriceEventListener>& listener);
286 
288 std::string to_string (const PriceSnap& snap);
289 std::string to_string (TimeSale::trade_type type);
291 
292 } // namespace tt_core_sdk
depth_snap bids
Price feed depth.
Definition: prices.hpp:46
Manages a price subscription.
Definition: prices.hpp:209
uint64_t before_callback_time
Definition: prices.hpp:79
uint64_t epoch_transact_time_nano
Transaction Time Since Epoch (ns)
Definition: prices.hpp:102
uint64_t exchange_time_ns
Internal.
Definition: prices.hpp:68
static constexpr size_t MAX_DEPTH_LEVEL
Max supported levels of depth.
Definition: prices.hpp:24
bool is_implied
Trade is implied.
Definition: prices.hpp:111
uint64_t after_merge_time
Definition: prices.hpp:78
int32_t order_count
Number of orders that make up the total quantity.
Definition: prices.hpp:39
std::string to_string(instr_state)
TT Core SDK enum to_string conversions.
Time and Sales update data.
Definition: prices.hpp:86
uint64_t queue_up_time
Definition: prices.hpp:73
uint64_t order_stimulus_received_algo
Definition: prices.hpp:71
double last_trade_price
Last Traded Price (NAN when unavailable)
Definition: prices.hpp:55
uint64_t seq_no
Price snapshot properties.
Definition: prices.hpp:62
uint64_t exchange_transaction_time_ns
Definition: prices.hpp:69
int32_t quantity
Total quantity at this level.
Definition: prices.hpp:37
uint64_t after_parse_time
Definition: prices.hpp:76
double close_price
Close price (NAN when unavailable)
Definition: prices.hpp:52
double last_trade_price
Time and Sales snapshot properties.
Definition: prices.hpp:98
uint64_t Id(void) const noexcept
Unique PriceSubscription ID.
Definition: prices.hpp:229
uint64_t before_parse_time
Definition: prices.hpp:75
uint64_t mdrc_recv_time
Definition: prices.hpp:70
uint64_t conflation_no
Price conflation count.
Definition: prices.hpp:63
trade_type
Type of trade triggering the update.
Definition: prices.hpp:90
double volume
Total contract volume.
Definition: prices.hpp:57
double last_trade_quantity
Last traded quantity (NAN when unavailable)
Definition: prices.hpp:56
trade_qualifier qualifier
Definition: prices.hpp:106
bool is_otc
Time and Sales data flags.
Definition: prices.hpp:110
uint64_t exchange_transact_time_ns
Internal.
Definition: prices.hpp:116
size_t count
Number of available price depth levels.
Definition: prices.hpp:30
int32_t implied_quantity
Implied quantity contributing to the total quantity.
Definition: prices.hpp:38
Interface for listening to price subscription events.
Definition: prices.hpp:175
uint64_t after_cache_time
Definition: prices.hpp:77
double last_trade_quantity
Last traded quantity (NAN when unavailable)
Definition: prices.hpp:99
uint64_t epoch_transact_time_micro
Transaction Time Since Epoch (us)
Definition: prices.hpp:101
Price update data.
Definition: prices.hpp:22
uint64_t exchange_time
Definition: prices.hpp:64
trade_type type
Trade type.
Definition: prices.hpp:104
enum market_state market_state
Market State.
Definition: prices.hpp:43
Snapshot of the market depth.
Definition: prices.hpp:28
uint64_t client_recv_time
Definition: prices.hpp:72
std::bitset< 30 > Filter
Bitmask specifying which price updates trigger event notifications.
Definition: prices.hpp:127
A single level of the total depth.
Definition: prices.hpp:34
double high_price
High price (NAN when unavailable)
Definition: prices.hpp:53
market_state
Market State.
Definition: enums.hpp:163
PriceSubscription CreatePriceSubscription(const std::shared_ptr< Instrument > &instr, const Filter &filter, const std::shared_ptr< PriceEventListener > &listener)
Create a price subscription.
trade_status status
Trade Status.
Definition: prices.hpp:105
double open_price
Price feed properties.
Definition: prices.hpp:51
double low_price
Low price (NAN when unavailable)
Definition: prices.hpp:54
struct tt_core_sdk::PriceSnap::depth_snap::depth_level levels[MAX_DEPTH_LEVEL]
uint64_t dequeue_time
Definition: prices.hpp:74