CppTrader  1.0.4.0
C++ Trader
level.h
Go to the documentation of this file.
1 
9 #ifndef CPPTRADER_MATCHING_LEVEL_H
10 #define CPPTRADER_MATCHING_LEVEL_H
11 
12 #include "order.h"
13 #include "update.h"
14 
15 #include "containers/bintree_avl.h"
16 
17 namespace CppTrader {
18 namespace Matching {
19 
21 enum class LevelType : uint8_t
22 {
23  BID,
24  ASK
25 };
26 
27 template <class TOutputStream>
28 TOutputStream& operator<<(TOutputStream& stream, LevelType type);
29 
31 struct Level
32 {
36  uint64_t Price;
38  uint64_t TotalVolume;
40  uint64_t HiddenVolume;
42  uint64_t VisibleVolume;
44  size_t Orders;
45 
46  Level(LevelType type, uint64_t price) noexcept;
47  Level(const Level&) noexcept = default;
48  Level(Level&&) noexcept = default;
49  ~Level() noexcept = default;
50 
51  Level& operator=(const Level&) noexcept = default;
52  Level& operator=(Level&&) noexcept = default;
53 
54  // Price level comparison
55  friend bool operator==(const Level& level1, const Level& level2) noexcept
56  { return level1.Price == level2.Price; }
57  friend bool operator!=(const Level& level1, const Level& level2) noexcept
58  { return level1.Price != level2.Price; }
59  friend bool operator<(const Level& level1, const Level& level2) noexcept
60  { return level1.Price < level2.Price; }
61  friend bool operator>(const Level& level1, const Level& level2) noexcept
62  { return level1.Price > level2.Price; }
63  friend bool operator<=(const Level& level1, const Level& level2) noexcept
64  { return level1.Price <= level2.Price; }
65  friend bool operator>=(const Level& level1, const Level& level2) noexcept
66  { return level1.Price >= level2.Price; }
67 
68  template <class TOutputStream>
69  friend TOutputStream& operator<<(TOutputStream& stream, const Level& level);
70 
72  bool IsBid() const noexcept { return Type == LevelType::BID; }
74  bool IsAsk() const noexcept { return Type == LevelType::ASK; }
75 };
76 
78 struct LevelNode : public Level, public CppCommon::BinTreeAVL<LevelNode>::Node
79 {
81  CppCommon::List<OrderNode> OrderList;
82 
83  LevelNode(LevelType type, uint64_t price) noexcept;
84  LevelNode(const Level& level) noexcept;
85  LevelNode(const LevelNode&) noexcept = default;
86  LevelNode(LevelNode&&) noexcept = default;
87  ~LevelNode() noexcept = default;
88 
89  LevelNode& operator=(const Level& level) noexcept;
90  LevelNode& operator=(const LevelNode&) noexcept = default;
91  LevelNode& operator=(LevelNode&&) noexcept = default;
92 
93  // Price level comparison
94  friend bool operator==(const LevelNode& level1, const LevelNode& level2) noexcept
95  { return level1.Price == level2.Price; }
96  friend bool operator!=(const LevelNode& level1, const LevelNode& level2) noexcept
97  { return level1.Price != level2.Price; }
98  friend bool operator<(const LevelNode& level1, const LevelNode& level2) noexcept
99  { return level1.Price < level2.Price; }
100  friend bool operator>(const LevelNode& level1, const LevelNode& level2) noexcept
101  { return level1.Price > level2.Price; }
102  friend bool operator<=(const LevelNode& level1, const LevelNode& level2) noexcept
103  { return level1.Price <= level2.Price; }
104  friend bool operator>=(const LevelNode& level1, const LevelNode& level2) noexcept
105  { return level1.Price >= level2.Price; }
106 };
107 
110 {
116  bool Top;
117 
118  LevelUpdate(UpdateType type, const Level& update, bool top) noexcept;
119  LevelUpdate(const LevelUpdate&) noexcept = default;
120  LevelUpdate(LevelUpdate&&) noexcept = default;
121  ~LevelUpdate() noexcept = default;
122 
123  LevelUpdate& operator=(const LevelUpdate&) noexcept = default;
124  LevelUpdate& operator=(LevelUpdate&&) noexcept = default;
125 
126  template <class TOutputStream>
127  friend TOutputStream& operator<<(TOutputStream& stream, const LevelUpdate& update);
128 };
129 
130 } // namespace Matching
131 } // namespace CppTrader
132 
133 #include "level.inl"
134 
135 #endif // CPPTRADER_MATCHING_LEVEL_H
LevelType
Price level type.
Definition: level.h:22
TOutputStream & operator<<(TOutputStream &stream, ErrorCode error)
Definition: errors.inl:13
UpdateType
Update type.
Definition: update.h:21
C++ Trader project definitions.
Definition: errors.h:16
Order definition.
Price level.
Definition: level.h:32
bool IsBid() const noexcept
Is the bid price level?
Definition: level.h:72
friend bool operator!=(const Level &level1, const Level &level2) noexcept
Definition: level.h:57
size_t Orders
Level orders.
Definition: level.h:44
friend bool operator<=(const Level &level1, const Level &level2) noexcept
Definition: level.h:63
friend bool operator>(const Level &level1, const Level &level2) noexcept
Definition: level.h:61
uint64_t TotalVolume
Level volume.
Definition: level.h:38
Level(const Level &) noexcept=default
Level(Level &&) noexcept=default
LevelType Type
Level type.
Definition: level.h:34
Level(LevelType type, uint64_t price) noexcept
Definition: level.inl:30
uint64_t HiddenVolume
Level hidden volume.
Definition: level.h:40
friend TOutputStream & operator<<(TOutputStream &stream, const Level &level)
Definition: level.inl:41
uint64_t Price
Level price.
Definition: level.h:36
friend bool operator>=(const Level &level1, const Level &level2) noexcept
Definition: level.h:65
uint64_t VisibleVolume
Level visible volume.
Definition: level.h:42
friend bool operator<(const Level &level1, const Level &level2) noexcept
Definition: level.h:59
bool IsAsk() const noexcept
Is the ask price level?
Definition: level.h:74
Price level node.
Definition: level.h:79
friend bool operator<=(const LevelNode &level1, const LevelNode &level2) noexcept
Definition: level.h:102
friend bool operator<(const LevelNode &level1, const LevelNode &level2) noexcept
Definition: level.h:98
CppCommon::List< OrderNode > OrderList
Price level orders.
Definition: level.h:81
friend bool operator>=(const LevelNode &level1, const LevelNode &level2) noexcept
Definition: level.h:104
friend bool operator!=(const LevelNode &level1, const LevelNode &level2) noexcept
Definition: level.h:96
friend bool operator>(const LevelNode &level1, const LevelNode &level2) noexcept
Definition: level.h:100
LevelNode(LevelNode &&) noexcept=default
LevelNode(LevelType type, uint64_t price) noexcept
Definition: level.inl:53
LevelNode(const LevelNode &) noexcept=default
Price level update.
Definition: level.h:110
Level Update
Level update value.
Definition: level.h:114
LevelUpdate(LevelUpdate &&) noexcept=default
bool Top
Top of the book flag.
Definition: level.h:116
LevelUpdate(const LevelUpdate &) noexcept=default
LevelUpdate(UpdateType type, const Level &update, bool top) noexcept
Definition: level.inl:69
UpdateType Type
Update type.
Definition: level.h:112
Update definition.