Skip to main content

dbn/
record.rs

1//! Market data types for encoding different Databento [`Schema`](crate::enums::Schema)s
2//! in the most recent DBN version, as well as conversion functions.
3
4pub(crate) mod conv;
5mod impl_default;
6mod layout_tests;
7mod methods;
8mod record_methods_tests;
9mod traits;
10mod with_ts_out_methods;
11
12use std::{ffi::CStr, mem, os::raw::c_char, ptr::NonNull, slice};
13
14// Dummy derive macro to get around `cfg_attr` incompatibility of several
15// of pyo3's attribute macros. See https://github.com/PyO3/pyo3/issues/780
16#[cfg(not(feature = "python"))]
17use dbn_macros::MockPyo3;
18
19use crate::{
20    enums::rtype,
21    macros::{dbn_record, CsvSerialize, JsonSerialize, RecordDebug},
22    Action, Error, FlagSet, InstrumentClass, MatchAlgorithm, Publisher, RType, Result,
23    SecurityUpdateAction, Side, StatUpdateAction, UserDefinedInstrument, ASSET_CSTR_LEN,
24    SYMBOL_CSTR_LEN,
25};
26pub(crate) use conv::as_u8_slice;
27#[cfg(feature = "serde")]
28pub(crate) use conv::cstr_serde;
29#[doc(hidden)]
30pub use conv::record_as_u8_slice;
31pub use conv::{
32    c_chars_to_str, str_to_c_chars, transmute_header_bytes, transmute_record,
33    transmute_record_bytes, transmute_record_mut, ts_to_dt,
34};
35pub use traits::{HasRType, Record, RecordMut};
36
37/// Common data for all Databento records. Always found at the beginning of a record
38/// struct.
39#[repr(C)]
40#[derive(Clone, Copy, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
43#[cfg_attr(test, derive(type_layout::TypeLayout))]
44pub struct RecordHeader {
45    /// The length of the record in 32-bit words.
46    #[dbn(skip)]
47    pub(crate) length: u8,
48    /// The record type; with `0x00..0x0F` specifying MBP levels size. Record types
49    /// implement the trait [`HasRType`], and the [`has_rtype`][HasRType::has_rtype]
50    /// function can be used to check if that type can be used to decode a message with
51    /// a given rtype. The set of possible values is defined in [`rtype`].
52    pub rtype: u8,
53    /// The publisher ID assigned by Databento, which denotes the dataset and venue.
54    ///
55    /// See [Publishers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#publishers-datasets-and-venues).
56    pub publisher_id: u16,
57    /// The numeric instrument ID. See [Instrument identifiers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#instrument-identifiers).
58    pub instrument_id: u32,
59    /// The matching-engine-received timestamp expressed as the number of nanoseconds
60    /// since the UNIX epoch.
61    ///
62    /// See [ts_event](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-event).
63    #[dbn(encode_order(0), unix_nanos)]
64    pub ts_event: u64,
65}
66
67/// A market-by-order (MBO) tick message. The record of the [`Mbo`](crate::Schema::Mbo)
68/// schema.
69#[repr(C)]
70#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
71#[cfg_attr(feature = "trivial_copy", derive(Copy))]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
74#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
75#[cfg_attr(test, derive(type_layout::TypeLayout))]
76#[dbn_record(rtype::MBO)]
77pub struct MboMsg {
78    /// The common header.
79    pub hd: RecordHeader,
80    /// The order ID assigned at the venue.
81    pub order_id: u64,
82    /// The order price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
83    /// 0.000000001.
84    ///
85    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
86    #[dbn(encode_order(4), fixed_price)]
87    pub price: i64,
88    /// The order quantity.
89    #[dbn(encode_order(5))]
90    pub size: u32,
91    /// A bit field indicating event end, message characteristics, and data quality.
92    /// See [`flags`](crate::flags) for possible values.
93    pub flags: FlagSet,
94    /// The channel ID assigned by Databento as an incrementing integer starting at zero.
95    #[dbn(encode_order(6))]
96    pub channel_id: u8,
97    /// The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R** book, **T**rade, **F**ill, or **N**one.
98    ///
99    /// See [Action](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#action).
100    #[dbn(c_char, encode_order(2))]
101    pub action: c_char,
102    /// The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in
103    /// a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified.
104    ///
105    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
106    #[dbn(c_char, encode_order(3))]
107    pub side: c_char,
108    /// The capture-server-received timestamp expressed as the number of nanoseconds
109    /// since the UNIX epoch.
110    ///
111    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
112    #[dbn(encode_order(0), index_ts, unix_nanos)]
113    pub ts_recv: u64,
114    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
115    /// `ts_recv`.
116    ///
117    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
118    pub ts_in_delta: i32,
119    /// The message sequence number assigned at the venue.
120    pub sequence: u32,
121}
122
123/// A price level.
124#[repr(C)]
125#[derive(Clone, JsonSerialize, RecordDebug, PartialEq, Eq, Hash)]
126#[cfg_attr(feature = "trivial_copy", derive(Copy))]
127#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
128#[cfg_attr(
129    feature = "python",
130    pyo3::pyclass(eq, from_py_object, module = "databento_dbn"),
131    derive(crate::macros::PyFieldDesc, crate::macros::WritePyRepr)
132)]
133#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
134#[cfg_attr(test, derive(type_layout::TypeLayout))]
135pub struct BidAskPair {
136    /// The bid price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
137    /// 0.000000001.
138    ///
139    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
140    #[dbn(fixed_price)]
141    #[pyo3(get, set)]
142    pub bid_px: i64,
143    /// The ask price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
144    /// 0.000000001.
145    ///
146    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
147    #[dbn(fixed_price)]
148    #[pyo3(get, set)]
149    pub ask_px: i64,
150    /// The bid size.
151    #[pyo3(get, set)]
152    pub bid_sz: u32,
153    /// The ask size.
154    #[pyo3(get, set)]
155    pub ask_sz: u32,
156    /// The bid order count.
157    #[pyo3(get, set)]
158    pub bid_ct: u32,
159    /// The ask order count.
160    #[pyo3(get, set)]
161    pub ask_ct: u32,
162}
163
164/// A price level consolidated from multiple venues.
165#[repr(C)]
166#[derive(Clone, JsonSerialize, RecordDebug, PartialEq, Eq, Hash)]
167#[cfg_attr(feature = "trivial_copy", derive(Copy))]
168#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
169#[cfg_attr(
170    feature = "python",
171    pyo3::pyclass(eq, from_py_object, module = "databento_dbn"),
172    derive(crate::macros::PyFieldDesc, crate::macros::WritePyRepr)
173)]
174#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
175#[cfg_attr(test, derive(type_layout::TypeLayout))]
176pub struct ConsolidatedBidAskPair {
177    /// The bid price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
178    /// 0.000000001.
179    ///
180    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
181    #[dbn(fixed_price)]
182    #[pyo3(get, set)]
183    pub bid_px: i64,
184    /// The ask price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
185    /// 0.000000001.
186    ///
187    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
188    #[dbn(fixed_price)]
189    #[pyo3(get, set)]
190    pub ask_px: i64,
191    /// The bid size.
192    #[pyo3(get, set)]
193    pub bid_sz: u32,
194    /// The ask size.
195    #[pyo3(get, set)]
196    pub ask_sz: u32,
197    /// The publisher ID indicating the venue containing the best bid.
198    ///
199    /// See [Publishers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#publishers-datasets-and-venues).
200    #[dbn(fmt_method)]
201    #[pyo3(get, set)]
202    pub bid_pb: u16,
203    #[doc(hidden)]
204    #[cfg_attr(feature = "serde", serde(skip))]
205    pub _reserved1: [u8; 2],
206    /// The publisher ID indicating the venue containing the best ask.
207    ///
208    /// See [Publishers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#publishers-datasets-and-venues).
209    #[dbn(fmt_method)]
210    #[pyo3(get, set)]
211    pub ask_pb: u16,
212    #[doc(hidden)]
213    #[cfg_attr(feature = "serde", serde(skip))]
214    pub _reserved2: [u8; 2],
215}
216
217/// Market-by-price implementation with a book depth of 0. Equivalent to MBP-0. The record of the [`Trades`](crate::Schema::Trades) schema.
218#[repr(C)]
219#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
220#[cfg_attr(feature = "trivial_copy", derive(Copy))]
221#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
222#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
223#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
224#[cfg_attr(test, derive(type_layout::TypeLayout))]
225#[dbn_record(rtype::MBP_0)]
226pub struct TradeMsg {
227    /// The common header.
228    pub hd: RecordHeader,
229    /// The trade price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
230    ///
231    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
232    #[dbn(fixed_price)]
233    pub price: i64,
234    /// The order quantity.
235    pub size: u32,
236    /// The event action. Always **T**rade in the trades schema.
237    ///
238    /// See [Action](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#action).
239    #[dbn(c_char, encode_order(2))]
240    pub action: c_char,
241    /// The side that initiates the trade. Can be **A**sk for a sell aggressor in a trade, **B**id for a buy aggressor in a trade, or **N**one where no side is specified.
242    ///
243    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
244    #[dbn(c_char, encode_order(3))]
245    pub side: c_char,
246    /// A bit field indicating event end, message characteristics, and data quality.
247    /// See [`flags`](crate::flags) for possible values.
248    pub flags: FlagSet,
249    /// The book level where the update event occurred.
250    #[dbn(encode_order(4))]
251    pub depth: u8,
252    /// The capture-server-received timestamp expressed as the number of nanoseconds
253    /// since the UNIX epoch.
254    ///
255    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
256    #[dbn(encode_order(0), index_ts, unix_nanos)]
257    pub ts_recv: u64,
258    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
259    /// `ts_recv`.
260    ///
261    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
262    pub ts_in_delta: i32,
263    /// The message sequence number assigned at the venue.
264    pub sequence: u32,
265}
266
267/// Market-by-price implementation with a known book depth of 1. The record of the
268/// [`Mbp1`](crate::Schema::Mbp1) schema.
269#[repr(C)]
270#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
271#[cfg_attr(feature = "trivial_copy", derive(Copy))]
272#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
273#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
274#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
275#[cfg_attr(test, derive(type_layout::TypeLayout))]
276#[dbn_record(rtype::MBP_1)]
277pub struct Mbp1Msg {
278    /// The common header.
279    pub hd: RecordHeader,
280    /// The order price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
281    /// 0.000000001.
282    ///
283    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
284    #[dbn(fixed_price)]
285    pub price: i64,
286    /// The order quantity.
287    pub size: u32,
288    /// The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R** book, or **T**rade.
289    ///
290    /// See [Action](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#action).
291    #[dbn(c_char, encode_order(2))]
292    pub action: c_char,
293    /// The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in
294    /// a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified.
295    ///
296    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
297    #[dbn(c_char, encode_order(3))]
298    pub side: c_char,
299    /// A bit field indicating event end, message characteristics, and data quality.
300    /// See [`flags`](crate::flags) for possible values.
301    pub flags: FlagSet,
302    /// The book level where the update event occurred.
303    #[dbn(encode_order(4))]
304    pub depth: u8,
305    /// The capture-server-received timestamp expressed as the number of nanoseconds
306    /// since the UNIX epoch.
307    ///
308    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
309    #[dbn(encode_order(0), index_ts, unix_nanos)]
310    pub ts_recv: u64,
311    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
312    /// `ts_recv`.
313    ///
314    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
315    pub ts_in_delta: i32,
316    /// The message sequence number assigned at the venue.
317    pub sequence: u32,
318    /// The top of the order book.
319    pub levels: [BidAskPair; 1],
320}
321
322/// Market-by-price implementation with a known book depth of 10. The record of the
323/// [`Mbp10`](crate::Schema::Mbp10) schema.
324#[repr(C)]
325#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
326#[cfg_attr(feature = "trivial_copy", derive(Copy))]
327#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
328#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
329#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
330#[cfg_attr(test, derive(type_layout::TypeLayout))]
331#[dbn_record(rtype::MBP_10)]
332pub struct Mbp10Msg {
333    /// The common header.
334    pub hd: RecordHeader,
335    /// The order price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
336    /// 0.000000001.
337    ///
338    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
339    #[dbn(fixed_price)]
340    pub price: i64,
341    /// The order quantity.
342    pub size: u32,
343    /// The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R** book, or **T**rade.
344    ///
345    /// See [Action](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#action).
346    #[dbn(c_char, encode_order(2))]
347    pub action: c_char,
348    /// The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in
349    /// a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified.
350    ///
351    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
352    #[dbn(c_char, encode_order(3))]
353    pub side: c_char,
354    /// A bit field indicating event end, message characteristics, and data quality.
355    /// See [`flags`](crate::flags) for possible values.
356    pub flags: FlagSet,
357    /// The book level where the update event occurred.
358    #[dbn(encode_order(4))]
359    pub depth: u8,
360    /// The capture-server-received timestamp expressed as the number of nanoseconds
361    /// since the UNIX epoch.
362    ///
363    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
364    #[dbn(encode_order(0), index_ts, unix_nanos)]
365    pub ts_recv: u64,
366    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
367    /// `ts_recv`.
368    ///
369    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
370    pub ts_in_delta: i32,
371    /// The message sequence number assigned at the venue.
372    pub sequence: u32,
373    /// The top 10 levels of the order book.
374    pub levels: [BidAskPair; 10],
375}
376
377/// Subsampled market by price with a known book depth of 1. The record of the
378/// [`Bbo1S`](crate::Schema::Bbo1S) and [`Bbo1M`](crate::Schema::Bbo1M) schemas.
379#[repr(C)]
380#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
381#[cfg_attr(feature = "trivial_copy", derive(Copy))]
382#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
383#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
384#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
385#[cfg_attr(test, derive(type_layout::TypeLayout))]
386#[dbn_record(rtype::BBO_1S, rtype::BBO_1M)]
387pub struct BboMsg {
388    /// The common header.
389    pub hd: RecordHeader,
390    /// The last trade price price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
391    /// or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) if there was no last trade
392    /// in the session.
393    ///
394    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
395    #[dbn(fixed_price)]
396    pub price: i64,
397    /// The quantity of the last trade.
398    pub size: u32,
399    #[doc(hidden)]
400    #[cfg_attr(feature = "serde", serde(skip))]
401    pub _reserved1: u8,
402    /// The side that initiated the last trade. Can be **A**sk for a sell order (or sell
403    /// aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or
404    /// **N**one where no side is specified.
405    ///
406    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
407    #[dbn(c_char, encode_order(2))]
408    pub side: c_char,
409    /// A bit field indicating event end, message characteristics, and data quality.
410    /// See [`flags`](crate::flags) for possible values.
411    pub flags: FlagSet,
412    #[doc(hidden)]
413    #[cfg_attr(feature = "serde", serde(skip))]
414    pub _reserved2: u8,
415    /// The end timestamp of the interval capture-server-received timestamp expressed as the
416    /// number of nanoseconds since the UNIX epoch.
417    ///
418    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
419    #[dbn(encode_order(0), index_ts, unix_nanos)]
420    pub ts_recv: u64,
421    #[doc(hidden)]
422    #[cfg_attr(feature = "serde", serde(skip))]
423    pub _reserved3: [u8; 4],
424    /// The message sequence number assigned at the venue of the last update.
425    pub sequence: u32,
426    /// The top of the order book.
427    pub levels: [BidAskPair; 1],
428}
429
430/// Consolidated market-by-price implementation with a known book depth of 1. The record of
431/// the [`Cmbp1`](crate::Schema::Cmbp1) schema.
432#[repr(C)]
433#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
434#[cfg_attr(feature = "trivial_copy", derive(Copy))]
435#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
436#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
437#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
438#[cfg_attr(test, derive(type_layout::TypeLayout))]
439#[dbn_record(rtype::CMBP_1, rtype::TCBBO)]
440pub struct Cmbp1Msg {
441    /// The common header.
442    pub hd: RecordHeader,
443    /// The order price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or
444    /// 0.000000001.
445    ///
446    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
447    #[dbn(fixed_price)]
448    pub price: i64,
449    /// The order quantity.
450    pub size: u32,
451    /// The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R** book, or **T**rade.
452    ///
453    /// See [Action](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#action).
454    #[dbn(c_char, encode_order(2))]
455    pub action: c_char,
456    /// The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in
457    /// a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified.
458    ///
459    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
460    #[dbn(c_char, encode_order(3))]
461    pub side: c_char,
462    /// A bit field indicating event end, message characteristics, and data quality.
463    /// See [`flags`](crate::flags) for possible values.
464    pub flags: FlagSet,
465    #[doc(hidden)]
466    #[cfg_attr(feature = "serde", serde(skip))]
467    pub _reserved1: [u8; 1],
468    /// The capture-server-received timestamp expressed as the number of nanoseconds
469    /// since the UNIX epoch.
470    ///
471    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
472    #[dbn(encode_order(0), index_ts, unix_nanos)]
473    pub ts_recv: u64,
474    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
475    /// `ts_recv`.
476    ///
477    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
478    pub ts_in_delta: i32,
479    #[doc(hidden)]
480    #[cfg_attr(feature = "serde", serde(skip))]
481    pub _reserved2: [u8; 4],
482    /// The top of the order book.
483    pub levels: [ConsolidatedBidAskPair; 1],
484}
485
486/// Subsampled consolidated market by price with a known book depth of 1. The record of the [`Cbbo1S`](crate::Schema::Cbbo1S) and [`Cbbo1M`](crate::Schema::Cbbo1M) schemas.
487#[repr(C)]
488#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
489#[cfg_attr(feature = "trivial_copy", derive(Copy))]
490#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
491#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
492#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
493#[cfg_attr(test, derive(type_layout::TypeLayout))]
494#[dbn_record(rtype::CBBO_1S, rtype::CBBO_1M)]
495pub struct CbboMsg {
496    /// The common header.
497    pub hd: RecordHeader,
498    /// The last trade price price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
499    /// or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) if there was no last trade
500    /// in the session.
501    ///
502    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
503    #[dbn(fixed_price)]
504    pub price: i64,
505    /// The quantity of the last trade.
506    pub size: u32,
507    #[doc(hidden)]
508    #[cfg_attr(feature = "serde", serde(skip))]
509    pub _reserved1: u8,
510    /// The side that initiated the last trade. Can be **A**sk for a sell order (or sell
511    /// aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or
512    /// **N**one where no side is specified.
513    ///
514    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
515    #[dbn(c_char, encode_order(2))]
516    pub side: c_char,
517    /// A bit field indicating event end, message characteristics, and data quality.
518    /// See [`flags`](crate::flags) for possible values.
519    pub flags: FlagSet,
520    #[doc(hidden)]
521    #[cfg_attr(feature = "serde", serde(skip))]
522    pub _reserved2: u8,
523    /// The end timestamp of the interval capture-server-received timestamp expressed as the
524    /// number of nanoseconds since the UNIX epoch.
525    ///
526    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
527    #[dbn(encode_order(0), index_ts, unix_nanos)]
528    pub ts_recv: u64,
529    #[doc(hidden)]
530    #[cfg_attr(feature = "serde", serde(skip))]
531    pub _reserved3: [u8; 8],
532    /// The top of the order book.
533    pub levels: [ConsolidatedBidAskPair; 1],
534}
535
536/// The record of the [`Tbbo`](crate::Schema::Tbbo) schema.
537pub type TbboMsg = Mbp1Msg;
538
539/// The record of the [`Bbo1S`](crate::Schema::Bbo1S) schema.
540pub type Bbo1SMsg = BboMsg;
541
542/// The record of the [`Bbo1M`](crate::Schema::Bbo1M) schema.
543pub type Bbo1MMsg = BboMsg;
544
545/// The record of the [`Tcbbo`](crate::Schema::Tcbbo) schema.
546pub type TcbboMsg = Cmbp1Msg;
547
548/// The record of the [`Cbbo1S`](crate::Schema::Cbbo1S) schema.
549pub type Cbbo1SMsg = CbboMsg;
550
551/// The record of the [`Cbbo1M`](crate::Schema::Cbbo1M) schema.
552pub type Cbbo1MMsg = CbboMsg;
553
554/// Open, high, low, close, and volume. The record of the following schemas:
555/// - [`Ohlcv1S`](crate::enums::Schema::Ohlcv1S)
556/// - [`Ohlcv1M`](crate::enums::Schema::Ohlcv1M)
557/// - [`Ohlcv1H`](crate::enums::Schema::Ohlcv1H)
558/// - [`Ohlcv1D`](crate::enums::Schema::Ohlcv1D)
559/// - [`OhlcvEod`](crate::enums::Schema::OhlcvEod)
560#[repr(C)]
561#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
562#[cfg_attr(feature = "trivial_copy", derive(Copy))]
563#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
564#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
565#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
566#[cfg_attr(test, derive(type_layout::TypeLayout))]
567#[dbn_record(
568    rtype::OHLCV_1S,
569    rtype::OHLCV_1M,
570    rtype::OHLCV_1H,
571    rtype::OHLCV_1D,
572    rtype::OHLCV_EOD,
573    rtype::OHLCV_DEPRECATED
574)]
575pub struct OhlcvMsg {
576    /// The common header.
577    pub hd: RecordHeader,
578    /// The open price for the bar where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
579    /// or 0.000000001.
580    ///
581    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
582    #[dbn(fixed_price)]
583    pub open: i64,
584    /// The high price for the bar where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
585    /// or 0.000000001.
586    ///
587    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
588    #[dbn(fixed_price)]
589    pub high: i64,
590    /// The low price for the bar where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
591    /// or 0.000000001.
592    ///
593    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
594    #[dbn(fixed_price)]
595    pub low: i64,
596    /// The close price for the bar where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000
597    /// or 0.000000001.
598    ///
599    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
600    #[dbn(fixed_price)]
601    pub close: i64,
602    /// The total volume traded during the aggregation period.
603    pub volume: u64,
604}
605
606/// A trading status update message. The record of the [`Status`](crate::Schema::Status) schema.
607#[repr(C)]
608#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
609#[cfg_attr(feature = "trivial_copy", derive(Copy))]
610#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
611#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
612#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
613#[cfg_attr(test, derive(type_layout::TypeLayout))]
614#[dbn_record(rtype::STATUS)]
615pub struct StatusMsg {
616    /// The common header.
617    pub hd: RecordHeader,
618    /// The capture-server-received timestamp expressed as the number of nanoseconds
619    /// since the UNIX epoch.
620    ///
621    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
622    #[dbn(encode_order(0), index_ts, unix_nanos)]
623    pub ts_recv: u64,
624    /// The type of status change.
625    #[dbn(fmt_method)]
626    pub action: u16,
627    /// Additional details about the cause of the status change.
628    #[dbn(fmt_method)]
629    pub reason: u16,
630    /// Further information about the status change and its effect on trading.
631    #[dbn(fmt_method)]
632    pub trading_event: u16,
633    /// The best-efforts state of trading in the instrument, either `Y`, `N` or `~`.
634    #[dbn(c_char)]
635    pub is_trading: c_char,
636    /// The best-efforts state of quoting in the instrument, either `Y`, `N` or `~`.
637    #[dbn(c_char)]
638    pub is_quoting: c_char,
639    /// The best-efforts state of short sell restrictions for the instrument (if applicable), either `Y`, `N` or `~`.
640    #[dbn(c_char)]
641    pub is_short_sell_restricted: c_char,
642    #[doc(hidden)]
643    #[cfg_attr(feature = "serde", serde(skip))]
644    pub _reserved: [u8; 7],
645}
646
647/// A definition of an instrument. The record of the
648/// [`Definition`](crate::Schema::Definition) schema.
649#[repr(C)]
650#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
651#[cfg_attr(feature = "trivial_copy", derive(Copy))]
652#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
653#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
654#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
655#[cfg_attr(test, derive(type_layout::TypeLayout))]
656#[dbn_record(rtype::INSTRUMENT_DEF)]
657pub struct InstrumentDefMsg {
658    /// The common header.
659    pub hd: RecordHeader,
660    /// The capture-server-received timestamp expressed as the number of nanoseconds
661    /// since the UNIX epoch.
662    ///
663    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
664    #[dbn(encode_order(0), index_ts, unix_nanos)]
665    pub ts_recv: u64,
666    /// The minimum constant tick for the instrument where every 1 unit corresponds to 1e-9, i.e.
667    /// 1/1,000,000,000 or 0.000000001.
668    ///
669    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
670    #[dbn(fixed_price)]
671    pub min_price_increment: i64,
672    /// The multiplier to convert the venue's display price to the conventional price where every
673    /// 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
674    #[dbn(fixed_price)]
675    pub display_factor: i64,
676    /// The last eligible trade time expressed as the number of nanoseconds since the
677    /// UNIX epoch.
678    ///
679    /// Will be [`UNDEF_TIMESTAMP`](crate::UNDEF_TIMESTAMP) when null, such as for equities. Some publishers
680    /// only provide date-level granularity.
681    #[dbn(unix_nanos)]
682    pub expiration: u64,
683    /// The time of instrument activation expressed as the number of nanoseconds since the
684    /// UNIX epoch.
685    ///
686    /// Will be [`UNDEF_TIMESTAMP`](crate::UNDEF_TIMESTAMP) when null, such as for equities. Some publishers
687    /// only provide date-level granularity.
688    #[dbn(unix_nanos)]
689    pub activation: u64,
690    /// The allowable high limit price for the trading day where every 1 unit corresponds to
691    /// 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
692    ///
693    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
694    #[dbn(fixed_price)]
695    pub high_limit_price: i64,
696    /// The allowable low limit price for the trading day where every 1 unit corresponds to
697    /// 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
698    ///
699    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
700    #[dbn(fixed_price)]
701    pub low_limit_price: i64,
702    /// The differential value for price banding where every 1 unit corresponds to 1e-9,
703    /// i.e. 1/1,000,000,000 or 0.000000001.
704    ///
705    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
706    #[dbn(fixed_price)]
707    pub max_price_variation: i64,
708    /// The contract size for each instrument, in combination with `unit_of_measure`, where every
709    /// 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
710    #[dbn(fixed_price)]
711    pub unit_of_measure_qty: i64,
712    /// The value currently under development by the venue where every 1 unit corresponds to 1e-9,
713    /// i.e. 1/1,000,000,000 or 0.000000001.
714    ///
715    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
716    #[dbn(fixed_price)]
717    pub min_price_increment_amount: i64,
718    /// The value used for price calculation in spread and leg pricing where every 1 unit
719    /// corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
720    #[dbn(fixed_price)]
721    pub price_ratio: i64,
722    /// The strike price of the option where every 1 unit corresponds to 1e-9, i.e.
723    /// 1/1,000,000,000 or 0.000000001.
724    ///
725    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
726    #[dbn(encode_order(54), fixed_price)]
727    pub strike_price: i64,
728    /// The instrument ID assigned by the publisher. May be the same as `instrument_id`.
729    ///
730    /// See [Instrument identifiers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#instrument-identifiers)
731    #[dbn(encode_order(20))]
732    pub raw_instrument_id: u64,
733    /// The tied price (if any) of the leg.
734    #[dbn(encode_order(165), fixed_price)]
735    pub leg_price: i64,
736    /// The associated delta (if any) of the leg.
737    #[dbn(encode_order(166), fixed_price)]
738    pub leg_delta: i64,
739    /// A bitmap of instrument eligibility attributes.
740    #[dbn(fmt_binary)]
741    pub inst_attrib_value: i32,
742    /// The `instrument_id` of the first underlying instrument.
743    ///
744    /// See [Instrument identifiers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#instrument-identifiers).
745    pub underlying_id: u32,
746    /// The implied book depth on the price level data feed.
747    pub market_depth_implied: i32,
748    /// The (outright) book depth on the price level data feed.
749    pub market_depth: i32,
750    /// The market segment of the instrument.
751    pub market_segment_id: u32,
752    /// The maximum trading volume for the instrument.
753    pub max_trade_vol: u32,
754    /// The minimum order entry quantity for the instrument.
755    pub min_lot_size: i32,
756    /// The minimum quantity required for a block trade of the instrument.
757    pub min_lot_size_block: i32,
758    /// The minimum quantity required for a round lot of the instrument. Multiples of this
759    /// quantity are also round lots.
760    pub min_lot_size_round_lot: i32,
761    /// The minimum trading volume for the instrument.
762    pub min_trade_vol: u32,
763    /// The number of deliverables per instrument, i.e. peak days.
764    pub contract_multiplier: i32,
765    /// The quantity that a contract will decay daily, after `decay_start_date` has been reached.
766    pub decay_quantity: i32,
767    /// The fixed contract value assigned to each instrument.
768    pub original_contract_size: i32,
769    /// The numeric ID assigned to the leg instrument.
770    ///
771    /// See [Instrument identifiers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#instrument-identifiers).
772    #[dbn(encode_order(160))]
773    pub leg_instrument_id: u32,
774    /// The numerator of the price ratio of the leg within the spread.
775    #[dbn(encode_order(167))]
776    pub leg_ratio_price_numerator: i32,
777    /// The denominator of the price ratio of the leg within the spread.
778    #[dbn(encode_order(168))]
779    pub leg_ratio_price_denominator: i32,
780    /// The numerator of the quantity ratio of the leg within the spread.
781    #[dbn(encode_order(169))]
782    pub leg_ratio_qty_numerator: i32,
783    /// The denominator of the quantity ratio of the leg within the spread.
784    #[dbn(encode_order(170))]
785    pub leg_ratio_qty_denominator: i32,
786    /// The numeric ID of the leg instrument's underlying instrument.
787    ///
788    /// See [Instrument identifiers](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#instrument-identifiers).
789    #[dbn(encode_order(171))]
790    pub leg_underlying_id: u32,
791    /// The channel ID assigned at the venue.
792    pub appl_id: i16,
793    /// The calendar year reflected in the instrument symbol.
794    pub maturity_year: u16,
795    /// The date at which a contract will begin to decay.
796    pub decay_start_date: u16,
797    /// The channel ID assigned by Databento as an incrementing integer starting at zero.
798    pub channel_id: u16,
799    /// The number of legs in the strategy or spread. Will be 0 for outrights.
800    #[dbn(encode_order(158))]
801    pub leg_count: u16,
802    /// The 0-based index of the leg.
803    #[dbn(encode_order(159))]
804    pub leg_index: u16,
805    /// The currency used for price fields.
806    #[dbn(fmt_method)]
807    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
808    pub currency: [c_char; 4],
809    /// The currency used for settlement, if different from `currency`.
810    #[dbn(fmt_method)]
811    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
812    pub settl_currency: [c_char; 4],
813    /// The strategy type of the spread.
814    #[dbn(fmt_method)]
815    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
816    pub secsubtype: [c_char; 6],
817    /// The instrument raw symbol assigned by the publisher.
818    #[dbn(encode_order(2), fmt_method)]
819    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
820    pub raw_symbol: [c_char; SYMBOL_CSTR_LEN],
821    /// The security group code of the instrument.
822    #[dbn(fmt_method)]
823    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
824    pub group: [c_char; 21],
825    /// The exchange used to identify the instrument.
826    #[dbn(fmt_method)]
827    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
828    pub exchange: [c_char; 5],
829    /// The underlying asset code (product code) of the instrument.
830    #[dbn(fmt_method)]
831    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
832    pub asset: [c_char; ASSET_CSTR_LEN],
833    /// The ISO standard instrument categorization code.
834    #[dbn(fmt_method)]
835    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
836    pub cfi: [c_char; 7],
837    /// The security type of the instrument, e.g. FUT for future or future spread.
838    ///
839    /// See [Security type](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#security-type).
840    #[dbn(fmt_method)]
841    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
842    pub security_type: [c_char; 7],
843    /// The unit of measure for the instrument’s original contract size, e.g. USD or LBS.
844    #[dbn(fmt_method)]
845    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
846    pub unit_of_measure: [c_char; 31],
847    /// The symbol of the first underlying instrument.
848    #[dbn(fmt_method)]
849    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
850    pub underlying: [c_char; 21],
851    /// The currency of [`strike_price`](Self::strike_price).
852    #[dbn(fmt_method)]
853    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
854    pub strike_price_currency: [c_char; 4],
855    /// The leg instrument's raw symbol assigned by the publisher.
856    #[dbn(encode_order(161), fmt_method)]
857    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
858    pub leg_raw_symbol: [c_char; SYMBOL_CSTR_LEN],
859    /// The classification of the instrument.
860    ///
861    /// See [Instrument class](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#instrument-class).
862    #[dbn(c_char, encode_order(4))]
863    pub instrument_class: c_char,
864    /// The matching algorithm used for the instrument, typically **F**IFO.
865    ///
866    /// See [Matching algorithm](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#matching-algorithm).
867    #[dbn(c_char)]
868    pub match_algorithm: c_char,
869    /// The price denominator of the main fraction.
870    pub main_fraction: u8,
871    /// The number of digits to the right of the tick mark, to display fractional prices.
872    pub price_display_format: u8,
873    /// The price denominator of the sub fraction.
874    pub sub_fraction: u8,
875    /// The product complex of the instrument.
876    pub underlying_product: u8,
877    /// Indicates if the instrument definition has been added, modified, or deleted.
878    #[dbn(c_char, encode_order(3))]
879    pub security_update_action: c_char,
880    /// The calendar month reflected in the instrument symbol.
881    pub maturity_month: u8,
882    /// The calendar day reflected in the instrument symbol, or 0.
883    pub maturity_day: u8,
884    /// The calendar week reflected in the instrument symbol, or 0.
885    pub maturity_week: u8,
886    /// Indicates if the instrument is user defined: **Y**es or **N**o.
887    #[dbn(c_char)]
888    pub user_defined_instrument: c_char,
889    /// The type of `contract_multiplier`. Either `1` for hours, or `2` for days.
890    pub contract_multiplier_unit: i8,
891    /// The schedule for delivering electricity.
892    pub flow_schedule_type: i8,
893    /// The tick rule of the spread.
894    pub tick_rule: u8,
895    /// The classification of the leg instrument.
896    #[dbn(c_char, encode_order(163))]
897    pub leg_instrument_class: c_char,
898    /// The side taken for the leg when purchasing the spread.
899    #[dbn(c_char, encode_order(164))]
900    pub leg_side: c_char,
901    #[doc(hidden)]
902    #[cfg_attr(feature = "serde", serde(skip))]
903    pub _reserved: [u8; 17],
904}
905
906/// An auction imbalance message.
907#[repr(C)]
908#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
909#[cfg_attr(feature = "trivial_copy", derive(Copy))]
910#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
911#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
912#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
913#[cfg_attr(test, derive(type_layout::TypeLayout))]
914#[dbn_record(rtype::IMBALANCE)]
915pub struct ImbalanceMsg {
916    /// The common header.
917    pub hd: RecordHeader,
918    /// The capture-server-received timestamp expressed as the number of nanoseconds
919    /// since the UNIX epoch.
920    ///
921    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
922    #[dbn(encode_order(0), index_ts, unix_nanos)]
923    pub ts_recv: u64,
924    /// The price at which the imbalance shares are calculated, where every 1 unit corresponds
925    /// to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE)
926    /// when unused.
927    ///
928    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
929    #[dbn(fixed_price)]
930    pub ref_price: i64,
931    /// Projected auction timestamp expressed as the number of nanoseconds since the UNIX epoch.
932    /// Will be [`UNDEF_TIMESTAMP`](crate::UNDEF_TIMESTAMP) when unused.
933    #[dbn(unix_nanos)]
934    pub auction_time: u64,
935    /// The hypothetical auction-clearing price for both cross and continuous orders where every
936    /// 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
937    /// Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
938    ///
939    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
940    #[dbn(fixed_price)]
941    pub cont_book_clr_price: i64,
942    /// The hypothetical auction-clearing price for cross orders only where every 1 unit corresponds
943    /// to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
944    ///
945    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
946    #[dbn(fixed_price)]
947    pub auct_interest_clr_price: i64,
948    /// The price at which sell short interest will be filed if a sell short restriction is
949    /// in effect, where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
950    /// Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
951    ///
952    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
953    #[dbn(fixed_price)]
954    pub ssr_filling_price: i64,
955    /// The price at which the highest number of shares would trade, subject to auction collars,
956    /// where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
957    /// Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
958    ///
959    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
960    #[dbn(fixed_price)]
961    pub ind_match_price: i64,
962    /// Upper limit of the auction collar, where every 1 unit corresponds
963    /// to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
964    ///
965    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
966    #[dbn(fixed_price)]
967    pub upper_collar: i64,
968    /// Lower limit of the auction collar, where every 1 unit corresponds
969    /// to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE) when unused.
970    ///
971    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
972    #[dbn(fixed_price)]
973    pub lower_collar: i64,
974    /// The quantity of shares that are eligible to be matched at [`ref_price`](Self::ref_price).
975    /// Will be [`UNDEF_ORDER_SIZE`](crate::UNDEF_ORDER_SIZE) when unused.
976    pub paired_qty: u32,
977    /// The quantity of shares that are not paired at [`ref_price`](Self::ref_price).
978    /// Will be [`UNDEF_ORDER_SIZE`](crate::UNDEF_ORDER_SIZE) when not used.
979    pub total_imbalance_qty: u32,
980    /// The total market order imbalance quantity at the [`ref_price`](Self::ref_price).
981    /// Will be [`UNDEF_ORDER_SIZE`](crate::UNDEF_ORDER_SIZE) when unused.
982    pub market_imbalance_qty: u32,
983    /// During the Closing Auction, the number of unpaired shares priced at or better than the
984    /// [`ref_price`](Self::ref_price). Will be `UNDEF_ORDER_SIZE` when unused.
985    pub unpaired_qty: u32,
986    /// Venue-specific character code indicating the auction type. Will be `~` when unused.
987    ///
988    /// Refer to the [venue-specific documentation](https://databento.com/docs/venues-and-datasets).
989    #[dbn(c_char)]
990    pub auction_type: c_char,
991    /// The market side of the [`total_imbalance_qty`](Self::total_imbalance_qty).
992    /// Can be **A**sk, **B**id, or **N**one.
993    ///
994    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
995    #[dbn(c_char)]
996    pub side: c_char,
997    /// Venue-specific status code.
998    ///
999    /// Refer to the [venue-specific documentation](https://databento.com/docs/venues-and-datasets).
1000    pub auction_status: u8,
1001    /// Venue-specific status code.
1002    ///
1003    /// Refer to the [venue-specific documentation](https://databento.com/docs/venues-and-datasets).
1004    pub freeze_status: u8,
1005    /// The number of times the halt period has been extended.
1006    pub num_extensions: u8,
1007    /// The side of the [`unpaired_qty`](Self::unpaired_qty).
1008    /// Can be **A**sk, **B**id, or **N**one. Will be **N**one when unused or not applicable.
1009    ///
1010    /// See [Side](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#side).
1011    #[dbn(c_char)]
1012    pub unpaired_side: c_char,
1013    /// Venue-specific character code. For Nasdaq, contains the raw Price Variation Indicator.
1014    ///
1015    /// Refer to the [venue-specific documentation](https://databento.com/docs/venues-and-datasets).
1016    #[dbn(c_char)]
1017    pub significant_imbalance: c_char,
1018    #[doc(hidden)]
1019    #[cfg_attr(feature = "serde", serde(skip))]
1020    pub _reserved: [u8; 1],
1021}
1022
1023/// A statistics message. A catchall for various data disseminated by publishers. The
1024/// [`stat_type`](Self::stat_type) indicates the statistic contained in the message.
1025#[repr(C)]
1026#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
1027#[cfg_attr(feature = "trivial_copy", derive(Copy))]
1028#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1029#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
1030#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
1031#[cfg_attr(test, derive(type_layout::TypeLayout))]
1032#[dbn_record(rtype::STATISTICS)]
1033pub struct StatMsg {
1034    /// The common header.
1035    pub hd: RecordHeader,
1036    /// The capture-server-received timestamp expressed as the number of nanoseconds
1037    /// since the UNIX epoch.
1038    ///
1039    /// See [ts_recv](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-recv).
1040    #[dbn(encode_order(0), index_ts, unix_nanos)]
1041    pub ts_recv: u64,
1042    /// The reference timestamp of the statistic value expressed as the number of
1043    /// nanoseconds since the UNIX epoch. Will be [`UNDEF_TIMESTAMP`](crate::UNDEF_TIMESTAMP) when
1044    /// unused.
1045    #[dbn(unix_nanos)]
1046    pub ts_ref: u64,
1047    /// The value for price statistics where every 1 unit corresponds to 1e-9, i.e.
1048    /// 1/1,000,000,000 or 0.000000001. Will be [`UNDEF_PRICE`](crate::UNDEF_PRICE)
1049    /// when unused.
1050    ///
1051    /// See [Prices](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#prices).
1052    #[dbn(fixed_price)]
1053    pub price: i64,
1054    /// The value for non-price statistics. Will be [`UNDEF_STAT_QUANTITY`](crate::UNDEF_STAT_QUANTITY)
1055    /// when unused.
1056    pub quantity: i64,
1057    /// The message sequence number assigned at the venue.
1058    pub sequence: u32,
1059    /// The matching-engine-sending timestamp expressed as the number of nanoseconds before
1060    /// `ts_recv`.
1061    ///
1062    /// See [ts_in_delta](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-in-delta).
1063    pub ts_in_delta: i32,
1064    /// The type of statistic value contained in the message. Refer to the
1065    /// [`StatType`](crate::enums::StatType) enum for possible variants.
1066    #[dbn(fmt_method)]
1067    pub stat_type: u16,
1068    /// The channel ID assigned by Databento as an incrementing integer starting at zero.
1069    pub channel_id: u16,
1070    /// Indicates if the statistic is newly added (1) or deleted (2). (Deleted is only
1071    /// used with some stat types).
1072    #[dbn(fmt_method)]
1073    pub update_action: u8,
1074    /// Additional flags associate with certain stat types.
1075    #[dbn(fmt_binary)]
1076    pub stat_flags: u8,
1077    #[doc(hidden)]
1078    #[cfg_attr(feature = "serde", serde(skip))]
1079    pub _reserved: [u8; 18],
1080}
1081
1082/// An error message from the Databento Live Subscription Gateway (LSG).
1083#[repr(C)]
1084#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
1085#[cfg_attr(feature = "trivial_copy", derive(Copy))]
1086#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1087#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
1088#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
1089#[cfg_attr(test, derive(type_layout::TypeLayout))]
1090#[dbn_record(rtype::ERROR)]
1091pub struct ErrorMsg {
1092    /// The common header.
1093    pub hd: RecordHeader,
1094    /// The error message.
1095    #[dbn(fmt_method)]
1096    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
1097    pub err: [c_char; 302],
1098    /// The error code. See the [`ErrorCode`](crate::enums::ErrorCode) enum
1099    /// for possible values.
1100    #[dbn(fmt_method)]
1101    pub code: u8,
1102    /// Sometimes multiple errors are sent together. This field will be non-zero for the
1103    /// last error.
1104    pub is_last: u8,
1105}
1106
1107/// A symbol mapping message from the live API which maps a symbol from one
1108/// [`SType`](crate::enums::SType) to another.
1109#[repr(C)]
1110#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
1111#[cfg_attr(feature = "trivial_copy", derive(Copy))]
1112#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1113#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
1114#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
1115#[cfg_attr(test, derive(type_layout::TypeLayout))]
1116#[dbn_record(rtype::SYMBOL_MAPPING)]
1117pub struct SymbolMappingMsg {
1118    /// The common header.
1119    pub hd: RecordHeader,
1120    /// The input symbology type of `stype_in_symbol`.
1121    #[dbn(fmt_method)]
1122    pub stype_in: u8,
1123    /// The input symbol.
1124    #[dbn(fmt_method)]
1125    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
1126    pub stype_in_symbol: [c_char; SYMBOL_CSTR_LEN],
1127    /// The output symbology type of `stype_out_symbol`. Will always be [`RawSymbol`](crate::SType::RawSymbol).
1128    #[dbn(fmt_method)]
1129    pub stype_out: u8,
1130    /// The output symbol.
1131    #[dbn(fmt_method)]
1132    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
1133    pub stype_out_symbol: [c_char; SYMBOL_CSTR_LEN],
1134    /// The start of the mapping interval expressed as the number of nanoseconds since
1135    /// the UNIX epoch.
1136    #[dbn(unix_nanos)]
1137    pub start_ts: u64,
1138    /// The end of the mapping interval expressed as the number of nanoseconds since
1139    /// the UNIX epoch.
1140    #[dbn(unix_nanos)]
1141    pub end_ts: u64,
1142}
1143
1144/// A non-error message from the Databento Live Subscription Gateway (LSG). Also used
1145/// for heartbeating.
1146#[repr(C)]
1147#[derive(Clone, CsvSerialize, JsonSerialize, PartialEq, Eq, Hash)]
1148#[cfg_attr(feature = "trivial_copy", derive(Copy))]
1149#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1150#[cfg_attr(feature = "python", derive(crate::macros::PyFieldDesc))]
1151#[cfg_attr(not(feature = "python"), derive(MockPyo3))] // bring `pyo3` attribute into scope
1152#[cfg_attr(test, derive(type_layout::TypeLayout))]
1153#[dbn_record(rtype::SYSTEM)]
1154pub struct SystemMsg {
1155    /// The common header.
1156    pub hd: RecordHeader,
1157    /// The message from the Databento gateway.
1158    #[dbn(fmt_method)]
1159    #[cfg_attr(feature = "serde", serde(with = "crate::record::cstr_serde"))]
1160    pub msg: [c_char; 303],
1161    /// Type of system message. See the [`SystemCode`](crate::enums::SystemCode) enum
1162    /// for possible values.
1163    #[dbn(fmt_method)]
1164    pub code: u8,
1165}
1166
1167/// Wrapper object for records that include the live gateway send timestamp (`ts_out`).
1168#[repr(C)]
1169#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1170#[cfg_attr(feature = "trivial_copy", derive(Copy))]
1171#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1172pub struct WithTsOut<T: HasRType> {
1173    /// The inner record.
1174    pub rec: T,
1175    /// The live gateway send timestamp expressed as the number of nanoseconds since the
1176    /// UNIX epoch.
1177    ///
1178    /// See [ts_out](https://databento.com/docs/standards-and-conventions/common-fields-enums-types#ts-out).
1179    pub ts_out: u64,
1180}