|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <cstddef> |
| 4 | +#include <cstdint> |
| 5 | + |
| 6 | +#include "databento/constants.hpp" // kSymbolCstrLen |
| 7 | +#include "databento/datetime.hpp" // UnixNanos |
| 8 | +#include "databento/enums.hpp" // InstrumentClass, MatchingAlgorithm, RType, SecurityUpdateAction, Side, UserDefinedInstrument |
| 9 | +#include "databento/record.hpp" // RecordHeader |
| 10 | + |
| 11 | +namespace databento { |
| 12 | +namespace v3 { |
| 13 | +static constexpr std::size_t kSymbolCstrLen = databento::kSymbolCstrLen; |
| 14 | + |
| 15 | +using MboMsg = databento::MboMsg; |
| 16 | +using TradeMsg = databento::TradeMsg; |
| 17 | +using Mbp1Msg = databento::Mbp1Msg; |
| 18 | +using TbboMsg = databento::TbboMsg; |
| 19 | +using Mbp10Msg = databento::Mbp10Msg; |
| 20 | +using BboMsg = databento::BboMsg; |
| 21 | +using Bbo1SMsg = databento::Bbo1SMsg; |
| 22 | +using Bbo1MMsg = databento::Bbo1MMsg; |
| 23 | +using Cmbp1Msg = databento::Cmbp1Msg; |
| 24 | +using TcbboMsg = databento::TcbboMsg; |
| 25 | +using CbboMsg = databento::CbboMsg; |
| 26 | +using Cbbo1SMsg = databento::Cbbo1SMsg; |
| 27 | +using Cbbo1MMsg = databento::Cbbo1MMsg; |
| 28 | +using OhlcvMsg = databento::OhlcvMsg; |
| 29 | +using StatusMsg = databento::StatusMsg; |
| 30 | +using ImbalanceMsg = databento::ImbalanceMsg; |
| 31 | +using StatMsg = databento::StatMsg; |
| 32 | +using ErrorMsg = databento::ErrorMsg; |
| 33 | +using SymbolMappingMsg = databento::SymbolMappingMsg; |
| 34 | +using SystemMsg = databento::SystemMsg; |
| 35 | + |
| 36 | +// An instrument definition in DBN version 3. |
| 37 | +struct InstrumentDefMsg { |
| 38 | + static bool HasRType(RType rtype) { return rtype == RType::InstrumentDef; } |
| 39 | + |
| 40 | + UnixNanos IndexTs() const { return ts_recv; } |
| 41 | + const char* Currency() const { return currency.data(); } |
| 42 | + const char* SettlCurrency() const { return settl_currency.data(); } |
| 43 | + const char* SecSubType() const { return secsubtype.data(); } |
| 44 | + const char* RawSymbol() const { return raw_symbol.data(); } |
| 45 | + const char* Group() const { return group.data(); } |
| 46 | + const char* Exchange() const { return exchange.data(); } |
| 47 | + const char* Asset() const { return asset.data(); } |
| 48 | + const char* Cfi() const { return cfi.data(); } |
| 49 | + const char* SecurityType() const { return security_type.data(); } |
| 50 | + const char* UnitOfMeasure() const { return unit_of_measure.data(); } |
| 51 | + const char* Underlying() const { return underlying.data(); } |
| 52 | + const char* StrikePriceCurrency() const { |
| 53 | + return strike_price_currency.data(); |
| 54 | + } |
| 55 | + const char* LegRawSymbol() const { return leg_raw_symbol.data(); } |
| 56 | + |
| 57 | + RecordHeader hd; |
| 58 | + UnixNanos ts_recv; |
| 59 | + std::int64_t min_price_increment; |
| 60 | + std::int64_t display_factor; |
| 61 | + UnixNanos expiration; |
| 62 | + UnixNanos activation; |
| 63 | + std::int64_t high_limit_price; |
| 64 | + std::int64_t low_limit_price; |
| 65 | + std::int64_t max_price_variation; |
| 66 | + std::int64_t unit_of_measure_qty; |
| 67 | + std::int64_t min_price_increment_amount; |
| 68 | + std::int64_t price_ratio; |
| 69 | + std::int64_t strike_price; |
| 70 | + std::uint64_t raw_instrument_id; |
| 71 | + std::int64_t leg_price; |
| 72 | + std::int64_t leg_delta; |
| 73 | + std::int32_t inst_attrib_value; |
| 74 | + std::uint32_t underlying_id; |
| 75 | + std::int32_t market_depth_implied; |
| 76 | + std::int32_t market_depth; |
| 77 | + std::uint32_t market_segment_id; |
| 78 | + std::uint32_t max_trade_vol; |
| 79 | + std::int32_t min_lot_size; |
| 80 | + std::int32_t min_lot_size_block; |
| 81 | + std::int32_t min_lot_size_round_lot; |
| 82 | + std::uint32_t min_trade_vol; |
| 83 | + std::int32_t contract_multiplier; |
| 84 | + std::int32_t decay_quantity; |
| 85 | + std::int32_t original_contract_size; |
| 86 | + std::uint32_t leg_instrument_id; |
| 87 | + std::int32_t leg_ratio_price_numerator; |
| 88 | + std::int32_t leg_ratio_price_denominator; |
| 89 | + std::int32_t leg_ratio_qty_numerator; |
| 90 | + std::int32_t leg_ratio_qty_denominator; |
| 91 | + std::uint32_t leg_underlying_id; |
| 92 | + std::int16_t appl_id; |
| 93 | + std::uint16_t maturity_year; |
| 94 | + std::uint16_t decay_start_date; |
| 95 | + std::uint16_t channel_id; |
| 96 | + std::uint16_t leg_count; |
| 97 | + std::uint16_t leg_index; |
| 98 | + std::array<char, 4> currency; |
| 99 | + std::array<char, 4> settl_currency; |
| 100 | + std::array<char, 6> secsubtype; |
| 101 | + std::array<char, kSymbolCstrLen> raw_symbol; |
| 102 | + std::array<char, 21> group; |
| 103 | + std::array<char, 5> exchange; |
| 104 | + std::array<char, 7> asset; |
| 105 | + std::array<char, 7> cfi; |
| 106 | + std::array<char, 7> security_type; |
| 107 | + std::array<char, 31> unit_of_measure; |
| 108 | + std::array<char, 21> underlying; |
| 109 | + std::array<char, 4> strike_price_currency; |
| 110 | + std::array<char, kSymbolCstrLen> leg_raw_symbol; |
| 111 | + InstrumentClass instrument_class; |
| 112 | + MatchAlgorithm match_algorithm; |
| 113 | + std::uint8_t main_fraction; |
| 114 | + std::uint8_t price_display_format; |
| 115 | + std::uint8_t sub_fraction; |
| 116 | + std::uint8_t underlying_product; |
| 117 | + SecurityUpdateAction security_update_action; |
| 118 | + std::uint8_t maturity_month; |
| 119 | + std::uint8_t maturity_day; |
| 120 | + std::uint8_t maturity_week; |
| 121 | + UserDefinedInstrument user_defined_instrument; |
| 122 | + std::int8_t contract_multiplier_unit; |
| 123 | + std::int8_t flow_schedule_type; |
| 124 | + std::uint8_t tick_rule; |
| 125 | + InstrumentClass leg_instrument_class; |
| 126 | + Side leg_side; |
| 127 | + // padding for alignment |
| 128 | + std::array<char, 21> reserved; |
| 129 | +}; |
| 130 | +static_assert(sizeof(InstrumentDefMsg) == 520, |
| 131 | + "InstrumentDefMsg size must match Rust"); |
| 132 | +static_assert(alignof(InstrumentDefMsg) == 8, "Must have 8-byte alignment"); |
| 133 | +static_assert(kMaxRecordLen == sizeof(InstrumentDefMsg) + sizeof(UnixNanos), |
| 134 | + "v3 definition with ts_out should be the largest record"); |
| 135 | + |
| 136 | +bool operator==(const InstrumentDefMsg& lhs, const InstrumentDefMsg& rhs); |
| 137 | +inline bool operator!=(const InstrumentDefMsg& lhs, |
| 138 | + const InstrumentDefMsg& rhs) { |
| 139 | + return !(lhs == rhs); |
| 140 | +} |
| 141 | + |
| 142 | +std::string ToString(const InstrumentDefMsg& instr_def_msg); |
| 143 | +std::ostream& operator<<(std::ostream& stream, |
| 144 | + const InstrumentDefMsg& instr_def_msg); |
| 145 | +} // namespace v3 |
| 146 | +} // namespace databento |
0 commit comments