Skip to content

Commit 4827509

Browse files
committed
MOD: Update C++ for DBNv3 as the default
1 parent eef8d44 commit 4827509

File tree

80 files changed

+809
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+809
-596
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# Changelog
22

3+
## 0.36.0 - TBD
4+
5+
This version marks the release of DBN version 3 (DBNv3), which is the new default.
6+
Decoders support decoding all versions of DBN and the DBN encoders default to
7+
upgrading the input to DBNv3.
8+
9+
### Enhancements
10+
- Added `UpgradeToV3` variant to `VersionUpgradePolicy` enum
11+
- Version 1 and 2 structs can be converted to version 3 structs with templated `Upgrade`
12+
method
13+
- Metadata will now always be encoded with a length divisible by 8 bytes for better
14+
alignment
15+
16+
### Breaking changes
17+
- Release of DBN version 3
18+
- Definition
19+
- Updated `InstrumentDefMsg` with new `leg_` fields to support multi-leg strategy
20+
definitions.
21+
- Expanded `raw_instrument_id` to 64 bits to support more venues. Like other 64-bit
22+
integer fields, its value will now be quoted in JSON
23+
- Removed `trading_reference_date`, `trading_reference_price`, and
24+
`settl_price_type` fields which will be normalized in the statistics schema
25+
- Removed `md_security_trading_status` better served by the status schema
26+
- Updated `asset` to 11 bytes and `kAssetCstrLen` to match
27+
- Statistics
28+
- Updated `StatMsg` has an expanded 64-bit `quantity` field. `kUndefStatQuantity`
29+
has been updated to match
30+
- The previous `StatMsg` has been moved to `v2::StatMsg` or `StatMsgV2`
31+
332
## 0.35.1 - 2025-05-20
433

534
### Bug fixes

cmake/SourcesAndHeaders.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ set(sources
7171
src/symbol_map.cpp
7272
src/symbology.cpp
7373
src/v1.cpp
74-
src/v3.cpp
74+
src/v2.cpp
7575
)

include/databento/constants.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ static constexpr auto kUndefOrderSize =
1616
std::numeric_limits<std::uint32_t>::max();
1717
// The sentinel value for an unset statistic quantity.
1818
static constexpr auto kUndefStatQuantity =
19-
std::numeric_limits<std::int32_t>::max();
19+
std::numeric_limits<std::int64_t>::max();
2020
// The sentinel value for an unset or null timestamp.
2121
static constexpr auto kUndefTimestamp =
2222
std::numeric_limits<std::uint64_t>::max();
2323
// The current version of the DBN encoding.
24-
static constexpr auto kDbnVersion = 2;
24+
static constexpr auto kDbnVersion = 3;
2525
// The length of fixed-length symbol strings.
2626
static constexpr auto kSymbolCstrLen = 71;
2727
// The length of fixed-length asset string.
28-
static constexpr auto kAssetCstrLen = 7;
28+
static constexpr auto kAssetCstrLen = 11;
2929
// The multiplier for converting the `length` field in `RecordHeader` to bytes.
3030
static constexpr std::size_t kRecordHeaderLengthMultiplier = 4;
3131

include/databento/dbn_decoder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
namespace databento {
1717
// DBN decoder. Set upgrade_policy to control how DBN version 1 data should be
18-
// handled. Defaults to upgrading DBNv1 data to version 2 (the current version).
18+
// handled. Defaults to upgrading DBN versions 1 and 2 to version 3 (the current
19+
// version).
1920
class DbnDecoder {
2021
public:
2122
DbnDecoder(ILogReceiver* log_receiver, InFileStream file_stream);

include/databento/dbn_encoder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class DbnEncoder {
3232
void EncodeRecord(const Record& record);
3333

3434
private:
35-
static std::uint32_t CalcLength(const Metadata& metadata);
35+
static std::pair<std::uint32_t, std::uint32_t> CalcLength(
36+
const Metadata& metadata);
3637

3738
IWritable* output_;
3839
};

include/databento/enums.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ enum class StatUpdateAction : std::uint8_t {
303303
enum class VersionUpgradePolicy : std::uint8_t {
304304
AsIs = 0,
305305
UpgradeToV2 = 1,
306+
UpgradeToV3 = 2,
306307
};
307308

308309
namespace status_action {

include/databento/live.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LiveBuilder {
5252
std::string key_;
5353
std::string dataset_;
5454
bool send_ts_out_{false};
55-
VersionUpgradePolicy upgrade_policy_{VersionUpgradePolicy::UpgradeToV2};
55+
VersionUpgradePolicy upgrade_policy_{VersionUpgradePolicy::UpgradeToV3};
5656
std::chrono::seconds heartbeat_interval_{};
5757
};
5858
} // namespace databento

include/databento/record.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#include "databento/publishers.hpp" // Publisher
1818

1919
namespace databento {
20-
// Forward declare
21-
namespace v3 {
22-
struct InstrumentDefMsg;
23-
struct StatMsg;
24-
} // namespace v3
25-
2620
// Common data for all Databento Records.
2721
struct RecordHeader {
2822
static constexpr std::size_t kLengthMultiplier =
@@ -379,7 +373,6 @@ static_assert(alignof(StatusMsg) == 8, "Must have 8-byte alignment");
379373
struct InstrumentDefMsg {
380374
static bool HasRType(RType rtype) { return rtype == RType::InstrumentDef; }
381375

382-
v3::InstrumentDefMsg ToV3() const;
383376
UnixNanos IndexTs() const { return ts_recv; }
384377
const char* Currency() const { return currency.data(); }
385378
const char* SettlCurrency() const { return settl_currency.data(); }
@@ -395,6 +388,7 @@ struct InstrumentDefMsg {
395388
const char* StrikePriceCurrency() const {
396389
return strike_price_currency.data();
397390
}
391+
const char* LegRawSymbol() const { return leg_raw_symbol.data(); }
398392

399393
RecordHeader hd;
400394
UnixNanos ts_recv;
@@ -405,14 +399,15 @@ struct InstrumentDefMsg {
405399
std::int64_t high_limit_price;
406400
std::int64_t low_limit_price;
407401
std::int64_t max_price_variation;
408-
std::int64_t trading_reference_price;
409402
std::int64_t unit_of_measure_qty;
410403
std::int64_t min_price_increment_amount;
411404
std::int64_t price_ratio;
412405
std::int64_t strike_price;
406+
std::uint64_t raw_instrument_id;
407+
std::int64_t leg_price;
408+
std::int64_t leg_delta;
413409
std::int32_t inst_attrib_value;
414410
std::uint32_t underlying_id;
415-
std::uint32_t raw_instrument_id;
416411
std::int32_t market_depth_implied;
417412
std::int32_t market_depth;
418413
std::uint32_t market_segment_id;
@@ -424,11 +419,18 @@ struct InstrumentDefMsg {
424419
std::int32_t contract_multiplier;
425420
std::int32_t decay_quantity;
426421
std::int32_t original_contract_size;
427-
std::uint16_t trading_reference_date;
422+
std::uint32_t leg_instrument_id;
423+
std::int32_t leg_ratio_price_numerator;
424+
std::int32_t leg_ratio_price_denominator;
425+
std::int32_t leg_ratio_qty_numerator;
426+
std::int32_t leg_ratio_qty_denominator;
427+
std::uint32_t leg_underlying_id;
428428
std::int16_t appl_id;
429429
std::uint16_t maturity_year;
430430
std::uint16_t decay_start_date;
431431
std::uint16_t channel_id;
432+
std::uint16_t leg_count;
433+
std::uint16_t leg_index;
432434
std::array<char, 4> currency;
433435
std::array<char, 4> settl_currency;
434436
std::array<char, 6> secsubtype;
@@ -441,12 +443,11 @@ struct InstrumentDefMsg {
441443
std::array<char, 31> unit_of_measure;
442444
std::array<char, 21> underlying;
443445
std::array<char, 4> strike_price_currency;
446+
std::array<char, kSymbolCstrLen> leg_raw_symbol;
444447
InstrumentClass instrument_class;
445448
MatchAlgorithm match_algorithm;
446-
std::uint8_t md_security_trading_status;
447449
std::uint8_t main_fraction;
448450
std::uint8_t price_display_format;
449-
std::uint8_t settl_price_type;
450451
std::uint8_t sub_fraction;
451452
std::uint8_t underlying_product;
452453
SecurityUpdateAction security_update_action;
@@ -457,9 +458,12 @@ struct InstrumentDefMsg {
457458
std::int8_t contract_multiplier_unit;
458459
std::int8_t flow_schedule_type;
459460
std::uint8_t tick_rule;
460-
std::array<char, 10> reserved;
461+
InstrumentClass leg_instrument_class;
462+
Side leg_side;
463+
// padding for alignment
464+
std::array<char, 17> reserved;
461465
};
462-
static_assert(sizeof(InstrumentDefMsg) == 400,
466+
static_assert(sizeof(InstrumentDefMsg) == 520,
463467
"InstrumentDefMsg size must match Rust");
464468
static_assert(alignof(InstrumentDefMsg) == 8, "Must have 8-byte alignment");
465469

@@ -502,23 +506,22 @@ static_assert(alignof(ImbalanceMsg) == 8, "Must have 8-byte alignment");
502506
struct StatMsg {
503507
static bool HasRType(RType rtype) { return rtype == RType::Statistics; }
504508

505-
v3::StatMsg ToV3() const;
506509
UnixNanos IndexTs() const { return ts_recv; }
507510

508511
RecordHeader hd;
509512
UnixNanos ts_recv;
510513
UnixNanos ts_ref;
511514
std::int64_t price;
512-
std::int32_t quantity;
515+
std::int64_t quantity;
513516
std::uint32_t sequence;
514517
TimeDeltaNanos ts_in_delta;
515518
StatType stat_type;
516519
std::uint16_t channel_id;
517520
StatUpdateAction update_action;
518521
std::uint8_t stat_flags;
519-
std::array<char, 6> reserved;
522+
std::array<char, 18> reserved;
520523
};
521-
static_assert(sizeof(StatMsg) == 64, "StatMsg size must match Rust");
524+
static_assert(sizeof(StatMsg) == 80, "StatMsg size must match Rust");
522525
static_assert(alignof(StatMsg) == 8, "Must have 8-byte alignment");
523526

524527
// An error message from the Live Subscription Gateway (LSG). This will never
@@ -798,4 +801,6 @@ std::ostream& operator<<(std::ostream& stream,
798801

799802
// The length in bytes of the largest record type.
800803
static constexpr std::size_t kMaxRecordLen = 520 + 8;
804+
static_assert(kMaxRecordLen == sizeof(InstrumentDefMsg) + sizeof(UnixNanos),
805+
"v3 definition with ts_out should be the largest record");
801806
} // namespace databento

0 commit comments

Comments
 (0)