OnixS C++ CME MDP Premium Market Data Handler  5.8.3
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 public:
38  /// Initializes instance indicating
39  /// absence of consolidated data.
41  : direct_(null())
42  , implied_(null())
43  {
44  }
45 
46  /// Initializes instance from direct price level only.
48  : direct_(&direct)
49  , implied_(null())
50  {
51  }
52 
53  /// Initializes instance from implied price level only.
55  : direct_(null())
56  , implied_(&implied)
57  {
58  }
59 
60  /// Initializes instance from both
61  /// direct and implied price levels.
63  : direct_(&direct)
64  , implied_(&implied)
65  {
66  }
67 
68  /// Initializes instance as copy of the other one.
70  : direct_(other.direct_)
71  , implied_(other.implied_)
72  {
73  }
74 
75  /// Finalizes instance.
77 
78  /// Indicates whether instance has a valid data
79  /// and actually exists at the level accessed.
80  bool exist() const
81  {
82  return (direct_->exist() || implied_->exist());
83  }
84 
85  /// Price component.
86  const Decimal& price() const
87  {
88  return (direct_->exist() ? direct_->price() : implied_->price());
89  }
90 
91  /// Quantity component.
92  Int32 quantity() const
93  {
94  return (direct_->quantity() + implied_->quantity());
95  }
96 
97  /// Reference to price level from direct
98  /// book consolidated into given instance.
99  ///
100  /// Use 'exist' member of returned reference
101  /// to check whether returned instance refers
102  /// to a valid data or there were no corresponding
103  /// level available in direct book.
104  const DirectPriceLevel& direct() const
105  {
106  return *direct_;
107  }
108 
109  /// Consolidates direct price level data part.
110  void consolidate(const DirectPriceLevel& direct)
111  {
112  direct_ = &direct;
113  }
114 
115  /// Reference to price level from implied
116  /// book consolidated into given instance.
117  ///
118  /// Use 'exist' member of returned reference
119  /// to check whether returned instance refers
120  /// to a valid data or there were no corresponding
121  /// level available in implied book.
122  const ImpliedPriceLevel& implied() const
123  {
124  return *implied_;
125  }
126 
127  /// Consolidates implied price level data part.
128  void consolidate(const ImpliedPriceLevel& implied)
129  {
130  implied_ = &implied;
131  }
132 
133  /// Casts instance to implied price level.
134  operator ImpliedPriceLevel() const
135  {
136  if (direct_->exist())
137  {
138  return ImpliedPriceLevel(direct_->price(), quantity());
139  }
140  else
141  {
142  return *implied_;
143  }
144  }
145 
146  /// Re-initializes instance as copy of other one.
148  {
149  direct_ = other.direct_;
150  implied_ = other.implied_;
151 
152  return *this;
153  }
154 
155 private:
156  // Direct price level component.
157  const DirectPriceLevel* direct_;
158 
159  // Implied price level component.
160  const ImpliedPriceLevel* implied_;
161 
162  // Used to make all references as a valid ones.
164  static const DirectPriceLevel* null();
165 };
166 
167 /// Serializes price level attributes into a string.
169 void toStr(std::string&, const ConsolidatedPriceLevel&);
170 
171 /// Serializes price level attributes into a string.
172 inline std::string toStr(const ConsolidatedPriceLevel& priceLevel)
173 {
174  std::string str;
175 
176  toStr(str, priceLevel);
177 
178  return str;
179 }
180 
std::string toStr(const ConsolidatedPriceLevel &priceLevel)
Serializes price level attributes into a string.
Encapsulates price level concept.
ConsolidatedPriceLevel & operator=(const ConsolidatedPriceLevel &other)
Re-initializes instance as copy of other one.
Int32 Int32
int32.
Definition: Fields.h:60
ConsolidatedPriceLevel(const DirectPriceLevel &direct, const ImpliedPriceLevel &implied)
Initializes instance from both direct and implied price levels.
void consolidate(const DirectPriceLevel &direct)
Consolidates direct price level data part.
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
const DirectPriceLevel & direct() const
Reference to price level from direct book consolidated into given instance.
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.
Price level data attributes of bid or ask of consolidated order book.
A real number with floating exponent.
Definition: Decimal.h:136
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
Int32 quantity() const
Quantity component.
ConsolidatedPriceLevel(const DirectPriceLevel &direct)
Initializes instance from direct price level only.
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:135
bool exist() const
Indicates whether instance has a valid data and actually exists at the level accessed.
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition: Bootstrap.h:47
ConsolidatedPriceLevel()
Initializes instance indicating absence of consolidated data.
const ImpliedPriceLevel & implied() const
Reference to price level from implied book consolidated into given instance.
const Decimal & price() const
Price component.
ConsolidatedPriceLevel(const ConsolidatedPriceLevel &other)
Initializes instance as copy of the other one.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68