Skip to content

Commit 601767d

Browse files
committed
ADD: Add separate BboMsg to C++ client
1 parent 7eb0c14 commit 601767d

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ for date fields were changed from strings or ints to `date::year_month_day`.
1212
- Added `DbnEncoder` class for encoding DBN data
1313
- Added blocking API similar to `LiveBlocking` to `DbnFileStore` with new `GetMetadata`
1414
and `NextRecord` methods
15+
- Added `BboMsg` record struct for future `bbo-1m` and `bbo-1s` schemas
1516
- Added `PitSymbol` map constructor from `Metadata` and a `date::year_month_day`
1617
- Added `Metadata::CreateSymbolMap` and `Metadata::CreateSymbolMapForDate` methods for
1718
creating symbology maps from historical metadata
@@ -25,6 +26,7 @@ for date fields were changed from strings or ints to `date::year_month_day`.
2526
- Added new dependency on [Howard Hinnant's date library](https://howardhinnant.github.io/date/date.html)
2627
- Added `ILogReceiver*` parameter to all `DbnDecoder` constructors and one `DbnFileStore` constructor
2728
- Removed type `StrMappingInterval`. `MappingInterval` is now also used in `SymbologyResolution`.
29+
- Changed `Bbo1sMsg` and `Bbo1mMsg` to be aliases for `BboMsg`
2830
- Changed type of `start_date` and `end_date` in `MappingInterval` to `date::year_month_day`
2931
- Added `stype_in` and `stype_out` fields to `SymbologyResolution` to support creating
3032
a `TsSymbolMap`

include/databento/record.hpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ static_assert(alignof(TradeMsg) == 8, "Must have 8-byte alignment");
177177
struct Mbp1Msg {
178178
static bool HasRType(RType rtype) {
179179
switch (rtype) {
180-
case RType::Mbp1: // fallthrough
181-
case RType::Bbo1M: // fallthrough
182-
case RType::Bbo1S:
180+
case RType::Mbp1:
183181
return true;
184182
default:
185183
return false;
@@ -202,8 +200,9 @@ struct Mbp1Msg {
202200
std::array<BidAskPair, 1> levels;
203201
};
204202
using TbboMsg = Mbp1Msg;
205-
using Bbo1SMsg = Mbp1Msg;
206-
using Bbo1MMsg = Mbp1Msg;
203+
static_assert(alignof(Mbp1Msg) == 8, "Must have 8-byte alignment");
204+
static_assert(sizeof(Mbp1Msg) == sizeof(TradeMsg) + sizeof(BidAskPair),
205+
"Mbp1Msg size must match Rust");
207206

208207
struct Mbp10Msg {
209208
static bool HasRType(RType rtype) { return rtype == rtype::Mbp10; }
@@ -223,14 +222,40 @@ struct Mbp10Msg {
223222
std::uint32_t sequence;
224223
std::array<BidAskPair, 10> levels;
225224
};
226-
227-
static_assert(alignof(Mbp1Msg) == 8, "Must have 8-byte alignment");
228225
static_assert(alignof(Mbp10Msg) == 8, "Must have 8-byte alignment");
229-
static_assert(sizeof(Mbp1Msg) == sizeof(TradeMsg) + sizeof(BidAskPair),
230-
"Mbp1Msg size must match Rust");
231226
static_assert(sizeof(Mbp10Msg) == sizeof(TradeMsg) + sizeof(BidAskPair) * 10,
232227
"Mbp10Msg size must match Rust");
233228

229+
struct BboMsg {
230+
static bool HasRType(RType rtype) {
231+
switch (rtype) {
232+
case RType::Bbo1S: // fallthrough
233+
case RType::Bbo1M:
234+
return true;
235+
default:
236+
return false;
237+
};
238+
}
239+
240+
UnixNanos IndexTs() const { return ts_recv; }
241+
242+
RecordHeader hd;
243+
std::int64_t price;
244+
std::uint32_t size;
245+
char reserved1;
246+
Side side;
247+
FlagSet flags;
248+
char reserved2;
249+
UnixNanos ts_recv;
250+
std::array<char, 4> reserved3;
251+
std::uint32_t sequence;
252+
std::array<BidAskPair, 1> levels;
253+
};
254+
using Bbo1SMsg = BboMsg;
255+
using Bbo1MMsg = BboMsg;
256+
static_assert(alignof(BboMsg) == 8, "Must have 8-byte alignment");
257+
static_assert(sizeof(BboMsg) == sizeof(Mbp1Msg), "BboMsg size must match Rust");
258+
234259
struct CbboMsg {
235260
static bool HasRType(RType rtype) {
236261
switch (rtype) {
@@ -252,7 +277,7 @@ struct CbboMsg {
252277
Action action;
253278
Side side;
254279
FlagSet flags;
255-
std::array<char, 1> reserved;
280+
char reserved;
256281
UnixNanos ts_recv;
257282
TimeDeltaNanos ts_in_delta;
258283
std::uint32_t sequence;
@@ -571,6 +596,16 @@ inline bool operator!=(const Mbp10Msg& lhs, const Mbp10Msg& rhs) {
571596
return !(lhs == rhs);
572597
}
573598

599+
inline bool operator==(const BboMsg& lhs, const BboMsg& rhs) {
600+
return std::tie(lhs.hd, lhs.price, lhs.size, lhs.side, lhs.flags, lhs.ts_recv,
601+
lhs.sequence, lhs.levels) ==
602+
std::tie(rhs.hd, rhs.price, rhs.size, rhs.side, rhs.flags, rhs.ts_recv,
603+
rhs.sequence, rhs.levels);
604+
}
605+
inline bool operator!=(const BboMsg& lhs, const BboMsg& rhs) {
606+
return !(lhs == rhs);
607+
}
608+
574609
inline bool operator==(const CbboMsg& lhs, const CbboMsg& rhs) {
575610
return lhs.hd == rhs.hd && lhs.price == rhs.price && lhs.size == rhs.size &&
576611
lhs.action == rhs.action && lhs.side == rhs.side &&
@@ -680,8 +715,10 @@ std::string ToString(const Mbp1Msg& mbp_msg);
680715
std::ostream& operator<<(std::ostream& stream, const Mbp1Msg& mbp_msg);
681716
std::string ToString(const Mbp10Msg& mbp_msg);
682717
std::ostream& operator<<(std::ostream& stream, const Mbp10Msg& mbp_msg);
683-
std::string ToString(const CbboMsg& mbp_msg);
684-
std::ostream& operator<<(std::ostream& stream, const CbboMsg& mbp_msg);
718+
std::string ToString(const BboMsg& bbo_msg);
719+
std::ostream& operator<<(std::ostream& stream, const BboMsg& bbo_msg);
720+
std::string ToString(const CbboMsg& cbbo_msg);
721+
std::ostream& operator<<(std::ostream& stream, const CbboMsg& cbbo_msg);
685722
std::string ToString(const TradeMsg& trade_msg);
686723
std::ostream& operator<<(std::ostream& stream, const TradeMsg& trade_msg);
687724
std::string ToString(const OhlcvMsg& ohlcv_msg);

src/record.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ std::ostream& operator<<(std::ostream& stream, const Mbp10Msg& mbp_msg) {
306306
static_cast<std::ostringstream&>(levels_helper.Finish()))
307307
.Finish();
308308
}
309+
std::string ToString(const BboMsg& bbo_msg) { return MakeString(bbo_msg); }
310+
std::ostream& operator<<(std::ostream& stream, const BboMsg& bbo_msg) {
311+
return StreamOpBuilder{stream}
312+
.SetTypeName("BboMsg")
313+
.SetSpacer("\n ")
314+
.Build()
315+
.AddField("hd", bbo_msg.hd)
316+
.AddField("price", FixPx{bbo_msg.price})
317+
.AddField("size", bbo_msg.size)
318+
.AddField("side", bbo_msg.side)
319+
.AddField("flags", bbo_msg.flags)
320+
.AddField("ts_recv", bbo_msg.ts_recv)
321+
.AddField("sequence", bbo_msg.sequence)
322+
.AddField("levels", std::get<0>(bbo_msg.levels))
323+
.Finish();
324+
}
309325
std::string ToString(const CbboMsg& cbbo_msg) { return MakeString(cbbo_msg); }
310326
std::ostream& operator<<(std::ostream& stream, const CbboMsg& cbbo_msg) {
311327
return StreamOpBuilder{stream}

0 commit comments

Comments
 (0)