OnixS C++ CME Market Data Handler  5.4.0
API documentation
ConsolidatedPriceLevel.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 /// Price level data attributes of bid
29 /// or ask of consolidated order book.
30 ///
31 /// Instance exposes consolidated price
32 /// level data as well as provides references
33 /// to price level from direct and implied order
34 /// books which comply consolidated price level.
36 {
37  // Direct price level component.
38  const DirectPriceLevel* direct_;
39 
40  // Implied price level component.
41  const ImpliedPriceLevel* implied_;
42 
43  // Used to make all references as a valid ones.
45  static
46  const
48  null()
49  {
50  static const
51  DirectPriceLevel null_;
52 
53  return &null_;
54  }
55 
56 public:
57  /// Initializes instance indicating
58  /// absence of consolidated data.
60  : direct_(null())
61  , implied_(null())
62  {
63  }
64 
65  /// Initializes instance from direct price level only.
67  const DirectPriceLevel& direct)
68  : direct_(&direct), implied_(null())
69  {
70  }
71 
72  /// Initializes instance from implied price level only.
74  const ImpliedPriceLevel& implied)
75  : direct_(null()), implied_(&implied)
76  {
77  }
78 
79  /// Initializes instance from both
80  /// direct and implied price levels.
82  const DirectPriceLevel& direct,
83  const ImpliedPriceLevel& implied)
84  : direct_(&direct), implied_(&implied)
85  {
86  }
87 
88  /// Initializes instance as copy of the other one.
90  const ConsolidatedPriceLevel& other)
91  : direct_(other.direct_)
92  , implied_(other.implied_)
93  {
94  }
95 
96  /// Finalizes instance.
98  {
99  }
100 
101  /// Indicates whether instance has a valid data
102  /// and actually exists at the level accessed.
103  bool exist() const
104  {
105  return (
106  direct_->exist() ||
107  implied_->exist()
108  );
109  }
110 
111  /// Price component.
112  const Decimal& price() const
113  {
114  return (
115  direct_->exist()
116  ? direct_->price()
117  : implied_->price()
118  );
119  }
120 
121  /// Quantity component.
122  Int32 quantity() const
123  {
124  return (
125  direct_->quantity() +
126  implied_->quantity()
127  );
128  }
129 
130  /// Reference to price level from direct
131  /// book consolidated into given instance.
132  ///
133  /// Use 'exist' member of returned reference
134  /// to check whether returned instance refers
135  /// to a valid data or there were no corresponding
136  /// level available in direct book.
137  const
139  direct() const
140  {
141  return *direct_;
142  }
143 
144  /// Consolidates direct price level data part.
145  void
147  const DirectPriceLevel& direct)
148  {
149  direct_ = &direct;
150  }
151 
152  /// Reference to price level from implied
153  /// book consolidated into given instance.
154  ///
155  /// Use 'exist' member of returned reference
156  /// to check whether returned instance refers
157  /// to a valid data or there were no corresponding
158  /// level available in implied book.
159  const
161  implied() const
162  {
163  return *implied_;
164  }
165 
166  /// Consolidates implied price level data part.
167  void
169  const ImpliedPriceLevel& implied)
170  {
171  implied_ = &implied;
172  }
173 
174  /// Casts instance to implied price level.
175  operator ImpliedPriceLevel() const
176  {
177  if (direct_->exist())
178  {
179  return
181  direct_->price(),
182  quantity());
183  }
184  else
185  {
186  return *implied_;
187  }
188  }
189 
190  /// Re-initializes instance as copy of other one.
192  operator =(
193  const ConsolidatedPriceLevel& other)
194  {
195  direct_ = other.direct_;
196  implied_ = other.implied_;
197 
198  return *this;
199  }
200 };
201 
202 /// Serializes price level attributes into a string.
203 ONIXS_CMEMDH_EXPORTED
204 void
205 toStr(
206  std::string&,
207  const ConsolidatedPriceLevel&);
208 
209 /// Serializes price level attributes into a string.
210 inline
211 std::string
213  const ConsolidatedPriceLevel& priceLevel)
214 {
215  std::string str;
216 
217  toStr(str, priceLevel);
218 
219  return str;
220 }
221 
std::string toStr(const ConsolidatedPriceLevel &priceLevel)
Serializes price level attributes into a string.
Encapsulates price level concept.
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
Int32 quantity() const
Quantify for the given price.
Int32 Int32
int32.
Definition: Fields.h:69
ConsolidatedPriceLevel(const DirectPriceLevel &direct, const ImpliedPriceLevel &implied)
void consolidate(const DirectPriceLevel &direct)
Consolidates direct price level data part.
const DirectPriceLevel & direct() const
ConsolidatedPriceLevel(const ImpliedPriceLevel &implied)
Initializes instance from implied price level only.
Encapsulates price level concept.
void consolidate(const ImpliedPriceLevel &implied)
Consolidates implied price level data part.
const Decimal & price() const
A real number with floating exponent.
Definition: Decimal.h:231
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
Int32 quantity() const
Quantity component.
ConsolidatedPriceLevel(const DirectPriceLevel &direct)
Initializes instance from direct price level only.
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition: Bootstrap.h:102
const ImpliedPriceLevel & implied() const
const Decimal & price() const
Price component.
ConsolidatedPriceLevel(const ConsolidatedPriceLevel &other)
Initializes instance as copy of the other one.
bool exist() const
Identifies whether price level exist.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156