ClockWork DB CoreAPI 1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
order_book_event.hpp
1#ifndef HAVE_TOM_UTIL_ORDER_BOOK_EVENT_HPP
2#define HAVE_TOM_UTIL_ORDER_BOOK_EVENT_HPP
3
4#include <ostream>
5#include <cstdint>
6#include <tom-util/value_types.hpp>
7#include <tom-util/observation.hpp>
8#include <tom-util/scalar.hpp>
9
10namespace tom
11{
12 namespace value_types
13 {
14
15 enum order_side : char
16 {
17 B = 'B',
18 S = 'S'
19 };
20
21 order_side
22 to_order_side(const char c);
23
24 enum event_type : char
25 {
26 NEW = 'F',
27 REPLACE = 'U',
28 DELETE = 'D',
29 EXECUTED = 'X'
30 };
31
32 event_type
33 to_event_type(const char c);
34
36 {
37 public:
38 order_book_event() : timestamp(0), price(0), size(0), order_side('B'), event_type('F') {}
39 order_book_event(const order_book_event &rhs) : timestamp(rhs.timestamp), price(rhs.price),
40 size(rhs.size), order_side(rhs.order_side), event_type(rhs.event_type) {};
42 operator=(const order_book_event &rhs)
43 {
44 timestamp = rhs.timestamp;
45 price = rhs.price;
46 size = rhs.size;
47 order_side = rhs.order_side;
48 event_type = rhs.event_type;
49 return *this;
50 }
51 int64_t timestamp;
52 int32_t price; // price * 1000
53 int32_t size; //
54 char order_side; // [B,S]
55 char event_type;
56
57 bool
58 is_normal() const
59 {
60 return true;
61 }
62 bool
63 operator==(const order_book_event &rhs) const
64 {
65 return timestamp == rhs.timestamp && price == rhs.price &&
66 size == rhs.size && order_side == rhs.order_side &&
67 event_type == rhs.event_type;
68 }
69 std::ostream &
70 print(std::ostream &os) const
71 {
72 return os << "OrderBookEvent{"
73 << "timestamp=" << timestamp
74 << ", price=" << price
75 << ", size=" << size
76 << ", order_side=" << order_side
77 << ", event_type=" << event_type
78 << "}";
79 };
80 };
81 template <>
83 {
84 static const order_book_event value;
85 };
86 template <>
88 {
89 static const order_book_event value;
90 };
91 template <>
93 {
94 static const order_book_event value;
95 };
96
97 std::ostream &
98 operator<<(std::ostream &os, const order_book_event &obe);
99
101 operator+(const order_book_event &lhs, const order_book_event &rhs);
102
104 operator-(const order_book_event &lhs, const order_book_event &rhs);
105
107 operator*=(const order_book_event &lhs, const order_book_event &rhs);
108
110 operator/=(const order_book_event &lhs, const order_book_event &rhs);
111
112 bool
113 operator<(const order_book_event &lhs, const order_book_event &rhs);
114
115 static order_book_event
116 get_missing_order_book_event();
117
119 public:
120 int64_t timestamp;
121 int32_t bid_price;
122 int32_t bid_size;
123 int32_t offer_price;
124 int32_t offer_size;
125
126 top_of_book() : timestamp(0), bid_price(0), bid_size(0), offer_price(0), offer_size(0) {}
127 top_of_book(const top_of_book &rhs) : timestamp(rhs.timestamp), bid_price(rhs.bid_price),
128 bid_size(rhs.bid_size), offer_price(rhs.offer_price), offer_size(rhs.offer_size) {};
130 operator=(const top_of_book &rhs)
131 {
132 timestamp = rhs.timestamp;
133 bid_price = rhs.bid_price;
134 bid_size = rhs.bid_size;
135 offer_price = rhs.offer_price;
136 offer_size = rhs.offer_size;
137 return *this;
138 }
139
140 bool
141 is_normal() const
142 {
143 return true;
144 }
145 bool
146 operator==(const top_of_book &rhs) const
147 {
148 return timestamp == rhs.timestamp && bid_price == rhs.bid_price &&
149 bid_size == rhs.bid_size && offer_price == rhs.offer_price &&
150 offer_size == rhs.offer_size;
151 }
152 std::ostream &
153 print(std::ostream &os) const
154 {
155 return os << "TopOfBook{"
156 << "timestamp=" << timestamp
157 << ", bid_price=" << bid_price
158 << ", bid_size=" << bid_size
159 << ", offer_price=" << offer_price
160 << ", offer_size=" << offer_size
161 << "}";
162 }
163
164 };
165 std::ostream &
166 operator<<(std::ostream &os, const top_of_book &obe);
167
169 operator+(const top_of_book &lhs, const top_of_book &rhs);
170
172 operator-(const top_of_book &lhs, const top_of_book &rhs);
173
175 operator*=(const top_of_book &lhs, const top_of_book &rhs);
176
178 operator/=(const top_of_book &lhs, const top_of_book &rhs);
179
180 bool
181 operator<(const top_of_book &lhs, const top_of_book &rhs);
182
183 template <>
185 {
186 static const top_of_book value;
187 };
188 template <>
190 {
191 static const top_of_book value;
192 };
193 template <>
195 {
196 static const top_of_book value;
197 };
198
199 std::ostream &
200 operator<<(std::ostream &os, const top_of_book &obe);
201
203 operator+(const top_of_book &lhs, const top_of_book &rhs);
204
206 operator-(const top_of_book &lhs, const top_of_book &rhs);
207
209 operator*=(const top_of_book &lhs, const top_of_book &rhs);
210
212 operator/=(const top_of_book &lhs, const top_of_book &rhs);
213
214 bool
215 operator<(const top_of_book &lhs, const top_of_book &rhs);
216
217 static top_of_book
218 get_missing_top_of_book();
219
220 } // end value_types namespace
221
222 class OrderBookEvent : public tom::scalar<tom::value_types::order_book_event>
223 {
224 public:
229
235
236 virtual ~OrderBookEvent();
237
239 operator=(const OrderBookEvent &);
240
241 virtual OrderBookEvent &
242 operator=(const tom::value_types::order_book_event &);
243
244 virtual OrderBookEvent &
246
247 virtual tom::value_type
248 flag() const;
249
250 virtual bool
251 is_normal() const;
252
253 virtual observation &operator+=(const observation &);
254 virtual observation &operator-=(const observation &);
255 virtual observation &operator*=(const observation &);
256 virtual observation &operator/=(const observation &);
257
258 virtual bool operator<(const observation &) const;
259 virtual bool operator<=(const observation &) const;
260 virtual bool operator>(const observation &) const;
261 virtual bool operator>=(const observation &) const;
262
263 virtual bool operator==(const observation &) const;
264 virtual bool operator!=(const observation &) const;
265
266 virtual std::ostream &print(std::ostream &) const;
267
268 virtual operator unsigned char() const;
269 virtual operator tom::value_types::string() const;
270 virtual operator short int() const;
271 virtual operator int() const;
272 virtual operator long int() const;
273 virtual operator unsigned short int() const;
274 virtual operator unsigned int() const;
275 virtual operator unsigned long int() const;
276 virtual operator float() const;
277 virtual operator double() const;
278
279 // special case, as there is no real bool!
280 // just an unsigned char to hold bool + flags
281 virtual operator bool() const;
282
284 value() const { return m_value; }
285
286 size_t
287 size() const { return sizeof(m_value); }
288
289 public:
290 value_type m_value;
291 };
292
293 class TopOfBook : public tom::scalar<tom::value_types::top_of_book>
294 {
295 public:
300
301 TopOfBook();
302 TopOfBook(const tom::TopOfBook &);
305 TopOfBook( const tom::observation &);
306
307 virtual ~TopOfBook();
308
309 TopOfBook &
310 operator=(const TopOfBook &);
311
312 virtual TopOfBook &
313 operator=(const tom::value_types::top_of_book &);
314
315 virtual TopOfBook &
317
318 virtual tom::value_type
319 flag() const;
320
321 virtual bool
322 is_normal() const;
323
324 virtual observation &operator+=(const observation &);
325 virtual observation &operator-=(const observation &);
326 virtual observation &operator*=(const observation &);
327 virtual observation &operator/=(const observation &);
328
329 virtual bool operator<(const observation &) const;
330 virtual bool operator<=(const observation &) const;
331 virtual bool operator>(const observation &) const;
332 virtual bool operator>=(const observation &) const;
333
334 virtual bool operator==(const observation &) const;
335 virtual bool operator!=(const observation &) const;
336
337 virtual std::ostream &print(std::ostream &) const;
338
339 virtual operator unsigned char() const;
340 virtual operator tom::value_types::string() const;
341 virtual operator short int() const;
342 virtual operator int() const;
343 virtual operator long int() const;
344 virtual operator unsigned short int() const;
345 virtual operator unsigned int() const;
346 virtual operator unsigned long int() const;
347 virtual operator float() const;
348 virtual operator double() const;
349
350 // special case, as there is no real bool!
351 // just an unsigned char to hold bool + flags
352 virtual operator bool() const;
353
355 value() const { return m_value; }
356
357 size_t
358 size() const { return sizeof(m_value); }
359
360 public:
361 value_type m_value;
362 };
363
364 namespace
365 {
366
367 template <>
369 cast_observation_(const observation &v)
370 {
372 return obe;
373 }
374 template <>
376 cast_observation_(const observation &v)
377 {
379 return obe;
380 }
381
382 } // end anonymous namespace
383
384};
385
386#endif // HAVE_TOM_UTIL_ORDER_BOOK_EVENT_HPP
Definition order_book_event.hpp:223
Definition order_book_event.hpp:294
Definition observation.hpp:13
Definition scalar.hpp:19
Definition order_book_event.hpp:36
Definition value_types.hpp:96
Definition order_book_event.hpp:118
Definition value_types.hpp:144
Definition value_types.hpp:324
Definition value_types.hpp:319
Definition value_types.hpp:329