Expand description
The official crate for working with Databento Binary Encoding (DBN), an extremely fast message encoding and storage format for normalized market data. The DBN specification includes a simple, self-describing metadata header and a fixed set of struct definitions, which enforce a standardized way to normalize market data.
All official Databento client libraries use DBN under the hood, both as a data interchange format and for in-memory representation of data. DBN is also the default encoding for all Databento APIs, including live data streaming, historical data streaming, and batch flat files. For more information about the encoding, read our introduction to DBN.
The crate supports reading and writing DBN files and streams, as well as converting
them to other Encodings. It can also be used to update legacy
DBZ files to DBN.
This crate provides:
- Decoders for DBN and DBZ (the precursor to DBN), both
sync and async, with the
asyncfeature flag - Encoders for CSV, DBN, and JSON, both sync and async,
with the
asyncfeature flag - Normalized market data struct definitions corresponding to the different market data schemas offered by Databento
- A wrapper type for holding a reference to a record struct of a dynamic type
- Helper functions and macros for common tasks
§Feature flags
async: enables async decoding and encodingpython: enablespyo3bindingsserde: enables derivingserdetraits for typestrivial_copy: enables deriving theCopytrait for records
Modules§
- compat
- Compatibility shims for different DBN versions.
- decode
- Decoding DBN and Zstd-compressed DBN files and streams. Sync decoders implement
- encode
- Encoding DBN and Zstd-compressed DBN files and streams. Encoders implement the
EncodeDbntrait. - enums
- Enums used in Databento APIs.
- error
- Types for errors that can occur while working with DBN.
- flags
- Bit set flags used in Databento market data.
- macros
- Helper macros for working with multiple RTypes, Schemas, and types of records.
- metadata
- Contains
Metadatastruct which comes at the beginning of any DBN file or stream andMetadataBuilderfor creating aMetadatawith defaults. - pretty
- Contains new types for pretty-printing timestamp and prices found in DBN records.
- publishers
- Enumerations for different data sources, venues, and publishers.
- python
python - Python wrappers around dbn functions. These are implemented here instead of in
python/to be able to implementpyo3traits for DBN types. - record
- Market data types for encoding different Databento
Schemas in the most recent DBN version, as well as conversion functions. - record_
ref - The
RecordRefstruct for non-owning dynamically-typed references to DBN records. - rtype
- Record types, possible values for
RecordHeader::rtype. - symbol_
map - Maps for mapping instrument IDs to human-readable symbols.
- v1
- Record data types for encoding different Databento
Schemas in DBN version 1. - v2
- Record data types for encoding different Databento
Schemas in DBN version 2. - v3
- Record data types for encoding different Databento
Schemas in the upcoming DBN version 3.
Macros§
- rtype_
async_ dispatch Deprecated - Specializes a generic async function to all record types and dispatches based
rtype. - rtype_
dispatch - Dispatches to a generic function or method based on
$rtypeand optionally$ts_out. - rtype_
dispatch_ with_ ts_ out Deprecated - Specializes a generic function to all record types wrapped in
WithTsOutand dispatches based on thertype. - rtype_
method_ dispatch Deprecated - Specializes a generic method to all record types and dispatches based
rtype. - rtype_
ts_ out_ async_ dispatch Deprecated - Specializes a generic async function to all record types and dispatches based
rtypeandts_out. - rtype_
ts_ out_ async_ method_ dispatch Deprecated - Specializes a generic async method to all record types and dispatches based
rtypeandts_out. - rtype_
ts_ out_ dispatch Deprecated - Specializes a generic function to all record types and dispatches based on the
rtypeandts_out. - rtype_
ts_ out_ method_ dispatch Deprecated - Specializes a generic method to all record types and dispatches based on the
rtypeandts_out. - schema_
async_ method_ dispatch Deprecated - Specializes a generic async method to all record types with an associated schema.
- schema_
dispatch - Dispatches to a generic function or method based on
$schemaand optionally$ts_out. - schema_
method_ dispatch Deprecated - Specializes a generic method to all record types with an associated schema.
- schema_
ts_ out_ method_ dispatch Deprecated - Specializes a generic method to all record types based on the associated type for
schemaandts_out.
Structs§
- BboMsg
- Subsampled market by price with a known book depth of 1. The record of the
Bbo1SandBbo1Mschemas. - BidAsk
Pair - A price level.
- CbboMsg
- Subsampled consolidated market by price with a known book depth of 1. The record of the
Cbbo1SandCbbo1Mschemas. - Cmbp1
Msg - Consolidated market-by-price implementation with a known book depth of 1. The record of
the
Cmbp1schema. - Consolidated
BidAsk Pair - A price level consolidated from multiple venues.
- DbnVersion
- New type for validating DBN versions.
- Error
Msg - An error message from the Databento Live Subscription Gateway (LSG).
- FlagSet
- A transparent wrapper around the bit field used in several DBN record types,
namely
MboMsgand record types derived from it. - Imbalance
Msg - An auction imbalance message.
- Instrument
DefMsg - A definition of an instrument. The record of the
Definitionschema. - Mapping
Interval - The resolved symbol for a date range.
- MboMsg
- A market-by-order (MBO) tick message. The record of the
Mboschema. - Mbp1Msg
- Market-by-price implementation with a known book depth of 1. The record of the
Mbp1schema. - Mbp10
Msg - Market-by-price implementation with a known book depth of 10. The record of the
Mbp10schema. - Metadata
- Information about the data contained in a DBN file or stream. DBN requires the Metadata to be included at the start of the encoded data.
- Metadata
Builder - Helper for constructing
Metadatastructs with defaults. - Ohlcv
Msg - Open, high, low, close, and volume. The record of the following schemas:
- PitSymbol
Map - A point-in-time symbol map. Useful for working with live symbology or a historical request over a single day or other situations where the symbol mappings are known not to change.
- Record
Header - Common data for all Databento records. Always found at the beginning of a record struct.
- Record
Ref - A wrapper around a non-owning immutable reference to a DBN record. This wrapper allows for mixing of record types and schemas and runtime record polymorphism.
- StatMsg
- A statistics message. A catchall for various data disseminated by publishers. The
stat_typeindicates the statistic contained in the message. - Status
Msg - A trading status update message. The record of the
Statusschema. - Symbol
Mapping - A raw symbol and its symbol mappings for different time ranges within the query range.
- Symbol
Mapping Msg - A symbol mapping message from the live API which maps a symbol from one
STypeto another. - System
Msg - A non-error message from the Databento Live Subscription Gateway (LSG). Also used for heartbeating.
- Trade
Msg - Market-by-price implementation with a book depth of 0. Equivalent to MBP-0. The record of the
Tradesschema. - TsSymbol
Map - A timeseries symbol map. Generally useful for working with historical data
and is commonly built from a
Metadataobject viaSelf::from_metadata(). - With
TsOut - Wrapper object for records that include the live gateway send timestamp (
ts_out).
Enums§
- Action
- An order event or order book operation.
- Compression
- A compression format or none if uncompressed.
- Dataset
- A source of data.
- Encoding
- A data encoding format.
- Error
- An error that can occur while processing DBN data.
- Error
Code - An error code from the live subscription gateway.
- Instrument
Class - The class of instrument.
- Match
Algorithm - The type of matching algorithm used for the instrument at the exchange.
- Publisher
- A specific Venue from a specific data source.
- RType
- A record type,
i.e. a sentinel for different types implementing
HasRType. - Record
Enum - An owned DBN record type of flexible type. Unlike
RecordRef, this type allowsmatching. - Record
RefEnum - An immutable reference to a DBN record of flexible type. Unlike
RecordRef, this type allowsmatching. - SType
- A symbology type. Refer to the symbology documentation for more information.
- Schema
- A data record schema.
- Security
Update Action - The type of
InstrumentDefMsgupdate. - Side
- A side of the market. The side of the market for resting orders, or the side of the aggressor for trades.
- Stat
Type - The type of statistic contained in a
StatMsg. - Stat
Update Action - The type of
StatMsgupdate. - Status
Action - The primary enum for the type of
StatusMsgupdate. - Status
Reason - The secondary enum for a
StatusMsgupdate, explains the cause of a halt or other change inaction. - System
Code - A
SystemMsgcode indicating the type of message from the live subscription gateway. - Trading
Event - Further information about a status update.
- TriState
- An enum for representing unknown, true, or false values. Equivalent to
Option<bool>but with a human-readable repr. - User
Defined Instrument - Whether the instrument is user-defined.
- Venue
- A trading execution venue.
- Version
Upgrade Policy - How to handle decoding DBN data from other versions.
Constants§
- ASSET_
CSTR_ LEN - The length of the fixed-length asset string.
- DBN_
VERSION - The current version of the DBN encoding, which is different from the crate version.
- FIXED_
PRICE_ SCALE - The denominator of fixed prices in DBN.
- MAX_
RECORD_ LEN - The length in bytes of the largest record type.
- SYMBOL_
CSTR_ LEN - The length of fixed-length symbol strings.
- UNDEF_
ORDER_ SIZE - The sentinel value for an unset or null order quantity.
- UNDEF_
PRICE - The sentinel value for an unset or null price.
- UNDEF_
STAT_ QUANTITY - The sentinel value for an unset or null stat quantity.
- UNDEF_
TIMESTAMP - The sentinel value for an unset or null timestamp.
Traits§
- HasR
Type - An extension of the
Recordtrait for types with a staticRType. Used for determining if a rtype matches a type. - Record
- Used for polymorphism around types all beginning with a
RecordHeaderwherertypeis the discriminant used for indicating the type of record. - Record
Mut - Used for polymorphism around mutable types beginning with a
RecordHeader. - Symbol
Index - Used for retrieving a symbol mapping for a DBN record.