|
| 1 | +// Record definitions from previous DBN versions and helper functions. |
| 2 | +#pragma once |
| 3 | + |
| 4 | +#include <cstddef> // size_t |
| 5 | +#include <cstdint> |
| 6 | + |
| 7 | +#include "databento/constants.hpp" // kSymbolCstrLen |
| 8 | +#include "databento/datetime.hpp" // UnixNanos |
| 9 | +#include "databento/enums.hpp" |
| 10 | +#include "databento/record.hpp" |
| 11 | + |
| 12 | +namespace databento { |
| 13 | +static constexpr std::size_t kSymbolCstrLenV1 = 22; |
| 14 | +static constexpr std::size_t kSymbolCstrLenV2 = kSymbolCstrLen; |
| 15 | + |
| 16 | +constexpr std::size_t VersionSymbolCstrLen(std::uint8_t version) { |
| 17 | + return version < 2 ? kSymbolCstrLenV1 : kSymbolCstrLenV2; |
| 18 | +} |
| 19 | + |
| 20 | +using InstrumentDefMsgV2 = InstrumentDefMsg; |
| 21 | +using SymbolMappingMsgV2 = SymbolMappingMsg; |
| 22 | + |
| 23 | +// DBN version 1 instrument definition. |
| 24 | +struct InstrumentDefMsgV1 { |
| 25 | + static bool HasRType(RType rtype) { return rtype == RType::InstrumentDef; } |
| 26 | + |
| 27 | + InstrumentDefMsgV2 ToV2() const; |
| 28 | + const char* Currency() const { return currency.data(); } |
| 29 | + const char* SettlCurrency() const { return settl_currency.data(); } |
| 30 | + const char* SecSubType() const { return secsubtype.data(); } |
| 31 | + const char* RawSymbol() const { return raw_symbol.data(); } |
| 32 | + const char* Group() const { return group.data(); } |
| 33 | + const char* Exchange() const { return exchange.data(); } |
| 34 | + const char* Asset() const { return asset.data(); } |
| 35 | + const char* Cfi() const { return cfi.data(); } |
| 36 | + const char* SecurityType() const { return security_type.data(); } |
| 37 | + const char* UnitOfMeasure() const { return unit_of_measure.data(); } |
| 38 | + const char* Underlying() const { return underlying.data(); } |
| 39 | + const char* StrikePriceCurrency() const { |
| 40 | + return strike_price_currency.data(); |
| 41 | + } |
| 42 | + |
| 43 | + RecordHeader hd; |
| 44 | + UnixNanos ts_recv; |
| 45 | + std::int64_t min_price_increment; |
| 46 | + std::int64_t display_factor; |
| 47 | + UnixNanos expiration; |
| 48 | + UnixNanos activation; |
| 49 | + std::int64_t high_limit_price; |
| 50 | + std::int64_t low_limit_price; |
| 51 | + std::int64_t max_price_variation; |
| 52 | + std::int64_t trading_reference_price; |
| 53 | + std::int64_t unit_of_measure_qty; |
| 54 | + std::int64_t min_price_increment_amount; |
| 55 | + std::int64_t price_ratio; |
| 56 | + std::int32_t inst_attrib_value; |
| 57 | + std::uint32_t underlying_id; |
| 58 | + std::uint32_t raw_instrument_id; |
| 59 | + std::int32_t market_depth_implied; |
| 60 | + std::int32_t market_depth; |
| 61 | + std::uint32_t market_segment_id; |
| 62 | + std::uint32_t max_trade_vol; |
| 63 | + std::int32_t min_lot_size; |
| 64 | + std::int32_t min_lot_size_block; |
| 65 | + std::int32_t min_lot_size_round_lot; |
| 66 | + std::uint32_t min_trade_vol; |
| 67 | + std::array<char, 4> _reserved2; |
| 68 | + std::int32_t contract_multiplier; |
| 69 | + std::int32_t decay_quantity; |
| 70 | + std::int32_t original_contract_size; |
| 71 | + std::array<char, 4> _reserved3; |
| 72 | + std::uint16_t trading_reference_date; |
| 73 | + std::int16_t appl_id; |
| 74 | + std::uint16_t maturity_year; |
| 75 | + std::uint16_t decay_start_date; |
| 76 | + std::uint16_t channel_id; |
| 77 | + std::array<char, 4> currency; |
| 78 | + std::array<char, 4> settl_currency; |
| 79 | + std::array<char, 6> secsubtype; |
| 80 | + std::array<char, kSymbolCstrLenV1> raw_symbol; |
| 81 | + std::array<char, 21> group; |
| 82 | + std::array<char, 5> exchange; |
| 83 | + std::array<char, 7> asset; |
| 84 | + std::array<char, 7> cfi; |
| 85 | + std::array<char, 7> security_type; |
| 86 | + std::array<char, 31> unit_of_measure; |
| 87 | + std::array<char, 21> underlying; |
| 88 | + std::array<char, 4> strike_price_currency; |
| 89 | + InstrumentClass instrument_class; |
| 90 | + std::array<char, 2> _reserved4; |
| 91 | + std::int64_t strike_price; |
| 92 | + std::array<char, 6> _reserved5; |
| 93 | + MatchAlgorithm match_algorithm; |
| 94 | + std::uint8_t md_security_trading_status; |
| 95 | + std::uint8_t main_fraction; |
| 96 | + std::uint8_t price_display_format; |
| 97 | + std::uint8_t settl_price_type; |
| 98 | + std::uint8_t sub_fraction; |
| 99 | + std::uint8_t underlying_product; |
| 100 | + SecurityUpdateAction security_update_action; |
| 101 | + std::uint8_t maturity_month; |
| 102 | + std::uint8_t maturity_day; |
| 103 | + std::uint8_t maturity_week; |
| 104 | + UserDefinedInstrument user_defined_instrument; |
| 105 | + std::int8_t contract_multiplier_unit; |
| 106 | + std::int8_t flow_schedule_type; |
| 107 | + std::uint8_t tick_rule; |
| 108 | + // padding for alignment |
| 109 | + std::array<char, 3> dummy; |
| 110 | +}; |
| 111 | +static_assert(sizeof(InstrumentDefMsgV1) == 360, "Size must match Rust"); |
| 112 | +static_assert(alignof(InstrumentDefMsgV1) == 8, "Must have 8-byte alignment"); |
| 113 | + |
| 114 | +/// A symbol mapping message. |
| 115 | +struct SymbolMappingMsgV1 { |
| 116 | + static bool HasRType(RType rtype) { return rtype == RType::SymbolMapping; } |
| 117 | + |
| 118 | + SymbolMappingMsgV2 ToV2() const; |
| 119 | + const char* STypeInSymbol() const { return stype_in_symbol.data(); } |
| 120 | + const char* STypeOutSymbol() const { return stype_out_symbol.data(); } |
| 121 | + |
| 122 | + RecordHeader hd; |
| 123 | + std::array<char, kSymbolCstrLenV1> stype_in_symbol; |
| 124 | + std::array<char, kSymbolCstrLenV1> stype_out_symbol; |
| 125 | + // padding for alignment |
| 126 | + std::array<char, 4> dummy; |
| 127 | + UnixNanos start_ts; |
| 128 | + UnixNanos end_ts; |
| 129 | +}; |
| 130 | +static_assert(sizeof(SymbolMappingMsgV1) == 80, "Size must match Rust"); |
| 131 | +static_assert(alignof(SymbolMappingMsgV1) == 8, "Must have 8-byte alignment"); |
| 132 | + |
| 133 | +bool operator==(const InstrumentDefMsgV1& lhs, const InstrumentDefMsgV1& rhs); |
| 134 | +inline bool operator!=(const InstrumentDefMsgV1& lhs, |
| 135 | + const InstrumentDefMsgV1& rhs) { |
| 136 | + return !(lhs == rhs); |
| 137 | +} |
| 138 | +inline bool operator==(const SymbolMappingMsgV1& lhs, |
| 139 | + const SymbolMappingMsgV1& rhs) { |
| 140 | + return std::tie(lhs.hd, lhs.stype_in_symbol, lhs.stype_out_symbol, |
| 141 | + lhs.start_ts, lhs.end_ts) == |
| 142 | + std::tie(rhs.hd, rhs.stype_in_symbol, rhs.stype_out_symbol, |
| 143 | + rhs.start_ts, rhs.end_ts); |
| 144 | +} |
| 145 | +inline bool operator!=(const SymbolMappingMsgV1& lhs, |
| 146 | + const SymbolMappingMsgV1& rhs) { |
| 147 | + return !(lhs == rhs); |
| 148 | +} |
| 149 | +std::string ToString(const InstrumentDefMsgV1& instr_def_msg); |
| 150 | +std::ostream& operator<<(std::ostream& stream, |
| 151 | + const InstrumentDefMsgV1& instr_def_msg); |
| 152 | +std::string ToString(const SymbolMappingMsgV1& symbol_mapping_msg); |
| 153 | +std::ostream& operator<<(std::ostream& stream, |
| 154 | + const SymbolMappingMsgV1& symbol_mapping_msg); |
| 155 | +} // namespace databento |
0 commit comments