|
4 | 4 | #include <cstddef> // size_t |
5 | 5 | #include <cstdint> |
6 | 6 |
|
7 | | -#include "databento/constants.hpp" // kSymbolCstrLen |
8 | | -#include "databento/datetime.hpp" // UnixNanos |
9 | | -#include "databento/enums.hpp" |
10 | | -#include "databento/record.hpp" |
| 7 | +#include "databento/v1.hpp" |
| 8 | +#include "databento/v2.hpp" |
11 | 9 |
|
12 | 10 | namespace databento { |
13 | | -static constexpr std::size_t kSymbolCstrLenV1 = 22; |
14 | | -static constexpr std::size_t kSymbolCstrLenV2 = kSymbolCstrLen; |
| 11 | +static constexpr std::size_t kSymbolCstrLenV1 = v1::kSymbolCstrLen; |
| 12 | +static constexpr std::size_t kSymbolCstrLenV2 = v2::kSymbolCstrLen; |
15 | 13 |
|
16 | 14 | constexpr std::size_t VersionSymbolCstrLen(std::uint8_t version) { |
17 | 15 | return version < 2 ? kSymbolCstrLenV1 : kSymbolCstrLenV2; |
18 | 16 | } |
19 | 17 |
|
20 | | -using InstrumentDefMsgV2 = InstrumentDefMsg; |
21 | | -using ErrorMsgV2 = ErrorMsg; |
22 | | -using SymbolMappingMsgV2 = SymbolMappingMsg; |
23 | | -using SystemMsgV2 = SystemMsg; |
24 | | - |
| 18 | +using InstrumentDefMsgV1 = v1::InstrumentDefMsg; |
| 19 | +using InstrumentDefMsgV2 = v2::InstrumentDefMsg; |
| 20 | +using ErrorMsgV1 = v1::ErrorMsg; |
| 21 | +using ErrorMsgV2 = v2::ErrorMsg; |
| 22 | +using SymbolMappingMsgV1 = v1::SymbolMappingMsg; |
| 23 | +using SymbolMappingMsgV2 = v2::SymbolMappingMsg; |
| 24 | +using SystemMsgV1 = v1::SystemMsg; |
| 25 | +using SystemMsgV2 = v2::SystemMsg; |
25 | 26 | // DBN version 1 instrument definition. |
26 | | -struct InstrumentDefMsgV1 { |
27 | | - static bool HasRType(RType rtype) { return rtype == RType::InstrumentDef; } |
28 | | - |
29 | | - InstrumentDefMsgV2 ToV2() const; |
30 | | - const char* Currency() const { return currency.data(); } |
31 | | - const char* SettlCurrency() const { return settl_currency.data(); } |
32 | | - const char* SecSubType() const { return secsubtype.data(); } |
33 | | - const char* RawSymbol() const { return raw_symbol.data(); } |
34 | | - const char* Group() const { return group.data(); } |
35 | | - const char* Exchange() const { return exchange.data(); } |
36 | | - const char* Asset() const { return asset.data(); } |
37 | | - const char* Cfi() const { return cfi.data(); } |
38 | | - const char* SecurityType() const { return security_type.data(); } |
39 | | - const char* UnitOfMeasure() const { return unit_of_measure.data(); } |
40 | | - const char* Underlying() const { return underlying.data(); } |
41 | | - const char* StrikePriceCurrency() const { |
42 | | - return strike_price_currency.data(); |
43 | | - } |
44 | | - |
45 | | - RecordHeader hd; |
46 | | - UnixNanos ts_recv; |
47 | | - std::int64_t min_price_increment; |
48 | | - std::int64_t display_factor; |
49 | | - UnixNanos expiration; |
50 | | - UnixNanos activation; |
51 | | - std::int64_t high_limit_price; |
52 | | - std::int64_t low_limit_price; |
53 | | - std::int64_t max_price_variation; |
54 | | - std::int64_t trading_reference_price; |
55 | | - std::int64_t unit_of_measure_qty; |
56 | | - std::int64_t min_price_increment_amount; |
57 | | - std::int64_t price_ratio; |
58 | | - std::int32_t inst_attrib_value; |
59 | | - std::uint32_t underlying_id; |
60 | | - std::uint32_t raw_instrument_id; |
61 | | - std::int32_t market_depth_implied; |
62 | | - std::int32_t market_depth; |
63 | | - std::uint32_t market_segment_id; |
64 | | - std::uint32_t max_trade_vol; |
65 | | - std::int32_t min_lot_size; |
66 | | - std::int32_t min_lot_size_block; |
67 | | - std::int32_t min_lot_size_round_lot; |
68 | | - std::uint32_t min_trade_vol; |
69 | | - std::array<char, 4> _reserved2; |
70 | | - std::int32_t contract_multiplier; |
71 | | - std::int32_t decay_quantity; |
72 | | - std::int32_t original_contract_size; |
73 | | - std::array<char, 4> _reserved3; |
74 | | - std::uint16_t trading_reference_date; |
75 | | - std::int16_t appl_id; |
76 | | - std::uint16_t maturity_year; |
77 | | - std::uint16_t decay_start_date; |
78 | | - std::uint16_t channel_id; |
79 | | - std::array<char, 4> currency; |
80 | | - std::array<char, 4> settl_currency; |
81 | | - std::array<char, 6> secsubtype; |
82 | | - std::array<char, kSymbolCstrLenV1> raw_symbol; |
83 | | - std::array<char, 21> group; |
84 | | - std::array<char, 5> exchange; |
85 | | - std::array<char, 7> asset; |
86 | | - std::array<char, 7> cfi; |
87 | | - std::array<char, 7> security_type; |
88 | | - std::array<char, 31> unit_of_measure; |
89 | | - std::array<char, 21> underlying; |
90 | | - std::array<char, 4> strike_price_currency; |
91 | | - InstrumentClass instrument_class; |
92 | | - std::array<char, 2> _reserved4; |
93 | | - std::int64_t strike_price; |
94 | | - std::array<char, 6> _reserved5; |
95 | | - MatchAlgorithm match_algorithm; |
96 | | - std::uint8_t md_security_trading_status; |
97 | | - std::uint8_t main_fraction; |
98 | | - std::uint8_t price_display_format; |
99 | | - std::uint8_t settl_price_type; |
100 | | - std::uint8_t sub_fraction; |
101 | | - std::uint8_t underlying_product; |
102 | | - SecurityUpdateAction security_update_action; |
103 | | - std::uint8_t maturity_month; |
104 | | - std::uint8_t maturity_day; |
105 | | - std::uint8_t maturity_week; |
106 | | - UserDefinedInstrument user_defined_instrument; |
107 | | - std::int8_t contract_multiplier_unit; |
108 | | - std::int8_t flow_schedule_type; |
109 | | - std::uint8_t tick_rule; |
110 | | - // padding for alignment |
111 | | - std::array<char, 3> dummy; |
112 | | -}; |
113 | | -static_assert(sizeof(InstrumentDefMsgV1) == 360, "Size must match Rust"); |
114 | | -static_assert(alignof(InstrumentDefMsgV1) == 8, "Must have 8-byte alignment"); |
115 | | - |
116 | | -// An error message from the Live Subscription Gateway (LSG). This will never |
117 | | -// be present in historical data. |
118 | | -struct ErrorMsgV1 { |
119 | | - static bool HasRType(RType rtype) { return rtype == RType::Error; } |
120 | | - |
121 | | - ErrorMsgV2 ToV2() const; |
122 | | - UnixNanos IndexTs() const { return hd.ts_event; } |
123 | | - const char* Err() const { return err.data(); } |
124 | | - |
125 | | - RecordHeader hd; |
126 | | - std::array<char, 64> err; |
127 | | -}; |
128 | | -static_assert(sizeof(ErrorMsgV1) == 80, "ErrorMsg size must match Rust"); |
129 | | -static_assert(alignof(ErrorMsgV1) == 8, "Must have 8-byte alignment"); |
130 | | - |
131 | | -/// A symbol mapping message. |
132 | | -struct SymbolMappingMsgV1 { |
133 | | - static bool HasRType(RType rtype) { return rtype == RType::SymbolMapping; } |
134 | | - |
135 | | - SymbolMappingMsgV2 ToV2() const; |
136 | | - const char* STypeInSymbol() const { return stype_in_symbol.data(); } |
137 | | - const char* STypeOutSymbol() const { return stype_out_symbol.data(); } |
138 | | - |
139 | | - RecordHeader hd; |
140 | | - std::array<char, kSymbolCstrLenV1> stype_in_symbol; |
141 | | - std::array<char, kSymbolCstrLenV1> stype_out_symbol; |
142 | | - // padding for alignment |
143 | | - std::array<char, 4> dummy; |
144 | | - UnixNanos start_ts; |
145 | | - UnixNanos end_ts; |
146 | | -}; |
147 | | -static_assert(sizeof(SymbolMappingMsgV1) == 80, "Size must match Rust"); |
148 | | -static_assert(alignof(SymbolMappingMsgV1) == 8, "Must have 8-byte alignment"); |
149 | | - |
150 | | -struct SystemMsgV1 { |
151 | | - static bool HasRType(RType rtype) { return rtype == RType::System; } |
152 | | - |
153 | | - SystemMsgV2 ToV2() const; |
154 | | - UnixNanos IndexTs() const { return hd.ts_event; } |
155 | | - const char* Msg() const { return msg.data(); } |
156 | | - bool IsHeartbeat() const { |
157 | | - return std::strncmp(msg.data(), "Heartbeat", 9) == 0; |
158 | | - } |
159 | | - |
160 | | - RecordHeader hd; |
161 | | - std::array<char, 64> msg; |
162 | | -}; |
163 | | -static_assert(sizeof(SystemMsgV1) == 80, "SystemMsg size must match Rust"); |
164 | | -static_assert(alignof(SystemMsgV1) == 8, "Must have 8-byte alignment"); |
165 | | - |
166 | | -bool operator==(const InstrumentDefMsgV1& lhs, const InstrumentDefMsgV1& rhs); |
167 | | -inline bool operator!=(const InstrumentDefMsgV1& lhs, |
168 | | - const InstrumentDefMsgV1& rhs) { |
169 | | - return !(lhs == rhs); |
170 | | -} |
171 | | -inline bool operator==(const ErrorMsgV1& lhs, const ErrorMsgV1& rhs) { |
172 | | - return std::tie(lhs.hd, lhs.err) == std::tie(rhs.hd, rhs.err); |
173 | | -} |
174 | | -inline bool operator!=(const ErrorMsgV1& lhs, const ErrorMsgV1& rhs) { |
175 | | - return !(lhs == rhs); |
176 | | -} |
177 | | -inline bool operator==(const SymbolMappingMsgV1& lhs, |
178 | | - const SymbolMappingMsgV1& rhs) { |
179 | | - return std::tie(lhs.hd, lhs.stype_in_symbol, lhs.stype_out_symbol, |
180 | | - lhs.start_ts, lhs.end_ts) == |
181 | | - std::tie(rhs.hd, rhs.stype_in_symbol, rhs.stype_out_symbol, |
182 | | - rhs.start_ts, rhs.end_ts); |
183 | | -} |
184 | | -inline bool operator!=(const SymbolMappingMsgV1& lhs, |
185 | | - const SymbolMappingMsgV1& rhs) { |
186 | | - return !(lhs == rhs); |
187 | | -} |
188 | | -inline bool operator==(const SystemMsgV1& lhs, const SystemMsgV1& rhs) { |
189 | | - return std::tie(lhs.hd, lhs.msg) == std::tie(rhs.hd, rhs.msg); |
190 | | -} |
191 | | -inline bool operator!=(const SystemMsgV1& lhs, const SystemMsgV1& rhs) { |
192 | | - return !(lhs == rhs); |
193 | | -} |
194 | | -std::string ToString(const InstrumentDefMsgV1& instr_def_msg); |
195 | | -std::ostream& operator<<(std::ostream& stream, |
196 | | - const InstrumentDefMsgV1& instr_def_msg); |
197 | | -std::string ToString(const ErrorMsgV1& err_msg); |
198 | | -std::ostream& operator<<(std::ostream& stream, const ErrorMsgV1& err_msg); |
199 | | -std::string ToString(const SymbolMappingMsgV1& symbol_mapping_msg); |
200 | | -std::ostream& operator<<(std::ostream& stream, |
201 | | - const SymbolMappingMsgV1& symbol_mapping_msg); |
202 | | -std::string ToString(const SystemMsgV1& sys_msg); |
203 | | -std::ostream& operator<<(std::ostream& stream, const SystemMsgV1& sys_msg); |
204 | 27 | } // namespace databento |
0 commit comments