OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
MboBook.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
25 
27 
28 /// Private base for MBO book.
29 ///
30 /// Manages internals related with
31 /// efficient order entry allocation.
33 {
34 protected:
35  /// Instantiates allocator using MemoryPool for orders.
37 
38  /// Initializes with privately maintained memory pool.
40  : pool_(*makeMemoryPool(64, 1, 20, 1))
41  , releasePool_(true)
42  {
43  }
44 
45  /// Binds to given memory pool.
46  MboBookBase(MemoryPool& sharedPool)
47  : pool_(sharedPool)
48  , releasePool_(false)
49  {
50  }
51 
52  /// Releases memory pool according to policy.
54  {
55  if (releasePool_)
56  pool_.release();
57  }
58 
59  /// Allocator over memory pool.
60  OrderAllocator allocator() const
61  {
62  return OrderAllocator(pool_);
63  }
64 
65 private:
66  MemoryPool& pool_;
67  const bool releasePool_;
68 };
69 
70 /// Market By Order book.
72 {
73 public:
74  /// Order as book entry.
75  typedef Order Entry;
76 
77  /// Book depth type.
78  typedef SortedOrders::size_type Depth;
79 
80  /// Sorted orders are book entries.
82 
83  /// Iterator over bids and offers.
84  typedef Entries::const_iterator EntryIterator;
85 
86  /// Initializes blank order book.
88  : state_(BookState::Constructed)
89  , bids_(allocator())
90  , offers_(allocator())
91  {
92  }
93 
94  /// Initializes book using given memory pool.
96  : MboBookBase(pool)
97  , state_(BookState::Constructed)
98  , bids_(allocator())
99  , offers_(allocator())
100  {
101  }
102 
103  /// Initializes as copy of other book.
104  MboBook(const MboBook& other)
105  : MboBookBase()
106  , state_(other.state())
107  , bids_(allocator())
108  , offers_(allocator())
109  {
110  bids_ = other.bids();
111  offers_ = other.offers();
112  }
113 
114  /// Disposes allocated resources.
115  ~MboBook() {}
116 
117  /// List of descending bid prices.
118  Entries& bids()
119  {
120  return bids_;
121  }
122 
123  /// List of descending bid prices.
124  Entries& operator[](const Bids&)
125  {
126  return bids_;
127  }
128 
129  /// List of descending bid prices.
130  const Entries& bids() const
131  {
132  return bids_;
133  }
134 
135  /// List of descending bid prices.
136  const Entries& operator[](const Bids&) const
137  {
138  return bids_;
139  }
140 
141  /// List of ascending offer prices.
142  Entries& offers()
143  {
144  return offers_;
145  }
146 
147  /// List of ascending offer prices.
148  Entries& operator[](const Offers&)
149  {
150  return offers_;
151  }
152 
153  /// List of ascending offer prices.
154  const Entries& offers() const
155  {
156  return offers_;
157  }
158 
159  /// List of ascending offer prices.
160  const Entries& operator[](const Offers&) const
161  {
162  return offers_;
163  }
164 
165  /// Indicates current state of book.
167  {
168  return state_;
169  }
170 
171  /// Updates state of book.
172  void state(BookState::Enum state)
173  {
174  state_ = state;
175  }
176 
177  /// Wipes out all bids and offers and other
178  /// data associated with book (like instance
179  /// of last applied FIX message).
180  void reset(BookState::Enum bookState)
181  {
182  state(bookState);
183 
184  bids_.clear();
185  offers_.clear();
186  }
187 
188  /// Re-initializes as copy of other instance.
189  MboBook& operator=(const MboBook& other)
190  {
191  if (this != &other)
192  {
193  state_ = other.state();
194 
195  bids_ = other.bids();
196  offers_ = other.offers();
197  }
198 
199  return *this;
200  }
201 
202 private:
203  BookState::Enum state_;
204 
205  SortedOrders bids_;
206  SortedOrders offers_;
207 };
208 
209 /// Copies content of MBO book to the other one.
210 inline MboBook& copy(MboBook& target, const MboBook& source)
211 {
212  target = source;
213  return target;
214 }
215 
216 /// Book brief info.
218 void brief(std::string&, const MboBook&);
219 
220 /// Book brief info.
221 inline std::string brief(const MboBook& book)
222 {
223  std::string str;
224 
225  brief(str, book);
226 
227  return str;
228 }
229 
230 /// Serializes book.
232 void toStr(std::string&, const MboBook&);
233 
234 /// Serializes book.
235 inline std::string toStr(const MboBook& book)
236 {
237  std::string str;
238 
239  toStr(str, book);
240 
241  return str;
242 }
243 
244 /// Serializes book in formatted form.
246 void toFormattedStr(std::string&, const MboBook&);
247 
248 /// Serializes book in formatted form.
249 inline std::string toFormattedStr(const MboBook& book)
250 {
251  std::string str;
252 
253  toFormattedStr(str, book);
254 
255  return str;
256 }
257 
Order Entry
Order as book entry.
Definition: MboBook.h:75
~MboBook()
Disposes allocated resources.
Definition: MboBook.h:115
MboBookBase()
Initializes with privately maintained memory pool.
Definition: MboBook.h:39
OrderAllocator allocator() const
Allocator over memory pool.
Definition: MboBook.h:60
SortedOrders Entries
Sorted orders are book entries.
Definition: MboBook.h:81
Tag class for accessing bids in templates.
void reset(BookState::Enum bookState)
Wipes out all bids and offers and other data associated with book (like instance of last applied FIX ...
Definition: MboBook.h:180
BookState::Enum state() const
Indicates current state of book.
Definition: MboBook.h:166
void brief(std::string &, const ConsolidatedBook &)
Book brief info.
Entries::const_iterator EntryIterator
Iterator over bids and offers.
Definition: MboBook.h:84
MboBook & operator=(const MboBook &other)
Re-initializes as copy of other instance.
Definition: MboBook.h:189
MboBook(MemoryPool &pool)
Initializes book using given memory pool.
Definition: MboBook.h:95
Order as the member of the Market By Order (MBO) book.
Definition: Order.h:72
Memory pool abstraction.
Definition: MemoryPool.h:35
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
std::list< Order, MemoryPoolAllocator< Order > > SortedOrders
Arranged collection of orders.
Definition: MboBookTraits.h:31
MboBook & copy(MboBook &target, const MboBook &source)
Copies content of MBO book to the other one.
Definition: MboBook.h:210
Entries & operator[](const Bids &)
List of descending bid prices.
Definition: MboBook.h:124
MemoryPool * makeMemoryPool(size_t, size_t, size_t, size_t)
Constructs a memory pool instance according to the given configuration.
MemoryPoolAllocator< Order > OrderAllocator
Instantiates allocator using MemoryPool for orders.
Definition: MboBook.h:36
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
MboBookBase(MemoryPool &sharedPool)
Binds to given memory pool.
Definition: MboBook.h:46
SortedOrders::size_type Depth
Book depth type.
Definition: MboBook.h:78
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:135
Private base for MBO book.
Definition: MboBook.h:32
MboBook()
Initializes blank order book.
Definition: MboBook.h:87
~MboBookBase()
Releases memory pool according to policy.
Definition: MboBook.h:53
void toFormattedStr(std::string &, const ConsolidatedBook &)
Serializes book in formatted form.
const Entries & bids() const
List of descending bid prices.
Definition: MboBook.h:130
const Entries & operator[](const Bids &) const
List of descending bid prices.
Definition: MboBook.h:136
Entries & operator[](const Offers &)
List of ascending offer prices.
Definition: MboBook.h:148
void state(BookState::Enum state)
Updates state of book.
Definition: MboBook.h:172
State of order book.
Entries & bids()
List of descending bid prices.
Definition: MboBook.h:118
const Entries & operator[](const Offers &) const
List of ascending offer prices.
Definition: MboBook.h:160
Entries & offers()
List of ascending offer prices.
Definition: MboBook.h:142
Tag class for accessing offers in templates.
Market By Order book.
Definition: MboBook.h:71
const Entries & offers() const
List of ascending offer prices.
Definition: MboBook.h:154
MboBook(const MboBook &other)
Initializes as copy of other book.
Definition: MboBook.h:104
void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68