dbn

package module
v0.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 1

README

dbn-go - Golang bindings to DBN

Latest Tag Go Reference Code Of Conduct

Golang tooling for Databento's APIs and DBN format

This repository contains Golang bindings to Databento's file format Databento Binary Encoding (DBN), Historical API, and Live API. It also includes tools to interact with these services.

NOTE: This library is not affiliated with Databento. Please be careful with commands which incur billing. We are not responsible for any charges you incur.

Library Usage

To use this library, import the following package, optionally with Databento Historical or Live support:

import (
    dbn "github.com/NimbleMarkets/dbn-go"
    dbn_hist "github.com/NimbleMarkets/dbn-go/hist"
    dbn_live "github.com/NimbleMarkets/dbn-go/live"
)

Most dbn-go types and enums parallel Databento's libraries. Available messages types are:

Reading DBN Files

If you want to read a homogeneous array of DBN records from a file, use the dbn.ReadDBNToSlice generic function. We include an io.Reader wrapper, [dbn.MakeCompressedReader]https://pkg.go.dev/github.com/NimbleMarkets/dbn-go#MakeCompressedReader), that automatically handles zstd-named files. The generic argument dicates which message type to read.

file, closer, _ := dbn.MakeCompressedReader("ohlcv-1s.dbn.zstd", false)
defer closer.Close()
records, metadata, err := dbn.ReadDBNToSlice[dbn.OhlcvMsg](file)

Alternatively, you can use the DBNScanner to read records one-by-one. Each record can be handled directly, or automatically dispatched to the callback method of a struct that implements the dbn.Visitor interface.

dbnFile, _ := os.Open("ohlcv-1s.dbn")
defer dbnFile.Close()

dbnScanner := dbn.NewDbnScanner(dbnFile)
metadata, err := dbnScanner.Metadata()
if err != nil {
	return fmt.Errorf("scanner failed to read metadata: %w", err)
}
for dbnScanner.Next() {
    header := dbnScanner.GetLastHeader()
    fmt.Printf("rtype: %s  ts: %d\n", header.RType, header.TsEvent)

    // you could get the raw bytes and size:
    lastRawByteArray := dbnScanner.GetLastRecord()
    lastSize := dbnScanner.GetLastSize()

    // you probably want to use this generic helper to crack the message:
    ohlcv, err := dbn.DbnScannerDecode[dbn.OhlcvMsg](dbnScanner)

    // or if you are handing multiple message types, dispatch a Visitor:
    err = dbnScanner.Visit(visitor)
}
if err := dbnScanner.Error(); err != nil && err != io.EOF {
    return fmt.Errorf("scanner error: %w", err)
}

Reading JSON Files

If you already have DBN-based JSON text files, you can use the generic dbn.ReadJsonToSlice or dbn.JsonScanner to read them in as dbn-go structs. Similar to the raw DBN, you can handle records manually or use the dbn.Visitor interface.

jsonFile, _ := os.Open("ohlcv-1s.dbn.json")
defer jsonFile.Close()
records, metadata, err := dbn.ReadJsonToSlice[dbn.OhlcvMsg](jsonFile)
jsonFile, _ := os.Open("ohlcv-1s.dbn.json")
defer jsonFile.Close()
jsonScanner := dbn.NewJsonScanner(jsonFile)
for jsonScanner.Next() {
    if err := jsonScanner.Visit(visitor); err != nil {
        return fmt.Errorf("visitor err: %w", err)
    }
}
if err := jsonScanner.Error(); err != nil {
    fmt.Errorf("scanner err: %w", err)
}

Many of the dbn-go structs are annotated with json tags to facilitate JSON serialization and deserialization using json.Marshal and json.Unmarshal. That said, dbn-go uses valyala/fastjson and hand-written extraction code.

Historical API

Support for the Databento Historical API is available in the /hist folder. Every API method is a function that takes an API key and arguments and returns a response struct and error.

databentoApiKey := os.Getenv("DATABENTO_API_KEY")
schemas, err := dbn_hist.ListSchemas(databentoApiKey, "EQUS.MINI")

The source for dbn-go-hist illustrates using this dbn_hist module.

Live API

Support for the Databento Live API is available in the /live folder.

The general model is:

  1. Use dbn_live.NewLiveClient to create a LiveClient based on a LiveConfig and connect to a DBN gateway
  2. client.Authenticate with the gateway.
  3. client.Subscribe to a stream using one or many SubscriptionRequestMsg.
  4. Begin the stream with client.Start.
  5. Read the stream using client.GetDbnScanner.

The source for dbn-go-live illustrates using this dbn_live module.

Tools

We include some tools to make our lives easier. Installation instructions

Open Collaboration

We welcome contributions and feedback. Please adhere to our Code of Conduct when engaging our community.

License

Released under the Apache License, version 2.0, see LICENSE.txt.

Portions adapted from databento/dbn databendo/databento-rs under the same Apache license.

Copyright (c) 2024-2025 Neomantra Corp.


Made with ❤ and 🔥 by the team behind Nimble.Markets.

Documentation

Index

Constants

View Source
const (
	/// Indicates it's the last message in the packet from the venue for a given
	/// `instrument_id`.
	RFlag_LAST uint8 = 1 << 7
	/// Indicates a top-of-book message, not an individual order.
	RFlag_TOB uint8 = 1 << 6
	/// Indicates the message was sourced from a replay, such as a snapshot server.
	RFlag_SNAPSHOT uint8 = 1 << 5
	/// Indicates an aggregated price level message, not an individual order.
	RFlag_MBP uint8 = 1 << 4
	/// Indicates the `ts_recv` value is inaccurate due to clock issues or packet
	/// reordering.
	RFlag_BAD_TS_RECV uint8 = 1 << 3
	/// Indicates an unrecoverable gap was detected in the channel.
	RFlag_MAYBE_BAD_BOOK uint8 = 1 << 2
)

/ Constants for the bit flag record fields.

View Source
const (
	/// A message sent in the absence of other records to indicate the connection remains open.
	SystemCode_Heartbeat = 0
	/// An acknowledgement of a subscription request.
	SystemCode_SubscriptionAck = 1
	/// The gateway has detected this session is falling behind real-time.
	SystemCode_SlowReaderWarning = 2
	/// Indicates a replay subscription has caught up with real-time data.
	SystemCode_ReplayCompleted = 3
	/// Signals that all records for interval-based schemas have been published for the given timestamp.
	SystemCode_EndOfInterval = 4
	/// No system code was specified or this record was upgraded from a version 1 struct where the code field didn't exist.
	SystemCode_Unset = 255
	// Heartbeat string
	SystemCodeString_Heartbeat = "HEARTBEAT"
)
View Source
const (
	/// The authentication step failed.
	ErrorCode_AuthFailed = 1
	/// The user account or API key were deactivated.
	ErrorCode_ApiKeyDeactivated = 2
	/// The user has exceeded their open connection limit.
	ErrorCode_ConnectionLimitExceeded = 3
	/// One or more symbols failed to resolve.
	ErrorCode_SymbolResolutionFailed = 4
	/// There was an issue with a subscription request (other than symbol resolution).
	ErrorCode_InvalidSubscription = 5
	/// An error occurred in the gateway.
	ErrorCode_InternalError = 6
	/// No error code was specified or this record was upgraded from a version 1 struct where the code field didn't exist.
	ErrorCode_Unset = 255
)
View Source
const (
	HeaderVersion1            = 1
	HeaderVersion2            = 2
	MetadataV1_SymbolCstrLen  = 22
	MetadataV1_ReservedLen    = 47
	MetadataV2_SymbolCstrLen  = 71
	MetadataV2_ReservedLen    = 53
	Metadata_DatasetCstrLen   = 16
	Metadata_PrefixSize       = 8
	MetadataHeaderV1_Size     = 100 // Size of the fixed-size portion of Metadata v1, without Prefix
	MetadataHeaderV2_Size     = 100 // Size of the fixed-size portion of Metadata v2, without Prefix
	MetadataHeaderV1_SizeFuzz = 12  // Difference between actual layout size and Golang struct
	MetadataHeaderV2_SizeFuzz = 12  // Difference between actual layout size and Golang struct
)
View Source
const BboMsg_Size = RHeader_Size + 64
View Source
const BidAskPair_Size = 32
View Source
const ConsolidatedBidAskPair_Size = 32
View Source
const DATASET_COUNT = 41
View Source
const DEFAULT_DECODE_BUFFER_SIZE = 16 * 1024

Default buffer size for decoding

View Source
const DEFAULT_SCRATCH_BUFFER_SIZE = 512 // bigger than largest record size
View Source
const ErrorMsg_ErrSize = 302
View Source
const ErrorMsg_Size = RHeader_Size + ErrorMsg_ErrSize + 2
View Source
const FIXED_PRICE_SCALE float64 = 1000000000.0

/ The denominator of fixed prices in DBN.

View Source
const ImbalanceMsg_Size = RHeader_Size + 96
View Source
const InstrumentDefMsg_Size = RHeader_Size + 313 + MetadataV2_SymbolCstrLen
View Source
const MboMsg_Size = RHeader_Size + 40
View Source
const Mbp0Msg_Size = RHeader_Size + 32
View Source
const Mbp10Msg_Size = RHeader_Size + 32 + 10*BidAskPair_Size
View Source
const Mbp1Msg_Size = RHeader_Size + 64
View Source
const OhlcvMsg_Size = RHeader_Size + 40
View Source
const PUBLISHER_COUNT = 107
View Source
const RHeader_Size = 16
View Source
const StatMsg_Size = RHeader_Size + 48
View Source
const StatusMsg_Size = RHeader_Size + 24 // TODO check size, add test
View Source
const SymbolMappingMsg_MinSize = RHeader_Size + 16

Minimum size of SymbolMappingMsg, the size with 0-length c-strings We add 2*SymbolCstrLength to it to get actual size.

View Source
const SystemMsg_MsgSize = 303
View Source
const SystemMsg_Size = RHeader_Size + SystemMsg_MsgSize + 1
View Source
const UNDEF_TIMESTAMP uint64 = math.MaxUint64

The sentinel value for an unset or null timestamp.

View Source
const VENUE_COUNT = 53

Variables

View Source
var (
	ErrInvalidDBNVersion     = fmt.Errorf("invalid DBN version")
	ErrInvalidDBNFile        = fmt.Errorf("invalid DBN file")
	ErrHeaderTooShort        = fmt.Errorf("header shorter than expected")
	ErrHeaderTooLong         = fmt.Errorf("header longer than expected")
	ErrUnexpectedCStrLength  = fmt.Errorf("unexpected cstr length")
	ErrNoRecord              = fmt.Errorf("no record scanned")
	ErrMalformedRecord       = fmt.Errorf("malformed record")
	ErrUnknownRType          = fmt.Errorf("unknown rtype")
	ErrDateOutsideQueryRange = fmt.Errorf("date outside the query range")
	ErrWrongStypesForMapping = fmt.Errorf("wrong stypes for mapping")
	ErrNoMetadata            = fmt.Errorf("no metadata")
)

Functions

func DatasetToHostname added in v0.0.8

func DatasetToHostname(dataset string) string

DatasetToHostname returns the dataset string into the hostname formnat. This is the dataset in lowercase with . replaced with -.

func DbnScannerDecode

func DbnScannerDecode[R Record, RP RecordPtr[R]](s *DbnScanner) (*R, error)

Parses the Scanner's current record as a `Record`. This a plain function because receiver functions cannot be generic.

func Fixed9ToFloat64

func Fixed9ToFloat64(fixed int64) float64

func JsonScannerDecode

func JsonScannerDecode[R Record, RP RecordPtr[R]](s *JsonScanner) (*R, error)

Parses the Scanner's current record as a `Record`. This a plain function (not a method) because methods cannot be generic.

func MakeCompressedReader added in v0.2.0

func MakeCompressedReader(filename string, useZstd bool) (io.Reader, io.Closer, error)

Returns a io.Reader for the given filename, or os.Stdout if filename is "-". Also returns a closing function to defer. If the filename ends in ".zst" or ".zstd", or if useZstd is true, the reader will zstd-decompress the input.

func MakeCompressedWriter added in v0.2.0

func MakeCompressedWriter(filename string, useZstd bool) (io.Writer, func(), error)

Returns an io.Writer for the given filename, or os.Stdout if filename is "-". Also returns a closing function to defer and any error. If the filename ends in ".zst" or ".zstd", or if useZstd is true, the writer will zstd-compress the output.

func ReadJsonToSlice

func ReadJsonToSlice[R Record, RP RecordPtr[R]](reader io.Reader) ([]R, error)

ReadJsonToSlice reads the entire stream from a JSONL stream of DBN records. It will scan for type R (for example Mbp0) and decode it into a slice of R. Returns the slice and any error. Example:

fileReader, err := os.Open(dbnFilename)
records, err := dbn.ReadJsonToSlice[dbn.Mbp0Msg](fileReader)

func TimeToYMD

func TimeToYMD(t time.Time) uint32

TimeToYMD returns the YYYYMMDD for the time.Time in that Time's location. A zero time returns a 0 value. From https://github.com/neomantra/ymdflag/blob/main/ymdflag.go#L49

func TimestampToSecNanos

func TimestampToSecNanos(dbnTimestamp uint64) (int64, int64)

TimestampToSecNanos converts a DBN timestamp to seconds and nanoseconds.

func TimestampToTime added in v0.0.3

func TimestampToTime(dbnTimestamp uint64) time.Time

TimestampToTime converts a DBN timestamp to time.Time

func TrimNullBytes

func TrimNullBytes(b []byte) string

TrimNullBytes removes trailing nulls from a byte slice and returns a string.

func YMDToTime added in v0.0.8

func YMDToTime(yyyymmdd int, loc *time.Location) time.Time

YMDtoTime returns the Time corresponding to the YYYYMMDD in the specified location, without validating the argument.` A value of 0 returns a Zero Time, independent of location. A nil location implies local time. https://github.com/neomantra/ymdflag/blob/main/ymdflag.go#L34

Types

type Action

type Action uint8

Action is an order event or order book operation.

For example usage see: - https://databento.com/docs/examples/order-book/order-actions - https://databento.com/docs/examples/order-book/order-tracking

const (
	// An existing order was modified.
	Action_Modify Action = 'M'
	// A trade executed.
	Action_Trade Action = 'T'
	// An existing order was filled.
	Action_Fill Action = 'F'
	// An order was cancelled.
	Action_Cancel Action = 'C'
	// A new order was added.
	Action_Add Action = 'A'
	// Reset the book; clear all orders for an instrument.
	Action_Clear Action = 'R'
	// Has no effect on the book, but may carry `flags` or other information.
	Action_None Action = 'N'
)

type BboMsg added in v0.6.3

type BboMsg struct {
	Header    RHeader    `json:"hd" csv:"hd"`                 // The common header.
	Price     int64      `json:"price" csv:"price"`           // The last trade price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be UNDEF_PRICE if there was no last trade in the session.
	Size      uint32     `json:"size" csv:"size"`             // The last trade quantity. Will be 0 if there was no last trade in the session.
	Reserved1 byte       `json:"_reserved1" csv:"_reserved1"` // Reserved for future use.
	Side      byte       `json:"side" csv:"side"`             // The side that initiated the last trade. Can be Ask for a sell aggressor in a trade, Bid for a buy aggressor in a trade, or None where no side is specified.
	Flags     uint8      `json:"flags" csv:"flags"`           // A bit field indicating event end, message characteristics, and data quality.
	Reserved2 byte       `json:"_reserved2" csv:"_reserved2"` // Reserved for future use.
	TsRecv    uint64     `json:"ts_recv" csv:"ts_recv"`       // The end timestamp of the interval, clamped to the second/minute boundary, expressed as the number of nanoseconds since the UNIX epoch.
	Reserved3 [4]byte    `json:"_reserved3" csv:"_reserved3"` // Reserved for future use.
	Sequence  uint32     `json:"sequence" csv:"sequence"`     // The message sequence number assigned at the venue of the last update.
	Level     BidAskPair `json:"levels" csv:"levels"`         // The bid and ask prices and sizes at the top level.
}

BboMsg is a Best Bid and Offer record subsampled on a 1-second or 1-minute interval. It provides the last best bid, best offer, and sale at the specified interval.

func (*BboMsg) Fill_Json added in v0.6.3

func (r *BboMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*BboMsg) Fill_Raw added in v0.6.3

func (r *BboMsg) Fill_Raw(b []byte) error

func (*BboMsg) RSize added in v0.6.3

func (*BboMsg) RSize() uint16

func (*BboMsg) RType added in v0.6.3

func (*BboMsg) RType() RType

type BidAskPair added in v0.0.8

type BidAskPair struct {
	BidPx int64  `json:"bid_px" csv:"bid_px"` // The bid price.
	AskPx int64  `json:"ask_px" csv:"ask_px"` // The ask price.
	BidSz uint32 `json:"bid_sz" csv:"bid_sz"` // The bid size.
	AskSz uint32 `json:"ask_sz" csv:"ask_sz"` // The ask size.
	BidCt uint32 `json:"bid_ct" csv:"bid_ct"` // The bid order count.
	AskCt uint32 `json:"ask_ct" csv:"ask_ct"` // The ask order count.
}

func (*BidAskPair) Fill_Json added in v0.0.8

func (p *BidAskPair) Fill_Json(val *fastjson.Value) error

func (*BidAskPair) Fill_Raw added in v0.0.8

func (p *BidAskPair) Fill_Raw(b []byte) error

type Cmbp1Msg added in v0.6.0

type Cmbp1Msg struct {
	Header    RHeader                `json:"hd" csv:"hd"`                         // The record header.
	Price     int64                  `json:"price" csv:"price"`                   // The order price expressed as a signed integer where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Size      uint32                 `json:"size" csv:"size"`                     // The order quantity.
	Action    byte                   `json:"action" csv:"action"`                 // The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R**, or **T**rade.
	Side      byte                   `json:"side" csv:"side"`                     // The side that initiates the event. Can be **A**sk for a sell order (or sell  aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or  **N**one where no side is specified by the original source.
	Flags     uint8                  `json:"flags" csv:"flags"`                   // A bit field indicating event end, message characteristics, and data quality. See [`enums::flags`](crate::enums::flags) for possible values.
	Reserved  byte                   `json:"_reserved,omitempty" csv:"_reserved"` // Reserved for future usage.
	TsRecv    uint64                 `json:"ts_recv" csv:"ts_recv"`               // The capture-server-received timestamp expressed as number of nanoseconds since the UNIX epoch.
	TsInDelta int32                  `json:"ts_in_delta" csv:"ts_in_delta"`       // The delta of `ts_recv - ts_exchange_send`, max 2 seconds.
	Sequence  uint32                 `json:"sequence" csv:"sequence"`             // The message sequence number assigned at the venue.
	Level     ConsolidatedBidAskPair `json:"levels" csv:"levels"`                 // The top of the order book.
}

Consolidated market by price implementation with a known book depth of 1. The record of the [`Cmbp1`](crate::Schema::Cmbp1) schema.

func (*Cmbp1Msg) Fill_Json added in v0.6.0

func (r *Cmbp1Msg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*Cmbp1Msg) Fill_Raw added in v0.6.0

func (r *Cmbp1Msg) Fill_Raw(b []byte) error

func (*Cmbp1Msg) RSize added in v0.6.0

func (*Cmbp1Msg) RSize() uint16

func (*Cmbp1Msg) RType added in v0.6.0

func (*Cmbp1Msg) RType() RType

type Compression

type Compression uint8

Compression is the compression format or none if uncompressed.

const (
	/// Uncompressed.
	Compress_None Compression = 0
	/// Zstandard compressed.
	Compress_ZStd Compression = 1
)

func CompressionFromString added in v0.0.13

func CompressionFromString(str string) (Compression, error)

CompressionFromString converts a string to a Compression. Returns an error if the string is unknown.

func (Compression) MarshalJSON added in v0.0.13

func (c Compression) MarshalJSON() ([]byte, error)

func (*Compression) Set added in v0.0.13

func (c *Compression) Set(value string) error

Set implements the flag.Value interface.

func (Compression) String added in v0.0.13

func (c Compression) String() string

Returns the string representation of the Compression ('zstd' or 'none'), or empty string if unknown.

func (*Compression) Type added in v0.0.13

func (*Compression) Type() string

Type implements pflag.Value.Type. Returns "dbn.Compression".

func (*Compression) UnmarshalJSON added in v0.0.13

func (c *Compression) UnmarshalJSON(data []byte) error

type ConsolidatedBidAskPair added in v0.0.11

type ConsolidatedBidAskPair struct {
	BidPx     int64  `json:"bid_px" csv:"bid_px"`         // The bid price.
	AskPx     int64  `json:"ask_px" csv:"ask_px"`         // The ask price.
	BidSz     uint32 `json:"bid_sz" csv:"bid_sz"`         // The bid size.
	AskSz     uint32 `json:"ask_sz" csv:"ask_sz"`         // The ask size.
	BidPb     uint16 `json:"bid_pb" csv:"bid_pb"`         // The bid publisher ID assigned by Databento, which denotes the dataset and venue.
	Reserved1 uint16 `json:"_reserved1" csv:"_reserved1"` // Reserved for later usage
	AskPb     uint16 `json:"ask_pb" csv:"ask_pb"`         // The ask publisher ID assigned by Databento, which denotes the dataset and venue.
	Reserved2 uint16 `json:"_reserved2" csv:"_reserved2"` // Reserved for later usage
}

A price level consolidated from multiple venues.

func (*ConsolidatedBidAskPair) Fill_Json added in v0.0.11

func (p *ConsolidatedBidAskPair) Fill_Json(val *fastjson.Value) error

func (*ConsolidatedBidAskPair) Fill_Raw added in v0.0.11

func (p *ConsolidatedBidAskPair) Fill_Raw(b []byte) error

type Dataset added in v0.7.0

type Dataset uint16

Dataset is a source of data.

const (
	// CME MDP 3.0 Market Data
	Dataset_GlbxMdp3 Dataset = 1
	// Nasdaq TotalView-ITCH
	Dataset_XnasItch Dataset = 2
	// Nasdaq BX TotalView-ITCH
	Dataset_XbosItch Dataset = 3
	// Nasdaq PSX TotalView-ITCH
	Dataset_XpsxItch Dataset = 4
	// Cboe BZX Depth
	Dataset_BatsPitch Dataset = 5
	// Cboe BYX Depth
	Dataset_BatyPitch Dataset = 6
	// Cboe EDGA Depth
	Dataset_EdgaPitch Dataset = 7
	// Cboe EDGX Depth
	Dataset_EdgxPitch Dataset = 8
	// NYSE Integrated
	Dataset_XnysPillar Dataset = 9
	// NYSE National Integrated
	Dataset_XcisPillar Dataset = 10
	// NYSE American Integrated
	Dataset_XasePillar Dataset = 11
	// NYSE Texas Integrated
	Dataset_XchiPillar Dataset = 12
	// NYSE National BBO
	Dataset_XcisBbo Dataset = 13
	// NYSE National Trades
	Dataset_XcisTrades Dataset = 14
	// MEMX Memoir Depth
	Dataset_MemxMemoir Dataset = 15
	// MIAX Pearl Depth
	Dataset_EprlDom Dataset = 16
	// FINRA/Nasdaq TRF (DEPRECATED)
	Dataset_FinnNls Dataset = 17
	// FINRA/NYSE TRF (DEPRECATED)
	Dataset_FinyTrades Dataset = 18
	// OPRA Binary
	Dataset_OpraPillar Dataset = 19
	// Databento US Equities Basic
	Dataset_DbeqBasic Dataset = 20
	// NYSE Arca Integrated
	Dataset_ArcxPillar Dataset = 21
	// IEX TOPS
	Dataset_IexgTops Dataset = 22
	// Databento US Equities Plus
	Dataset_EqusPlus Dataset = 23
	// NYSE BBO
	Dataset_XnysBbo Dataset = 24
	// NYSE Trades
	Dataset_XnysTrades Dataset = 25
	// Nasdaq QBBO
	Dataset_XnasQbbo Dataset = 26
	// Nasdaq NLS
	Dataset_XnasNls Dataset = 27
	// ICE Europe Commodities iMpact
	Dataset_IfeuImpact Dataset = 28
	// ICE Endex iMpact
	Dataset_NdexImpact Dataset = 29
	// Databento US Equities (All Feeds)
	Dataset_EqusAll Dataset = 30
	// Nasdaq Basic (NLS and QBBO)
	Dataset_XnasBasic Dataset = 31
	// Databento US Equities Summary
	Dataset_EqusSummary Dataset = 32
	// NYSE National Trades and BBO
	Dataset_XcisTradesbbo Dataset = 33
	// NYSE Trades and BBO
	Dataset_XnysTradesbbo Dataset = 34
	// Databento US Equities Mini
	Dataset_EqusMini Dataset = 35
	// ICE Futures US iMpact
	Dataset_IfusImpact Dataset = 36
	// ICE Europe Financials iMpact
	Dataset_IfllImpact Dataset = 37
	// Eurex EOBI
	Dataset_XeurEobi Dataset = 38
	// European Energy Exchange EOBI
	Dataset_XeeeEobi Dataset = 39
	// Cboe Futures Exchange PITCH
	Dataset_XcbfPitch Dataset = 40
	// Blue Ocean ATS MEMOIR Depth
	Dataset_OceaMemoir Dataset = 41
)

func DatasetFromString added in v0.7.0

func DatasetFromString(str string) (Dataset, error)

DatasetFromString converts a string to a Dataset. Returns an error if the string is unknown.

func (Dataset) MarshalJSON added in v0.7.0

func (d Dataset) MarshalJSON() ([]byte, error)

func (Dataset) Publishers added in v0.7.0

func (d Dataset) Publishers() []Publisher

Publishers returns all Publisher values associated with this dataset. Tracks https://github.com/databento/dbn/blob/main/rust/dbn/src/publishers.rs#L410

func (*Dataset) Set added in v0.7.0

func (d *Dataset) Set(value string) error

Set implements the flag.Value interface.

func (Dataset) String added in v0.7.0

func (d Dataset) String() string

Returns the string representation of the Dataset, or empty string if unknown.

func (*Dataset) Type added in v0.7.0

func (*Dataset) Type() string

Type implements pflag.Value.Type. Returns "dbn.Dataset".

func (*Dataset) UnmarshalJSON added in v0.7.0

func (d *Dataset) UnmarshalJSON(data []byte) error

type DbnScanner

type DbnScanner struct {
	// contains filtered or unexported fields
}

DbnScanner scans a raw DBN stream

func NewDbnScanner

func NewDbnScanner(sourceReader io.Reader) *DbnScanner

NewDbnScanner creates a new dbn.DbnScanner

func (*DbnScanner) DecodeSymbolMappingMsg added in v0.4.1

func (s *DbnScanner) DecodeSymbolMappingMsg() (*SymbolMappingMsg, error)

DecodeSymbolMappingMsg parses the Scanner's current record as a `SymbolMappingMsg`. This is outside the DbnScannerDecode function because SymbolMappingMsg.Fill_Raw is two-argum,ent, depending on the DbnScanner's metadata's SymbolCstrLen.

func (*DbnScanner) Error

func (s *DbnScanner) Error() error

Error returns the last error from Next(). May be io.EOF.

func (*DbnScanner) GetLastHeader added in v0.0.8

func (s *DbnScanner) GetLastHeader() (RHeader, error)

GetLastHeader returns the RHeader of the last record read, or an error

func (*DbnScanner) GetLastRecord added in v0.0.8

func (s *DbnScanner) GetLastRecord() []byte

GetLastRecord returns the raw bytes of the last record read

func (*DbnScanner) GetLastSize added in v0.0.8

func (s *DbnScanner) GetLastSize() int

GetLastSize returns the size of the last record read

func (*DbnScanner) Metadata

func (s *DbnScanner) Metadata() (*Metadata, error)

Metadata returns the metadata for the stream, or nil if none. May try to read the metadata, which may result in an error.

func (*DbnScanner) Next

func (s *DbnScanner) Next() bool

Next parses the next record from the stream

func (*DbnScanner) Visit

func (s *DbnScanner) Visit(visitor Visitor) error

Parses the current Record and passes it to the Visitor.

type Encoding

type Encoding uint8

/ Encoding A data encoding format.

const (
	/// Databento Binary Encoding.
	Encoding_Dbn Encoding = 0
	/// Comma-separated values.
	Encoding_Csv Encoding = 1
	/// JavaScript object notation.
	Encoding_Json Encoding = 2
)

func EncodingFromString added in v0.0.11

func EncodingFromString(str string) (Encoding, error)

EncodingFromString converts a string to an Encoding. Returns an error if the string is unknown.

func (Encoding) MarshalJSON added in v0.0.13

func (e Encoding) MarshalJSON() ([]byte, error)

func (*Encoding) Set added in v0.0.13

func (e *Encoding) Set(value string) error

Set implements the flag.Value interface.

func (Encoding) String added in v0.0.5

func (e Encoding) String() string

Returns the string representation of the Encoding, or empty string if unknown.

func (*Encoding) Type added in v0.0.13

func (*Encoding) Type() string

Type implements pflag.Value.Type. Returns "dbn.Encoding".

func (*Encoding) UnmarshalJSON added in v0.0.13

func (e *Encoding) UnmarshalJSON(data []byte) error

type ErrorCode added in v0.7.0

type ErrorCode uint8

An error code from the live subscription gateway.

func ErrorCodeFromString added in v0.7.0

func ErrorCodeFromString(str string) (ErrorCode, error)

ErrorCodeFromString converts a string to an ErrorCode. Returns an error if the string is unknown.

func (ErrorCode) MarshalJSON added in v0.7.0

func (e ErrorCode) MarshalJSON() ([]byte, error)

func (ErrorCode) String added in v0.7.0

func (e ErrorCode) String() string

Returns the string representation of the ErrorCode, or empty string if unknown.

func (*ErrorCode) UnmarshalJSON added in v0.7.0

func (e *ErrorCode) UnmarshalJSON(data []byte) error

type ErrorMsg added in v0.0.8

type ErrorMsg struct {
	Header RHeader                `json:"hd" csv:"hd"`           // The common header.
	Error  [ErrorMsg_ErrSize]byte `json:"err" csv:"err"`         // The error message.
	Code   ErrorCode              `json:"code" csv:"code"`       // The error code.
	IsLast uint8                  `json:"is_last" csv:"is_last"` // Sometimes multiple errors are sent together. This field will be non-zero for the last error.
}

func (*ErrorMsg) Fill_Json added in v0.0.8

func (r *ErrorMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*ErrorMsg) Fill_Raw added in v0.0.8

func (r *ErrorMsg) Fill_Raw(b []byte) error

func (*ErrorMsg) RSize added in v0.0.8

func (*ErrorMsg) RSize() uint16

func (*ErrorMsg) RType added in v0.0.8

func (*ErrorMsg) RType() RType

type ImbalanceMsg added in v0.0.11

type ImbalanceMsg struct {
	Header               RHeader `json:"hd" csv:"hd"`                                          // The record header.
	TsRecv               uint64  `json:"ts_recv" csv:"ts_recv"`                                // The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
	RefPrice             int64   `json:"ref_price" csv:"ref_price"`                            // The price at which the imbalance shares are calculated, where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	AuctionTime          uint64  `json:"auction_time" csv:"auction_time"`                      // Reserved for future use.
	ContBookClrPrice     int64   `json:"cont_book_clr_price" csv:"contBook_clr_price"`         // The hypothetical auction-clearing price for both cross and continuous orders.
	AuctInterestClrPrice int64   `json:"auct_interest_clr_price" csv:"auctInterest_clr_price"` // The hypothetical auction-clearing price for cross orders only.
	SsrFillingPrice      int64   `json:"ssr_filling_price" csv:"ssr_filling_price"`            // Reserved for future use.
	IndMatchPrice        int64   `json:"ind_match_price" csv:"ind_match_price"`                // Reserved for future use.
	UpperCollar          int64   `json:"upper_collar" csv:"upper_collar"`                      // Reserved for future use.
	LowerCollar          int64   `json:"lower_collar" csv:"lower_collar"`                      // Reserved for future use.
	PairedQty            uint32  `json:"paired_qty" csv:"paired_qty"`                          // The quantity of shares that are eligible to be matched at `ref_price`.
	TotalImbalanceQty    uint32  `json:"total_imbalance_qty" csv:"total_imbalance_qty"`        // The quantity of shares that are not paired at `ref_price`.
	MarketImbalanceQty   uint32  `json:"market_imbalance_qty" csv:"market_ombalance_qty"`      // Reserved for future use.
	UnpairedQty          int32   `json:"unpaired_qty" csv:"unpaired_qty"`                      // Reserved for future use.
	AuctionType          uint8   `json:"auction_type" csv:"auction_type"`                      // Venue-specific character code indicating the auction type.
	Side                 uint8   `json:"side" csv:"side"`                                      // The market side of the `total_imbalance_qty`. Can be **A**sk, **B**id, or **N**one.
	AuctionStatus        uint8   `json:"auction_status" csv:"auction_status"`                  // Reserved for future use.
	FreezeStatus         uint8   `json:"freeze_status" csv:"freeze_status"`                    // Reserved for future use.
	NumExtensions        uint8   `json:"num_extensions" csv:"num_extensions"`                  // Reserved for future use.
	UnpairedSide         uint8   `json:"unpaired_side" csv:"unpaired_side"`                    // Reserved for future use.
	SignificantImbalance uint8   `json:"significant_imbalance" csv:"significant_imbalance"`    // Venue-specific character code. For Nasdaq, contains the raw Price Variation Indicator.
	Reserved             uint8   `json:"reserved" csv:"reserved"`                              // Filler for alignment.
}

Databento Normalized Imbalance Message {"ts_recv":"1711027500000942123","hd":{"ts_event":"1711027500000776211","rtype":20,"publisher_id":2,"instrument_id":17598},"ref_price":"0","auction_time":"0","cont_book_clr_price":"0","auct_interest_clr_price":"0","ssr_filling_price":"0","ind_match_price":"0","upper_collar":"0","lower_collar":"0","paired_qty":0,"total_imbalance_qty":0,"market_imbalance_qty":0,"unpaired_qty":0,"auction_type":"O","side":"N","auction_status":0,"freeze_status":0,"num_extensions":0,"unpaired_side":"N","significant_imbalance":"~"}

func (*ImbalanceMsg) Fill_Json added in v0.0.11

func (r *ImbalanceMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*ImbalanceMsg) Fill_Raw added in v0.0.11

func (r *ImbalanceMsg) Fill_Raw(b []byte) error

func (*ImbalanceMsg) RSize added in v0.0.11

func (*ImbalanceMsg) RSize() uint16

func (*ImbalanceMsg) RType added in v0.0.11

func (*ImbalanceMsg) RType() RType

type InstrumentClass

type InstrumentClass uint8

InstrumentClass

const (
	// A bond.
	InstrumentClass_Bond InstrumentClass = 'B'
	// A call option.
	InstrumentClass_Call InstrumentClass = 'C'
	// A future.
	InstrumentClass_Future InstrumentClass = 'F'
	// A stock.
	InstrumentClass_Stock InstrumentClass = 'K'
	// A spread composed of multiple instrument classes
	InstrumentClass_MixedSpread InstrumentClass = 'M'
	// A put option
	InstrumentClass_Put InstrumentClass = 'P'
	// A spread composed of futures.
	InstrumentClass_FutureSpread InstrumentClass = 'S'
	// A spread composed of options.
	InstrumentClass_OptionSpread InstrumentClass = 'T'
	// A foreign exchange spot.
	InstrumentClass_FxSpot InstrumentClass = 'X'
	// A commodity spot.
	InstrumentClass_CommoditySpot InstrumentClass = 'Y'
)

func (InstrumentClass) IsFuture added in v0.0.11

func (i InstrumentClass) IsFuture() bool

func (InstrumentClass) IsOption added in v0.0.11

func (i InstrumentClass) IsOption() bool

func (InstrumentClass) IsSpread added in v0.0.11

func (i InstrumentClass) IsSpread() bool

type InstrumentDefMsg added in v0.1.0

type InstrumentDefMsg struct {
	Header                  RHeader                        `json:"hd" csv:"hd"`                                                 // The common header.
	TsRecv                  uint64                         `json:"ts_recv" csv:"ts_recv"`                                       // The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
	MinPriceIncrement       int64                          `json:"min_price_increment" csv:"min_price_increment"`               // Fixed price The minimum constant tick for the instrument in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	DisplayFactor           int64                          `json:"display_factor" csv:"display_factor"`                         // The multiplier to convert the venue’s display price to the conventional price, in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Expiration              uint64                         `json:"expiration" csv:"expiration"`                                 // The last eligible trade time expressed as a number of nanoseconds since the UNIX epoch. Will be [`crate::UNDEF_TIMESTAMP`] when null, such as for equities.  Some publishers only provide date-level granularity.
	Activation              uint64                         `json:"activation" csv:"activation"`                                 // The time of instrument activation expressed as a number of nanoseconds since the UNIX epoch. Will be [`crate::UNDEF_TIMESTAMP`] when null, such as for equities.  Some publishers only provide date-level granularity.
	HighLimitPrice          int64                          `json:"high_limit_price" csv:"high_limit_price"`                     // The allowable high limit price for the trading day in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	LowLimitPrice           int64                          `json:"low_limit_price" csv:"low_limit_price"`                       // The allowable low limit price for the trading day in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	MaxPriceVariation       int64                          `json:"max_price_variation" csv:"max_price_variation"`               // The differential value for price banding in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	TradingReferencePrice   int64                          `json:"trading_reference_price" csv:"trading_reference_price"`       // The trading session settlement price on `trading_reference_date`.
	UnitOfMeasureQty        int64                          `json:"unit_of_measure_qty" csv:"unit_of_measure_qty"`               // The contract size for each instrument, in combination with `unit_of_measure`, in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	MinPriceIncrementAmount int64                          `json:"min_price_increment_amount" csv:"min_price_increment_amount"` // The value currently under development by the venue. Converted to units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	PriceRatio              int64                          `json:"price_ratio" csv:"price_ratio"`                               // The value used for price calculation in spread and leg pricing in units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	StrikePrice             int64                          `json:"strike_price" csv:"strike_price"`                             // The strike price of the option. Converted to units of 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	InstAttribValue         int32                          `json:"inst_attrib_value" csv:"inst_attrib_value"`                   // A bitmap of instrument eligibility attributes.
	UnderlyingID            uint32                         `json:"underlying_id" csv:"underlying_id"`                           // The `instrument_id` of the first underlying instrument.
	RawInstrumentID         uint32                         `json:"raw_instrument_id" csv:"raw_instrument_id"`                   // The instrument ID assigned by the publisher. May be the same as `instrument_id`.
	MarketDepthImplied      int32                          `json:"market_depth_implied" csv:"market_depth_implied"`             // The implied book depth on the price level data feed.
	MarketDepth             int32                          `json:"market_depth" csv:"market_depth"`                             // The (outright) book depth on the price level data feed.
	MarketSegmentID         uint32                         `json:"market_segment_id" csv:"market_segment_id"`                   // The market segment of the instrument.
	MaxTradeVol             uint32                         `json:"max_trade_vol" csv:"max_trade_vol"`                           // The maximum trading volume for the instrument.
	MinLotSize              int32                          `json:"min_lot_size" csv:"min_lot_size"`                             // The minimum order entry quantity for the instrument.
	MinLotSizeBlock         int32                          `json:"min_lot_size_block" csv:"min_lot_size_block"`                 // The minimum quantity required for a block trade of the instrument.
	MinLotSizeRoundLot      int32                          `json:"min_lot_size_round_lot" csv:"min_lot_size_round_lot"`         // The minimum quantity required for a round lot of the instrument. Multiples of this quantity are also round lots.
	MinTradeVol             uint32                         `json:"min_trade_vol" csv:"min_trade_vol"`                           // The minimum trading volume for the instrument.
	ContractMultiplier      int32                          `json:"contract_multiplier" csv:"contract_multiplier"`               // The number of deliverables per instrument, i.e. peak days.
	DecayQuantity           int32                          `json:"decay_quantity" csv:"decay_quantity"`                         // The quantity that a contract will decay daily, after `decay_start_date` has been reached.
	OriginalContractSize    int32                          `json:"original_contract_size" csv:"original_contract_size"`         // The fixed contract value assigned to each instrument.
	TradingReferenceDate    uint16                         `json:"trading_reference_date" csv:"trading_reference_date"`         // The trading session date corresponding to the settlement price in  `trading_reference_price`, in number of days since the UNIX epoch.
	ApplID                  int16                          `json:"appl_id" csv:"appl_id"`                                       // The channel ID assigned at the venue.
	MaturityYear            uint16                         `json:"maturity_year" csv:"maturity_year"`                           // The calendar year reflected in the instrument symbol.
	DecayStartDate          uint16                         `json:"decay_start_date" csv:"decay_start_date"`                     // The date at which a contract will begin to decay.
	ChannelID               uint16                         `json:"channel_id" csv:"channel_id"`                                 // The channel ID assigned by Databento as an incrementing integer starting at zero.
	Currency                [4]byte                        `json:"currency" csv:"currency"`                                     // The currency used for price fields.
	SettlCurrency           [4]byte                        `json:"settl_currency" csv:"settl_currency"`                         // The currency used for settlement, if different from `currency`.
	Secsubtype              [6]byte                        `json:"secsubtype" csv:"secsubtype"`                                 // The strategy type of the spread.
	RawSymbol               [MetadataV2_SymbolCstrLen]byte `json:"raw_symbol" csv:"raw_symbol"`                                 // The instrument raw symbol assigned by the publisher.
	Group                   [21]byte                       `json:"group" csv:"group"`                                           // The security group code of the instrument.
	Exchange                [5]byte                        `json:"exchange" csv:"exchange"`                                     // The exchange used to identify the instrument.
	Asset                   [7]byte                        `json:"asset" csv:"asset"`                                           // The underlying asset code (product code) of the instrument.
	Cfi                     [7]byte                        `json:"cfi" csv:"cfi"`                                               // The ISO standard instrument categorization code.
	SecurityType            [7]byte                        `json:"security_type" csv:"security_type"`                           // The [Security type](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#security-type) of the instrument, e.g. FUT for future or future spread.
	UnitOfMeasure           [31]byte                       `json:"unit_of_measure" csv:"unit_of_measure"`                       // The unit of measure for the instrument’s original contract size, e.g. USD or LBS.
	Underlying              [21]byte                       `json:"underlying" csv:"underlying"`                                 // The symbol of the first underlying instrument.
	StrikePriceCurrency     [4]byte                        `json:"strike_price_currency" csv:"strike_price_currency"`           // The currency of [`strike_price`](Self::strike_price).
	InstrumentClass         byte                           `json:"instrument_class" csv:"instrument_class"`                     // The classification of the instrument.
	MatchAlgorithm          byte                           `json:"match_algorithm" csv:"match_algorithm"`                       // The matching algorithm used for the instrument, typically **F**IFO.
	MdSecurityTradingStatus uint8                          `json:"md_security_trading_status" csv:"md_security_trading_status"` // The current trading state of the instrument.
	MainFraction            uint8                          `json:"main_fraction" csv:"main_fraction"`                           // The price denominator of the main fraction.
	PriceDisplayFormat      uint8                          `json:"price_display_format" csv:"price_display_format"`             // The number of digits to the right of the tick mark, to display fractional prices.
	SettlPrice_type         uint8                          `json:"settl_price_type" csv:"settl_price_type"`                     // The type indicators for the settlement price, as a bitmap.
	SubFraction             uint8                          `json:"sub_fraction" csv:"sub_fraction"`                             // The price denominator of the sub fraction.
	UnderlyingProduct       uint8                          `json:"underlying_product" csv:"underlying_product"`                 // The product complex of the instrument.
	SecurityUpdateAction    byte                           `json:"security_update_action" csv:"security_update_action"`         // Indicates if the instrument definition has been added, modified, or deleted.
	MaturityMonth           uint8                          `json:"maturity_month" csv:"maturity_month"`                         // The calendar month reflected in the instrument symbol.
	MaturityDay             uint8                          `json:"maturity_day" csv:"maturity_day"`                             // The calendar day reflected in the instrument symbol, or 0.
	MaturityWeek            uint8                          `json:"maturity_week" csv:"maturity_week"`                           // The calendar week reflected in the instrument symbol, or 0.
	UserDefinedInstrument   UserDefinedInstrument          `json:"user_defined_instrument" csv:"user_defined_instrument"`       // Indicates if the instrument is user defined: **Y**es or **N**o.
	ContractMultiplierUnit  int8                           `json:"contract_multiplier_unit" csv:"contract_multiplier_unit"`     // The type of `contract_multiplier`. Either `1` for hours, or `2` for days.
	FlowScheduleType        int8                           `json:"flow_schedule_type" csv:"flow_schedule_type"`                 // The schedule for delivering electricity.
	TickRule                uint8                          `json:"tick_rule" csv:"tick_rule"`                                   // The tick rule of the spread.
	Reserved                [10]byte                       `json:"_reserved" csv:"_reserved"`                                   // Filler for alignment.
}

InstrumentDefMsg is a statistics message. A catchall for various data disseminated by publishers. The [`stat_type`](Self::stat_type) indicates the statistic contained in the message. This is not a strict byte-layout because RawSymbol has dynamic length that depends on metadata's SymbolCstrLen.

func (*InstrumentDefMsg) Fill_Json added in v0.1.0

func (r *InstrumentDefMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*InstrumentDefMsg) Fill_Raw added in v0.1.0

func (r *InstrumentDefMsg) Fill_Raw(b []byte) error

func (*InstrumentDefMsg) RSize added in v0.1.0

func (*InstrumentDefMsg) RSize() uint16

func (*InstrumentDefMsg) RType added in v0.1.0

func (*InstrumentDefMsg) RType() RType

type JsonScanner

type JsonScanner struct {
	// contains filtered or unexported fields
}

JsonScanner scans a series of DBN JSON values. Delimited by whitespace (generally newlines)

func NewJsonScanner

func NewJsonScanner(r io.Reader) *JsonScanner

NewJsonScanner creates a new dbn.JsonScanner from a byte array

func (*JsonScanner) Error

func (s *JsonScanner) Error() error

Error returns the last error from Next().

func (*JsonScanner) GetLastRecord added in v0.1.0

func (s *JsonScanner) GetLastRecord() []byte

GetLastRecord returns the raw JSON bytes of the last record read. This data may be overwritten by the next call to Next().

func (*JsonScanner) GetLastSize added in v0.1.0

func (s *JsonScanner) GetLastSize() int

GetLastSize returns the size of the last record read.

func (*JsonScanner) Next

func (s *JsonScanner) Next() bool

Next parses the next JSON value from the data. Returns true on success. Returns false either on error or on the end of data. Call Error() in order to determine the cause of the returned false. Acces the raw data with GetLastRecord, JsonScannerDecocde, or Visit.

func (*JsonScanner) Visit

func (s *JsonScanner) Visit(visitor Visitor) error

Parses the current Record and passes it to the Visitor.

type MappingInterval

type MappingInterval struct {
	StartDate uint32 // The UTC start date of interval (inclusive), as YYYYMMDD
	EndDate   uint32 // The UTC end date of interval (exclusive), as YYYYMMDD.
	Symbol    string // The resolved symbol for this interval.
}

The resolved symbol for a date range.

type MatchAlgorithm

type MatchAlgorithm uint8

MatchAlgorithm

const (
	// First-in-first-out matching.
	MatchAlgorithm_Fifo MatchAlgorithm = 'F'
	// A configurable match algorithm.
	MatchAlgorithm_Configurable MatchAlgorithm = 'K'
	// Trade quantity is allocated to resting orders based on a pro-rata percentage:
	// resting order quantity divided by total quantity.
	MatchAlgorithm_ProRata MatchAlgorithm = 'C'
	// Like [`Self::Fifo`] but with LMM allocations prior to FIFO allocations.
	MatchAlgorithm_FifoLmm MatchAlgorithm = 'T'
	// Like [`Self::ProRata`] but includes a configurable allocation to the first order that improves the market.
	MatchAlgorithm_ThresholdProRata MatchAlgorithm = 'O'
	// Like [`Self::FifoLmm`] but includes a configurable allocation to the first order that improves the market.
	MatchAlgorithm_FifoTopLmm MatchAlgorithm = 'S'
	// Like [`Self::ThresholdProRata`] but includes a special priority to LMMs.
	MatchAlgorithm_ThresholdProRataLmm MatchAlgorithm = 'Q'
	// Special variant used only for Eurodollar futures on CME.
	MatchAlgorithm_EurodollarFutures MatchAlgorithm = 'Y'
	// Trade quantity is shared between all orders at the best price. Orders with the
	// highest time priority receive a higher matched quantity.
	MatchAlgorithm_TimeProRata MatchAlgorithm = 'P'
	// A two-pass FIFO algorithm. The first pass fills the Institutional Group the aggressing
	// order is associated with. The second pass matches orders without an Institutional Group
	// association. See [CME documentation](https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457217267#InstitutionalPrioritizationMatchAlgorithm).
	MatchAlgorithm_InstitutionalPrioritization MatchAlgorithm = 'V'
)

type MboMsg

type MboMsg struct {
	Header    RHeader `json:"hd" csv:"hd"`                   // The record header.
	OrderID   uint64  `json:"order_id" csv:"order_id"`       // The order ID assigned at the venue.
	Price     int64   `json:"price" csv:"price"`             // The order price expressed as a signed integer where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Size      uint32  `json:"size" csv:"size"`               // The order quantity.
	Flags     uint8   `json:"flags" csv:"flags"`             // A bit field indicating event end, message characteristics, and data quality. See [`enums::flags`](crate::enums::flags) for possible values.
	ChannelID uint8   `json:"channel_id" csv:"channel_id"`   // The channel ID assigned by Databento as an incrementing integer starting at zero.
	Action    byte    `json:"action" csv:"action"`           // The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R**,  **T**rade, **F**ill, or **NN**one.
	Side      byte    `json:"side" csv:"side"`               // The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified by the original source.
	TsRecv    uint64  `json:"ts_recv" csv:"ts_recv"`         // The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
	TsInDelta int32   `json:"ts_in_delta" csv:"ts_in_delta"` // The delta of `ts_recv - ts_exchange_send`, max 2 seconds.
	Sequence  uint32  `json:"sequence" csv:"sequence"`       // The message sequence number assigned at the venue.
}

Databento Normalized market-by-order (MBO) message. The record of the [`Mbo`](crate::enums::Schema::Mbo) schema.

func (*MboMsg) Fill_Json added in v0.0.8

func (r *MboMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*MboMsg) Fill_Raw added in v0.0.8

func (r *MboMsg) Fill_Raw(b []byte) error

func (*MboMsg) RSize added in v0.0.8

func (*MboMsg) RSize() uint16

func (*MboMsg) RType added in v0.0.8

func (*MboMsg) RType() RType

type Mbp0Msg added in v0.0.11

type Mbp0Msg struct {
	Header    RHeader `json:"hd" csv:"hd"`                   // The record header.
	Price     int64   `json:"price" csv:"price"`             // The order price where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Size      uint32  `json:"size" csv:"size"`               // The order quantity.
	Action    uint8   `json:"action" csv:"action"`           // The event action. Always Trade in the trades schema. See Action.
	Side      uint8   `json:"side" csv:"side"`               // The side that initiates the event. Can be Ask for a sell aggressor, Bid for a buy aggressor, or None where no side is specified by the original trade.
	Flags     uint8   `json:"flags" csv:"flags"`             // A bit field indicating packet end, message characteristics, and data quality. See Flags.
	Depth     uint8   `json:"depth" csv:"depth"`             // The book level where the update event occurred.
	TsRecv    uint64  `json:"ts_recv" csv:"ts_recv"`         // The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
	TsInDelta int32   `json:"ts_in_delta" csv:"ts_in_delta"` // The matching-engine-sending timestamp expressed as the number of nanoseconds before ts_recv.
	Sequence  uint32  `json:"sequence" csv:"sequence"`       // The message sequence number assigned at the venue.
}

Databento Normalized Mbp0 message (Market-by-price depth0) {"ts_recv":"1704186000404085841","hd":{"ts_event":"1704186000403918695","rtype":0,"publisher_id":2,"instrument_id":15144},"action":"T","side":"B","depth":0,"price":"476370000000","size":40,"flags":130,"ts_in_delta":167146,"sequence":277449,"symbol":"SPY"}

func (*Mbp0Msg) Fill_Json added in v0.0.11

func (r *Mbp0Msg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*Mbp0Msg) Fill_Raw added in v0.0.11

func (r *Mbp0Msg) Fill_Raw(b []byte) error

func (*Mbp0Msg) RSize added in v0.0.11

func (*Mbp0Msg) RSize() uint16

func (*Mbp0Msg) RType added in v0.0.11

func (*Mbp0Msg) RType() RType

type Mbp1Msg added in v0.0.8

type Mbp1Msg struct {
	Header    RHeader    `json:"hd" csv:"hd"`                   // The record header.
	Price     int64      `json:"price" csv:"price"`             // The order price expressed as a signed integer where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Size      uint32     `json:"size" csv:"size"`               // The order quantity.
	Action    byte       `json:"action" csv:"action"`           // The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R**, or **T**rade.
	Side      byte       `json:"side" csv:"side"`               // The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified by the original source.
	Flags     uint8      `json:"flags" csv:"flags"`             // A bit field indicating event end, message characteristics, and data quality. See [`enums::flags`](crate::enums::flags) for possible values.
	Depth     uint8      `json:"depth" csv:"depth"`             // The depth of actual book change.
	TsRecv    uint64     `json:"ts_recv" csv:"ts_recv"`         // The capture-server-received timestamp expressed as number of nanoseconds since the UNIX epoch.
	TsInDelta int32      `json:"ts_in_delta" csv:"ts_in_delta"` // The delta of `ts_recv - ts_exchange_send`, max 2 seconds.
	Sequence  uint32     `json:"sequence" csv:"sequence"`       // The message sequence number assigned at the venue.
	Level     BidAskPair `json:"levels" csv:"levels"`           // The top of the order book.
}

Databento Normalized market-by-price (MBP) implementation with a known book depth of 1. The record of the [`Mbp1`](crate::enums::Schema::Mbp1) schema.

func (*Mbp1Msg) Fill_Json added in v0.0.8

func (r *Mbp1Msg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*Mbp1Msg) Fill_Raw added in v0.0.8

func (r *Mbp1Msg) Fill_Raw(b []byte) error

func (*Mbp1Msg) RSize added in v0.0.8

func (*Mbp1Msg) RSize() uint16

func (*Mbp1Msg) RType added in v0.0.8

func (*Mbp1Msg) RType() RType

type Mbp10Msg added in v0.0.8

type Mbp10Msg struct {
	Header    RHeader        `json:"hd" csv:"hd"`                   // The record header.
	Price     int64          `json:"price" csv:"price"`             // The order price expressed as a signed integer where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001.
	Size      uint32         `json:"size" csv:"size"`               // The order quantity.
	Action    byte           `json:"action" csv:"action"`           // The event action. Can be **A**dd, **C**ancel, **M**odify, clea**R**, or **T**rade.
	Side      byte           `json:"side" csv:"side"`               // The side that initiates the event. Can be **A**sk for a sell order (or sell aggressor in a trade), **B**id for a buy order (or buy aggressor in a trade), or **N**one where no side is specified by the original source.
	Flags     uint8          `json:"flags" csv:"flags"`             // A bit field indicating event end, message characteristics, and data quality. See [`enums::flags`](crate::enums::flags) for possible values.
	Depth     uint8          `json:"depth" csv:"depth"`             // The depth of actual book change.
	TsRecv    uint64         `json:"ts_recv" csv:"ts_recv"`         // The capture-server-received timestamp expressed as number of nanoseconds since the UNIX epoch.
	TsInDelta int32          `json:"ts_in_delta" csv:"ts_in_delta"` // The delta of `ts_recv - ts_exchange_send`, max 2 seconds.
	Sequence  uint32         `json:"sequence" csv:"sequence"`       // The message sequence number assigned at the venue.
	Levels    [10]BidAskPair `json:"levels" csv:"levels"`           // The top 10 levels of the order book.
}

Databento Normalized market-by-price implementation with a known book depth of 10. The record of the [`Mbp10`](crate::enums::Schema::Mbp10) schema.

func (*Mbp10Msg) Fill_Json added in v0.0.8

func (r *Mbp10Msg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*Mbp10Msg) Fill_Raw added in v0.0.8

func (r *Mbp10Msg) Fill_Raw(b []byte) error

func (*Mbp10Msg) RSize added in v0.0.8

func (*Mbp10Msg) RSize() uint16

func (*Mbp10Msg) RType added in v0.0.8

func (*Mbp10Msg) RType() RType

type Metadata

type Metadata struct {
	VersionNum       uint8
	Schema           Schema // The data record schema. u16::MAX indicates a potential mix of schemas and record types, which will always be the case for live data.
	Start            uint64 // The start time of query range in UNIX epoch nanoseconds.
	End              uint64 // The end time of query range in UNIX epoch nanoseconds. u64::MAX indicates no end time was provided.
	Limit            uint64 // The maximum number of records to return. 0 indicates no limit.
	StypeIn          SType  // The symbology type of input symbols. u8::MAX indicates a potential mix of types, such as with live data.
	StypeOut         SType  // The symbology type of output symbols.
	TsOut            uint8  // Whether each record has an appended gateway send timestamp.
	SymbolCstrLen    uint16 // The number of bytes in fixed-length string symbols, including a null terminator byte. Version 2 only, symbol strings are always 22 in version 1.
	Dataset          string
	SchemaDefinition []byte // Self-describing schema to be implemented in the future.
	Symbols          []string
	Partial          []string
	NotFound         []string
	Mappings         []SymbolMapping
}

Normalized Metadata about the data contained in a DBN file or stream. DBN requires the Metadata to be included at the start of the encoded data.

func ReadDBNToSlice

func ReadDBNToSlice[R Record, RP RecordPtr[R]](reader io.Reader) ([]R, *Metadata, error)

ReadDBNToSlice reads the entire raw DBN stream from an io.Reader. It will scan for type R (for example Mbp0) and decode it into a slice of R. Returns the slice, the stream's metadata, and any error. Example:

fileReader, err := os.Open(dbnFilename)
records, metadata, err := dbn.ReadDBNToSlice[dbn.Mbp0Msg](fileReader)

func ReadMetadata

func ReadMetadata(r io.Reader) (*Metadata, error)

ReadMetadata reads the Metadata from a DBN stream over an io.Reader.

func (*Metadata) IsInverseMapping

func (m *Metadata) IsInverseMapping() (bool, error)

IsInverseMapping returns true if the map goes from InstrumentId to some other type. Returns an error if neither of the STypes are InstrumentId.

func (*Metadata) Write added in v0.0.8

func (m *Metadata) Write(writer io.Writer) error

Write writes out a Metadata to a DBN stream over an io.Writer. Returns any error.

type MetadataHeaderV1

type MetadataHeaderV1 struct {
	DatasetRaw [Metadata_DatasetCstrLen]byte // The dataset code (string identifier).
	Schema     Schema                        // The data record schema. u16::MAX indicates a potential mix of schemas and record types, which will always be the case for live data.
	Start      uint64                        // The start time of query range in UNIX epoch nanoseconds.
	End        uint64                        // The end time of query range in UNIX epoch nanoseconds. u64::MAX indicates no end time was provided.
	Limit      uint64                        // The maximum number of records to return. 0 indicates no limit.
	ReservedX  [8]byte                       // Reserved padding
	StypeIn    SType                         // The symbology type of input symbols. u8::MAX indicates a potential mix of types, such as with live data.
	StypeOut   SType                         // The symbology type of output symbols.
	TsOut      uint8                         // Whether each record has an appended gateway send timestamp.
	Reserved   [MetadataV1_ReservedLen]byte  // Reserved padding, after is dynamically sized section
}

Raw DBN Metadata Header V1. Every DBN file begins with this header, followed by variable length fields. See Metadata for the full nomralized decoded structure.

func (*MetadataHeaderV1) FillFixed_Raw

func (m1 *MetadataHeaderV1) FillFixed_Raw(b []byte) error

type MetadataHeaderV2

type MetadataHeaderV2 struct {
	DatasetRaw    [Metadata_DatasetCstrLen]byte // The dataset code (string identifier).
	Schema        Schema                        // The data record schema. u16::MAX indicates a potential mix of schemas and record types, which will always be the case for live data.
	Start         uint64                        // The start time of query range in UNIX epoch nanoseconds.
	End           uint64                        // The end time of query range in UNIX epoch nanoseconds. u64::MAX indicates no end time was provided.
	Limit         uint64                        // The maximum number of records to return. 0 indicates no limit.
	StypeIn       SType                         // The symbology type of input symbols. u8::MAX indicates a potential mix of types, such as with live data.
	StypeOut      SType                         // The symbology type of output symbols.
	TsOut         uint8                         // Whether each record has an appended gateway send timestamp.
	SymbolCstrLen uint16                        // The number of bytes in fixed-length string symbols, including a null terminator byte. Version 2 only, symbol strings are always 22 in version 1.
	Reserved      [MetadataV2_ReservedLen]byte  // Reserved padding, after is dynamically sized section
}

Raw DBN Metadata Header V2. Every DBN file begins with this header, followed by variable length fields. See Metadata for the full nomralized decoded structure.

func (*MetadataHeaderV2) FillFixed_Raw

func (m2 *MetadataHeaderV2) FillFixed_Raw(b []byte) error

type MetadataPrefix

type MetadataPrefix struct {
	VersionRaw [4]byte // "DBN" followed by the version of DBN the file is encoded in as a u8.
	Length     uint32  // The length of the remaining metadata header, i.e. excluding MetadataPrefix
}

The start of every Metadata header, independent of version

type NullVisitor added in v0.0.8

type NullVisitor struct {
}

NullVisitor is an implementation of all the dbn.Visitor interface. It is useful for copy/pasting to ones own implementation.

func (*NullVisitor) OnBbo added in v0.6.3

func (v *NullVisitor) OnBbo(record *BboMsg) error

func (*NullVisitor) OnCmbp1 added in v0.6.0

func (v *NullVisitor) OnCmbp1(record *Cmbp1Msg) error

func (*NullVisitor) OnErrorMsg added in v0.0.8

func (v *NullVisitor) OnErrorMsg(record *ErrorMsg) error

func (*NullVisitor) OnImbalance added in v0.0.8

func (v *NullVisitor) OnImbalance(record *ImbalanceMsg) error

func (*NullVisitor) OnInstrumentDefMsg added in v0.1.0

func (v *NullVisitor) OnInstrumentDefMsg(record *InstrumentDefMsg) error

func (*NullVisitor) OnMbo added in v0.0.8

func (v *NullVisitor) OnMbo(record *MboMsg) error

func (*NullVisitor) OnMbp0 added in v0.0.8

func (v *NullVisitor) OnMbp0(record *Mbp0Msg) error

func (*NullVisitor) OnMbp1 added in v0.0.8

func (v *NullVisitor) OnMbp1(record *Mbp1Msg) error

func (*NullVisitor) OnMbp10 added in v0.0.8

func (v *NullVisitor) OnMbp10(record *Mbp10Msg) error

func (*NullVisitor) OnOhlcv added in v0.0.8

func (v *NullVisitor) OnOhlcv(record *OhlcvMsg) error

func (*NullVisitor) OnStatMsg added in v0.0.8

func (v *NullVisitor) OnStatMsg(record *StatMsg) error

func (*NullVisitor) OnStatusMsg added in v0.1.0

func (v *NullVisitor) OnStatusMsg(record *StatusMsg) error

func (*NullVisitor) OnStreamEnd added in v0.0.8

func (v *NullVisitor) OnStreamEnd() error

func (*NullVisitor) OnSymbolMappingMsg added in v0.0.8

func (v *NullVisitor) OnSymbolMappingMsg(record *SymbolMappingMsg) error

func (*NullVisitor) OnSystemMsg added in v0.0.8

func (v *NullVisitor) OnSystemMsg(record *SystemMsg) error

type OhlcvMsg added in v0.0.11

type OhlcvMsg struct {
	Header RHeader `json:"hd" csv:"hd"`         // The record header.
	Open   int64   `json:"open" csv:"open"`     // The open price for the bar.
	High   int64   `json:"high" csv:"high"`     // The high price for the bar.
	Low    int64   `json:"low" csv:"low"`       // The low price for the bar.
	Close  int64   `json:"close" csv:"close"`   // The close price for the bar.
	Volume uint64  `json:"volume" csv:"volume"` // The total volume traded during the aggregation period.
}

Databento Normalized Ohlcv Message (OHLC candlestick, bar) {"hd":{"ts_event":"1702987922000000000","rtype":32,"publisher_id":40,"instrument_id":15144},"open":"472600000000","high":"472600000000","low":"472600000000","close":"472600000000","volume":"300"}

func (*OhlcvMsg) Fill_Json added in v0.0.11

func (r *OhlcvMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*OhlcvMsg) Fill_Raw added in v0.0.11

func (r *OhlcvMsg) Fill_Raw(b []byte) error

func (*OhlcvMsg) RSize added in v0.0.11

func (*OhlcvMsg) RSize() uint16

func (*OhlcvMsg) RType added in v0.0.11

func (*OhlcvMsg) RType() RType

type PitSymbolMap

type PitSymbolMap struct {
	// contains filtered or unexported fields
}

PitSymbolMap is 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. TOOD: handle nuance of int<>string and string<>string mappings based on SType

func NewPitSymbolMap

func NewPitSymbolMap() *PitSymbolMap

func (*PitSymbolMap) FillFromMetadata

func (p *PitSymbolMap) FillFromMetadata(metadata *Metadata, timestamp uint64) error

Fills the PitSymbolMap with mappings from `metadata` for `date`, clearing any original contents Returns an error if any.

func (*PitSymbolMap) Get

func (p *PitSymbolMap) Get(instrumentID uint32) string

Returns the string mapping of the instrument ID, or empty string if not found.

func (*PitSymbolMap) IsEmpty

func (p *PitSymbolMap) IsEmpty() bool

IsEmpty returns `true` if there are no mappings.

func (*PitSymbolMap) Len

func (p *PitSymbolMap) Len() int

Returns the number of symbol mappings in the map.

func (*PitSymbolMap) OnSymbolMappingMsg

func (p *PitSymbolMap) OnSymbolMappingMsg(symbolMapping *SymbolMappingMsg) error

OnSymbolMappingMsg handles updating the mappings (if required) for a SymbolMappingMsg record.

type Publisher added in v0.7.0

type Publisher uint16

Publisher is a specific Venue from a specific data source.

const (
	// CME Globex MDP 3.0
	Publisher_GlbxMdp3Glbx Publisher = 1
	// Nasdaq TotalView-ITCH
	Publisher_XnasItchXnas Publisher = 2
	// Nasdaq BX TotalView-ITCH
	Publisher_XbosItchXbos Publisher = 3
	// Nasdaq PSX TotalView-ITCH
	Publisher_XpsxItchXpsx Publisher = 4
	// Cboe BZX Depth
	Publisher_BatsPitchBats Publisher = 5
	// Cboe BYX Depth
	Publisher_BatyPitchBaty Publisher = 6
	// Cboe EDGA Depth
	Publisher_EdgaPitchEdga Publisher = 7
	// Cboe EDGX Depth
	Publisher_EdgxPitchEdgx Publisher = 8
	// NYSE Integrated
	Publisher_XnysPillarXnys Publisher = 9
	// NYSE National Integrated
	Publisher_XcisPillarXcis Publisher = 10
	// NYSE American Integrated
	Publisher_XasePillarXase Publisher = 11
	// NYSE Texas Integrated
	Publisher_XchiPillarXchi Publisher = 12
	// NYSE National BBO
	Publisher_XcisBboXcis Publisher = 13
	// NYSE National Trades
	Publisher_XcisTradesXcis Publisher = 14
	// MEMX Memoir Depth
	Publisher_MemxMemoirMemx Publisher = 15
	// MIAX Pearl Depth
	Publisher_EprlDomEprl Publisher = 16
	// FINRA/Nasdaq TRF Carteret
	Publisher_XnasNlsFinn Publisher = 17
	// FINRA/Nasdaq TRF Chicago
	Publisher_XnasNlsFinc Publisher = 18
	// FINRA/NYSE TRF
	Publisher_XnysTradesFiny Publisher = 19
	// OPRA - NYSE American Options
	Publisher_OpraPillarAmxo Publisher = 20
	// OPRA - BOX Options
	Publisher_OpraPillarXbox Publisher = 21
	// OPRA - Cboe Options
	Publisher_OpraPillarXcbo Publisher = 22
	// OPRA - MIAX Emerald
	Publisher_OpraPillarEmld Publisher = 23
	// OPRA - Cboe EDGX Options
	Publisher_OpraPillarEdgo Publisher = 24
	// OPRA - Nasdaq GEMX
	Publisher_OpraPillarGmni Publisher = 25
	// OPRA - Nasdaq ISE
	Publisher_OpraPillarXisx Publisher = 26
	// OPRA - Nasdaq MRX
	Publisher_OpraPillarMcry Publisher = 27
	// OPRA - MIAX Options
	Publisher_OpraPillarXmio Publisher = 28
	// OPRA - NYSE Arca Options
	Publisher_OpraPillarArco Publisher = 29
	// OPRA - Options Price Reporting Authority
	Publisher_OpraPillarOpra Publisher = 30
	// OPRA - MIAX Pearl
	Publisher_OpraPillarMprl Publisher = 31
	// OPRA - Nasdaq Options
	Publisher_OpraPillarXndq Publisher = 32
	// OPRA - Nasdaq BX Options
	Publisher_OpraPillarXbxo Publisher = 33
	// OPRA - Cboe C2 Options
	Publisher_OpraPillarC2Ox Publisher = 34
	// OPRA - Nasdaq PHLX
	Publisher_OpraPillarXphl Publisher = 35
	// OPRA - Cboe BZX Options
	Publisher_OpraPillarBato Publisher = 36
	// OPRA - MEMX Options
	Publisher_OpraPillarMxop Publisher = 37
	// IEX TOPS
	Publisher_IexgTopsIexg Publisher = 38
	// DBEQ Basic - NYSE Texas
	Publisher_DbeqBasicXchi Publisher = 39
	// DBEQ Basic - NYSE National
	Publisher_DbeqBasicXcis Publisher = 40
	// DBEQ Basic - IEX
	Publisher_DbeqBasicIexg Publisher = 41
	// DBEQ Basic - MIAX Pearl
	Publisher_DbeqBasicEprl Publisher = 42
	// NYSE Arca Integrated
	Publisher_ArcxPillarArcx Publisher = 43
	// NYSE BBO
	Publisher_XnysBboXnys Publisher = 44
	// NYSE Trades
	Publisher_XnysTradesXnys Publisher = 45
	// Nasdaq QBBO
	Publisher_XnasQbboXnas Publisher = 46
	// Nasdaq Trades
	Publisher_XnasNlsXnas Publisher = 47
	// Databento US Equities Plus - NYSE Texas
	Publisher_EqusPlusXchi Publisher = 48
	// Databento US Equities Plus - NYSE National
	Publisher_EqusPlusXcis Publisher = 49
	// Databento US Equities Plus - IEX
	Publisher_EqusPlusIexg Publisher = 50
	// Databento US Equities Plus - MIAX Pearl
	Publisher_EqusPlusEprl Publisher = 51
	// Databento US Equities Plus - Nasdaq
	Publisher_EqusPlusXnas Publisher = 52
	// Databento US Equities Plus - NYSE
	Publisher_EqusPlusXnys Publisher = 53
	// Databento US Equities Plus - FINRA/Nasdaq TRF Carteret
	Publisher_EqusPlusFinn Publisher = 54
	// Databento US Equities Plus - FINRA/NYSE TRF
	Publisher_EqusPlusFiny Publisher = 55
	// Databento US Equities Plus - FINRA/Nasdaq TRF Chicago
	Publisher_EqusPlusFinc Publisher = 56
	// ICE Europe Commodities
	Publisher_IfeuImpactIfeu Publisher = 57
	// ICE Endex
	Publisher_NdexImpactNdex Publisher = 58
	// Databento US Equities Basic - Consolidated
	Publisher_DbeqBasicDbeq Publisher = 59
	// EQUS Plus - Consolidated
	Publisher_EqusPlusEqus Publisher = 60
	// OPRA - MIAX Sapphire
	Publisher_OpraPillarSphr Publisher = 61
	// Databento US Equities (All Feeds) - NYSE Texas
	Publisher_EqusAllXchi Publisher = 62
	// Databento US Equities (All Feeds) - NYSE National
	Publisher_EqusAllXcis Publisher = 63
	// Databento US Equities (All Feeds) - IEX
	Publisher_EqusAllIexg Publisher = 64
	// Databento US Equities (All Feeds) - MIAX Pearl
	Publisher_EqusAllEprl Publisher = 65
	// Databento US Equities (All Feeds) - Nasdaq
	Publisher_EqusAllXnas Publisher = 66
	// Databento US Equities (All Feeds) - NYSE
	Publisher_EqusAllXnys Publisher = 67
	// Databento US Equities (All Feeds) - FINRA/Nasdaq TRF Carteret
	Publisher_EqusAllFinn Publisher = 68
	// Databento US Equities (All Feeds) - FINRA/NYSE TRF
	Publisher_EqusAllFiny Publisher = 69
	// Databento US Equities (All Feeds) - FINRA/Nasdaq TRF Chicago
	Publisher_EqusAllFinc Publisher = 70
	// Databento US Equities (All Feeds) - Cboe BZX
	Publisher_EqusAllBats Publisher = 71
	// Databento US Equities (All Feeds) - Cboe BYX
	Publisher_EqusAllBaty Publisher = 72
	// Databento US Equities (All Feeds) - Cboe EDGA
	Publisher_EqusAllEdga Publisher = 73
	// Databento US Equities (All Feeds) - Cboe EDGX
	Publisher_EqusAllEdgx Publisher = 74
	// Databento US Equities (All Feeds) - Nasdaq BX
	Publisher_EqusAllXbos Publisher = 75
	// Databento US Equities (All Feeds) - Nasdaq PSX
	Publisher_EqusAllXpsx Publisher = 76
	// Databento US Equities (All Feeds) - MEMX
	Publisher_EqusAllMemx Publisher = 77
	// Databento US Equities (All Feeds) - NYSE American
	Publisher_EqusAllXase Publisher = 78
	// Databento US Equities (All Feeds) - NYSE Arca
	Publisher_EqusAllArcx Publisher = 79
	// Databento US Equities (All Feeds) - Long-Term Stock Exchange
	Publisher_EqusAllLtse Publisher = 80
	// Nasdaq Basic - Nasdaq
	Publisher_XnasBasicXnas Publisher = 81
	// Nasdaq Basic - FINRA/Nasdaq TRF Carteret
	Publisher_XnasBasicFinn Publisher = 82
	// Nasdaq Basic - FINRA/Nasdaq TRF Chicago
	Publisher_XnasBasicFinc Publisher = 83
	// ICE Europe - Off-Market Trades
	Publisher_IfeuImpactXoff Publisher = 84
	// ICE Endex - Off-Market Trades
	Publisher_NdexImpactXoff Publisher = 85
	// Nasdaq NLS - Nasdaq BX
	Publisher_XnasNlsXbos Publisher = 86
	// Nasdaq NLS - Nasdaq PSX
	Publisher_XnasNlsXpsx Publisher = 87
	// Nasdaq Basic - Nasdaq BX
	Publisher_XnasBasicXbos Publisher = 88
	// Nasdaq Basic - Nasdaq PSX
	Publisher_XnasBasicXpsx Publisher = 89
	// Databento Equities Summary
	Publisher_EqusSummaryEqus Publisher = 90
	// NYSE National Trades and BBO
	Publisher_XcisTradesbboXcis Publisher = 91
	// NYSE Trades and BBO
	Publisher_XnysTradesbboXnys Publisher = 92
	// Nasdaq Basic - Consolidated
	Publisher_XnasBasicEqus Publisher = 93
	// Databento US Equities (All Feeds) - Consolidated
	Publisher_EqusAllEqus Publisher = 94
	// Databento US Equities Mini
	Publisher_EqusMiniEqus Publisher = 95
	// NYSE Trades - Consolidated
	Publisher_XnysTradesEqus Publisher = 96
	// ICE Futures US
	Publisher_IfusImpactIfus Publisher = 97
	// ICE Futures US - Off-Market Trades
	Publisher_IfusImpactXoff Publisher = 98
	// ICE Europe Financials
	Publisher_IfllImpactIfll Publisher = 99
	// ICE Europe Financials - Off-Market Trades
	Publisher_IfllImpactXoff Publisher = 100
	// Eurex EOBI
	Publisher_XeurEobiXeur Publisher = 101
	// European Energy Exchange EOBI
	Publisher_XeeeEobiXeee Publisher = 102
	// Eurex EOBI - Off-Market Trades
	Publisher_XeurEobiXoff Publisher = 103
	// European Energy Exchange EOBI - Off-Market Trades
	Publisher_XeeeEobiXoff Publisher = 104
	// Cboe Futures Exchange
	Publisher_XcbfPitchXcbf Publisher = 105
	// Cboe Futures Exchange - Off-Market Trades
	Publisher_XcbfPitchXoff Publisher = 106
	// Blue Ocean ATS MEMOIR
	Publisher_OceaMemoirOcea Publisher = 107
)

func PublisherFromDatasetVenue added in v0.7.0

func PublisherFromDatasetVenue(dataset Dataset, venue Venue) (Publisher, error)

PublisherFromDatasetVenue constructs a Publisher from its Dataset and Venue components. Returns an error if there's no Publisher with the corresponding Dataset and Venue combination.

func PublisherFromString added in v0.7.0

func PublisherFromString(str string) (Publisher, error)

PublisherFromString converts a string to a Publisher. Returns an error if the string is unknown.

func (Publisher) Dataset added in v0.7.0

func (p Publisher) Dataset() Dataset

Dataset returns the publisher's Dataset.

func (Publisher) MarshalJSON added in v0.7.0

func (p Publisher) MarshalJSON() ([]byte, error)

func (*Publisher) Set added in v0.7.0

func (p *Publisher) Set(value string) error

Set implements the flag.Value interface.

func (Publisher) String added in v0.7.0

func (p Publisher) String() string

Returns the string representation of the Publisher, or empty string if unknown.

func (*Publisher) Type added in v0.7.0

func (*Publisher) Type() string

Type implements pflag.Value.Type. Returns "dbn.Publisher".

func (*Publisher) UnmarshalJSON added in v0.7.0

func (p *Publisher) UnmarshalJSON(data []byte) error

func (Publisher) Venue added in v0.7.0

func (p Publisher) Venue() Venue

Venue returns the publisher's Venue.

type RHeader

type RHeader struct {
	Length       uint8  `json:"len,omitempty"`                     // The length of the record in 32-bit words.
	RType        RType  `json:"rtype" csv:"rtype"`                 // Sentinel values for different DBN record types.
	PublisherID  uint16 `json:"publisher_id" csv:"publisher_id"`   // The publisher ID assigned by Databento, which denotes the dataset and venue.
	InstrumentID uint32 `json:"instrument_id" csv:"instrument_id"` // The numeric instrument ID.
	TsEvent      uint64 `json:"ts_event" csv:"ts_event"`           // The matching-engine-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
}

Databento Normalized Record Header {"ts_event":"1704186000403918695","rtype":0,"publisher_id":2,"instrument_id":15144}

func (*RHeader) Fill_Json added in v0.0.8

func (h *RHeader) Fill_Json(val *fastjson.Value) error

func (*RHeader) Fill_Raw added in v0.0.8

func (h *RHeader) Fill_Raw(b []byte) error

func (*RHeader) RSize

func (h *RHeader) RSize() uint16

type RType

type RType uint8
const (
	// Sentinel values for different DBN record types.
	// comments from: https://github.com/databento/dbn/blob/main/rust/dbn/src/enums.rs
	RType_Mbp0            RType = 0x00 // Denotes a market-by-price record with a book depth of 0 (used for the Trades schema)
	RType_Mbp1            RType = 0x01 // Denotes a market-by-price record with a book depth of 1 (also used for the Tbbo schema)
	RType_Mbp10           RType = 0x0A // Denotes a market-by-price record with a book depth of 10.
	RType_OhlcvDeprecated RType = 0x11 // Deprecated in 0.4.0. Denotes an open, high, low, close, and volume record at an unspecified cadence.
	RType_Ohlcv1S         RType = 0x20 // Denotes an open, high, low, close, and volume record at a 1-second cadence.
	RType_Ohlcv1M         RType = 0x21 // Denotes an open, high, low, close, and volume record at a 1-minute cadence.
	RType_Ohlcv1H         RType = 0x22 // Denotes an open, high, low, close, and volume record at an hourly cadence.
	RType_Ohlcv1D         RType = 0x23 // Denotes an open, high, low, close, and volume record at a daily cadence based on the UTC date.
	RType_OhlcvEod        RType = 0x24 // Denotes an open, high, low, close, and volume record at a daily cadence based on the end of the trading session.
	RType_Status          RType = 0x12 // Denotes an exchange status record.
	RType_InstrumentDef   RType = 0x13 // Denotes an instrument definition record.
	RType_Imbalance       RType = 0x14 // Denotes an order imbalance record.
	RType_Error           RType = 0x15 // Denotes an error from gateway.
	RType_SymbolMapping   RType = 0x16 // Denotes a symbol mapping record.
	RType_System          RType = 0x17 // Denotes a non-error message from the gateway. Also used for heartbeats.
	RType_Statistics      RType = 0x18 // Denotes a statistics record from the publisher (not calculated by Databento).
	RType_Mbo             RType = 0xA0 // Denotes a market by order record.
	RType_Cmbp1           RType = 0xB1 // Denotes a consolidated best bid and offer record.
	RType_Cbbo1S          RType = 0xC0 // Denotes a consolidated best bid and offer record subsampled on a one-second interval.
	RType_Cbbo1M          RType = 0xC1 // Denotes a consolidated best bid and offer record subsampled on a one-minute interval.
	RType_Tcbbo           RType = 0xC2 // Denotes a consolidated best bid and offer trade record containing the consolidated BBO before the trade.
	RType_Bbo1S           RType = 0xC3 // Denotes a best bid and offer record subsampled on a one-second interval.
	RType_Bbo1M           RType = 0xC4 // Denotes a best bid and offer record subsampled on a one-minute interval.
	RType_Unknown         RType = 0xFF // Golang-only: Unknown or invalid record type
)

func (RType) IsBbo added in v0.6.3

func (rtype RType) IsBbo() bool

func (RType) IsCandle

func (rtype RType) IsCandle() bool

func (RType) IsCompatibleWith

func (rtype RType) IsCompatibleWith(rtype2 RType) bool

func (RType) String added in v0.0.8

func (s RType) String() string

Returns the string representation of the RType, or empty string if unknown.

type Record

type Record interface {
}

Interface Type for Record Decoding

type RecordPtr

type RecordPtr[T any] interface {
	*T     // constrain to T or its pointer
	Record // T must implement record

	RType() RType
	RSize() uint16
	Fill_Raw([]byte) error
	Fill_Json(val *fastjson.Value, header *RHeader) error
}

type SType

type SType uint8

SType Symbology type

const (
	/// Symbology using a unique numeric ID.
	SType_InstrumentId SType = 0
	/// Symbology using the original symbols provided by the publisher.
	SType_RawSymbol SType = 1
	/// Deprecated: A set of Databento-specific symbologies for referring to groups of symbols.
	SType_Smart SType = 2
	/// A Databento-specific symbology where one symbol may point to different
	/// instruments at different points of time, e.g. to always refer to the front month
	/// future.
	SType_Continuous SType = 3
	/// A Databento-specific symbology for referring to a group of symbols by one
	/// "parent" symbol, e.g. ES.FUT to refer to all ES futures.
	SType_Parent SType = 4
	/// Symbology for US equities using NASDAQ Integrated suffix conventions.
	SType_NasdaqSymbol SType = 5
	/// Symbology for US equities using CMS suffix conventions.
	SType_CmsSymbol SType = 6
	/// Symbology using International Security Identification Numbers (ISIN) - ISO 6166.
	SType_Isin SType = 7
	/// Symbology using US domestic Committee on Uniform Securities Identification Procedure (CUSIP) codes.
	SType_UsCode SType = 8
	/// Symbology using Bloomberg composite global IDs.
	SType_BbgCompId SType = 9
	/// Symbology using Bloomberg composite tickers.
	SType_BbgCompTicker SType = 10
	/// Symbology using Bloomberg FIGI exchange level IDs.
	SType_Figi SType = 11
	/// Symbology using Bloomberg exchange level tickers.
	SType_FigiTicker SType = 12
)

func STypeFromString added in v0.0.11

func STypeFromString(str string) (SType, error)

STypeFromString converts a string to an SType. Returns an error if the string is unknown. Possible string values: instrument_id, id, instr, raw_symbol, raw, smart, continuous, parent, nasdaq, cms

func (SType) MarshalJSON added in v0.0.13

func (s SType) MarshalJSON() ([]byte, error)

func (*SType) Set added in v0.0.13

func (s *SType) Set(value string) error

Set implements the flag.Value interface.

func (SType) String added in v0.0.5

func (s SType) String() string

Returns the string representation of the SType, or empty string if unknown.

func (*SType) Type added in v0.0.13

func (*SType) Type() string

Type implements pflag.Value.Type. Returns "dbn.SType".

func (*SType) UnmarshalJSON added in v0.0.13

func (s *SType) UnmarshalJSON(data []byte) error

type Schema

type Schema uint16
const (
	/// The data record schema. u16::MAX indicates a potential mix of schemas and record types, which will always be the case for live data.
	Schema_Mixed Schema = 0xFFFF
	/// Market by order.
	Schema_Mbo Schema = 0
	/// Market by price with a book depth of 1.
	Schema_Mbp1 Schema = 1
	/// Market by price with a book depth of 10.
	Schema_Mbp10 Schema = 2
	/// All trade events with the best bid and offer (BBO) immediately **before** the effect of the trade.
	Schema_Tbbo Schema = 3
	/// All trade events.
	Schema_Trades Schema = 4
	/// Open, high, low, close, and volume at a one-second interval.
	Schema_Ohlcv1S Schema = 5
	/// Open, high, low, close, and volume at a one-minute interval.
	Schema_Ohlcv1M Schema = 6
	/// Open, high, low, close, and volume at an hourly interval.
	Schema_Ohlcv1H Schema = 7
	/// Open, high, low, close, and volume at a daily interval based on the UTC date.
	Schema_Ohlcv1D Schema = 8
	/// Instrument definitions.
	Schema_Definition Schema = 9
	/// Additional data disseminated by publishers.
	Schema_Statistics Schema = 10
	/// Trading status events.
	Schema_Status Schema = 11
	/// Auction imbalance events.
	Schema_Imbalance Schema = 12
	/// Open, high, low, close, and volume at a daily cadence based on the end of the trading session.
	Schema_OhlcvEod Schema = 13
	/// Consolidated best bid and offer.
	Schema_Cmbp1 Schema = 14
	/// Consolidated best bid and offer subsampled at one-second intervals, in addition to trades.
	Schema_Cbbo1S Schema = 15
	/// Consolidated best bid and offer subsampled at one-minute intervals, in addition to trades.
	Schema_Cbbo1M Schema = 16
	/// All trade events with the consolidated best bid and offer (CBBO) immediately **before** the effect of the trade.6
	Schema_Tcbbo Schema = 17
	/// Best bid and offer subsampled at one-second intervals, in addition to trades.
	Schema_Bbo1S Schema = 18
	/// Best bid and offer subsampled at one-minute intervals, in addition to trades.
	Schema_Bbo1M Schema = 19
)

func SchemaFromString added in v0.0.5

func SchemaFromString(str string) (Schema, error)

SchemaFromString converts a string to a Schema. Returns an error if the string is unknown.

func (Schema) MarshalJSON added in v0.0.13

func (s Schema) MarshalJSON() ([]byte, error)

func (Schema) String added in v0.0.5

func (s Schema) String() string

Returns the string representation of the Schema, or empty string if unknown.

func (*Schema) UnmarshalJSON added in v0.0.13

func (s *Schema) UnmarshalJSON(data []byte) error

type SecurityUpdateAction

type SecurityUpdateAction uint8

/ The type of [`InstrumentDefMsg`](crate::record::InstrumentDefMsg) update.

const (
	/// A new instrument definition.
	Add SecurityUpdateAction = 'A'
	/// A modified instrument definition of an existing one.
	Modify SecurityUpdateAction = 'M'
	/// Removal of an instrument definition.
	Delete SecurityUpdateAction = 'D'
	// Deprecated: Still present in legacy files."
	Invalid SecurityUpdateAction = '~'
)

type Side

type Side uint8

Side is a side of the market. The side of the market for resting orders, or the side of the aggressor for trades.

const (
	// A sell order or sell aggressor in a trade.
	Side_Ask Side = 'A'
	// A buy order or a buy aggressor in a trade.
	Side_Bid Side = 'B'
	// No side specified by the original source.
	Side_None Side = 'N'
)

type StatMsg added in v0.0.8

type StatMsg struct {
	Header       RHeader  `json:"hd" csv:"hd"`                       // The common header.
	TsRecv       uint64   `json:"ts_recv" csv:"ts_recv"`             // The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch.
	TsRef        uint64   `json:"ts_ref" csv:"ts_ref"`               // The reference timestamp of the statistic value expressed as the number of nanoseconds since the UNIX epoch. Will be [`crate::UNDEF_TIMESTAMP`] when unused.
	Price        int64    `json:"price" csv:"price"`                 // The value for price statistics expressed as a signed integer where every 1 unit corresponds to 1e-9, i.e. 1/1,000,000,000 or 0.000000001. Will be [`crate::UNDEF_PRICE`] when unused.
	Quantity     int32    `json:"quantity" csv:"quantity"`           // The value for non-price statistics. Will be [`crate::UNDEF_STAT_QUANTITY`] when unused.
	Sequence     uint32   `json:"sequence" csv:"sequence"`           // The message sequence number assigned at the venue.
	TsInDelta    int32    `json:"ts_in_delta" csv:"ts_in_delta"`     // The delta of `ts_recv - ts_exchange_send`, max 2 seconds.
	StatType     uint16   `json:"stat_type" csv:"stat_type"`         // The type of statistic value contained in the message. Refer to the [`StatType`](crate::enums::StatType) for variants.
	ChannelID    uint16   `json:"channel_id" csv:"channel_id"`       // The channel ID assigned by Databento as an incrementing integer starting at zero.
	UpdateAction uint8    `json:"update_action" csv:"update_action"` // Indicates if the statistic is newly added (1) or deleted (2). (Deleted is only used with some stat types)
	StatFlags    uint8    `json:"stat_flags" csv:"stat_flags"`       // Additional flags associate with certain stat types.
	Reserved     [6]uint8 // Filler for alignment
}

StatMsg is a statistics message. A catchall for various data disseminated by publishers. The [`stat_type`](Self::stat_type) indicates the statistic contained in the message.

func (*StatMsg) Fill_Json added in v0.0.8

func (r *StatMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*StatMsg) Fill_Raw added in v0.0.8

func (r *StatMsg) Fill_Raw(b []byte) error

func (*StatMsg) RSize added in v0.0.8

func (*StatMsg) RSize() uint16

func (*StatMsg) RType added in v0.0.8

func (*StatMsg) RType() RType

type StatType

type StatType uint8

/ The type of statistic contained in a [`StatMsg`](crate::record::StatMsg).

const (
	/// The price of the first trade of an instrument. `price` will be set.
	/// `quantity` will be set when provided by the venue.
	StatType_OpeningPrice StatType = 1
	/// The probable price of the first trade of an instrument published during pre-
	/// open. Both `price` and `quantity` will be set.
	StatType_IndicativeOpeningPrice StatType = 2
	/// The settlement price of an instrument. `price` will be set and `flags` indicate
	/// whether the price is final or preliminary and actual or theoretical. `ts_ref`
	/// will indicate the trading date of the settlement price.
	StatType_SettlementPrice StatType = 3
	/// The lowest trade price of an instrument during the trading session. `price` will
	/// be set.
	StatType_TradingSessionLowPrice StatType = 4
	/// The highest trade price of an instrument during the trading session. `price` will
	/// be set.
	StatType_TradingSessionHighPrice StatType = 5
	/// The number of contracts cleared for an instrument on the previous trading date.
	/// `quantity` will be set. `ts_ref` will indicate the trading date of the volume.
	StatType_ClearedVolume StatType = 6
	/// The lowest offer price for an instrument during the trading session. `price`
	/// will be set.
	StatType_LowestOffer StatType = 7
	/// The highest bid price for an instrument during the trading session. `price`
	/// will be set.
	StatType_HighestBid StatType = 8
	/// The current number of outstanding contracts of an instrument. `quantity` will
	/// be set. `ts_ref` will indicate the trading date for which the open interest was
	/// calculated.
	StatType_OpenInterest StatType = 9
	/// The volume-weighted average price (VWAP) for a fixing period. `price` will be
	/// set.
	StatType_FixingPrice StatType = 10
	/// The last trade price during a trading session. `price` will be set.
	/// `quantity` will be set when provided by the venue.
	StatType_ClosePrice StatType = 11
	/// The change in price from the close price of the previous trading session to the
	/// most recent trading session. `price` will be set.
	StatType_NetChange StatType = 12
	/// The volume-weighted average price (VWAP) during the trading session.
	/// `price` will be set to the VWAP while `quantity` will be the traded
	/// volume.
	StatType_Vwap StatType = 13
	// The implied volatility associated with the settlement price. `price` will
	// be set with the standard precision.
	StatType_Volatility StatType = 14
	// The option delta associated with the settlement price. `price` will be set
	// with the standard precision.
	StatType_Delta StatType = 15
	// The auction uncrossing price. This is used for auctions that are neither the official opening auction nor the official closing auction. `price` will be
	// `quantity` will be set when provided by the venue.
	StatType_UncrossingPrice StatType = 16
)

type StatUpdateAction

type StatUpdateAction uint8

/ The type of [`StatMsg`](crate::record::StatMsg) update.

const (
	/// A new statistic.
	StatUpdateAction_New StatUpdateAction = 1
	/// A removal of a statistic.
	StatUpdateAction_Delete StatUpdateAction = 2
)

type StatusAction

type StatusAction uint8

/ The primary enum for the type of [`StatusMsg`](crate::record::StatusMsg) update.

const (
	/// No change.
	StatusAction_None StatusAction = 0
	/// The instrument is in a pre-open period.
	StatusAction_PreOpen StatusAction = 1
	/// The instrument is in a pre-cross period.
	StatusAction_PreCross StatusAction = 2
	/// The instrument is quoting but not trading.
	StatusAction_Quoting StatusAction = 3
	/// The instrument is in a cross/auction.
	StatusAction_Cross StatusAction = 4
	/// The instrument is being opened through a trading rotation.
	StatusAction_Rotation StatusAction = 5
	/// A new price indication is available for the instrument.
	StatusAction_NewPriceIndication StatusAction = 6
	/// The instrument is trading.
	StatusAction_Trading StatusAction = 7
	/// Trading in the instrument has been halted.
	StatusAction_Halt StatusAction = 8
	/// Trading in the instrument has been paused.
	StatusAction_Pause StatusAction = 9
	/// Trading in the instrument has been suspended.
	StatusAction_Suspend StatusAction = 10
	/// The instrument is in a pre-close period.
	StatusAction_PreClose StatusAction = 11
	/// Trading in the instrument has closed.
	StatusAction_Close StatusAction = 12
	/// The instrument is in a post-close period.
	StatusAction_PostClose StatusAction = 13
	/// A change in short-selling restrictions.
	StatusAction_SsrChange StatusAction = 14
	/// The instrument is not available for trading, either trading has closed or been
	/// halted.
	StatusAction_NotAvailableForTrading StatusAction = 15
)
const (
	/// No reason is given.
	StatusReason_None StatusAction = 0
	/// The change in status occurred as scheduled.
	StatusReason_Scheduled StatusAction = 1
	/// The instrument stopped due to a market surveillance intervention.
	StatusReason_SurveillanceIntervention StatusAction = 2
	/// The status changed due to activity in the market.
	StatusReason_MarketEvent StatusAction = 3
	/// The derivative instrument began trading.
	StatusReason_InstrumentActivation StatusAction = 4
	/// The derivative instrument expired.
	StatusReason_InstrumentExpiration StatusAction = 5
	/// Recovery in progress.
	StatusReason_RecoveryInProcess StatusAction = 6
	/// The status change was caused by a regulatory action.
	StatusReason_Regulatory StatusAction = 10
	/// The status change was caused by an administrative action.
	StatusReason_Administrative StatusAction = 11
	/// The status change was caused by the issuer not being compliance with regulatory
	/// requirements.
	StatusReason_NonCompliance StatusAction = 12
	/// Trading halted because the issuer's filings are not current.
	StatusReason_FilingsNotCurrent StatusAction = 13
	/// Trading halted due to an SEC trading suspension.
	StatusReason_SecTradingSuspension StatusAction = 14
	/// The status changed because a new issue is available.
	StatusReason_NewIssue StatusAction = 15
	/// The status changed because an issue is available.
	StatusReason_IssueAvailable StatusAction = 16
	/// The status changed because the issue was reviewed.
	StatusReason_IssuesReviewed StatusAction = 17
	/// The status changed because the filing requirements were satisfied.
	StatusReason_FilingReqsSatisfied StatusAction = 18
	/// Relevant news is pending.
	StatusReason_NewsPending StatusAction = 30
	/// Relevant news was released.
	StatusReason_NewsReleased StatusAction = 31
	/// The news has been fully disseminated and times are available for the resumption
	/// in quoting and trading.
	StatusReason_NewsAndResumptionTimes StatusAction = 32
	/// The relevants news was not forthcoming.
	StatusReason_NewsNotForthcoming StatusAction = 33
	/// Halted for order imbalance.
	StatusReason_OrderImbalance StatusAction = 40
	/// The instrument hit limit up or limit down.
	StatusReason_LuldPause StatusAction = 50
	/// An operational issue occurred with the venue.
	StatusReason_Operational StatusAction = 60
	/// The status changed until the exchange receives additional information.
	StatusReason_AdditionalInformationRequested StatusAction = 70
	/// Trading halted due to merger becoming effective.
	StatusReason_MergerEffective StatusAction = 80
	/// Trading is halted in an ETF due to conditions with the component securities.
	StatusReason_Etf StatusAction = 90
	/// Trading is halted for a corporate action.
	StatusReason_CorporateAction StatusAction = 100
	/// Trading is halted because the instrument is a new offering.
	StatusReason_NewSecurityOffering StatusAction = 110
	/// Halted due to the market-wide circuit breaker level 1.
	StatusReason_MarketWideHaltLevel1 StatusAction = 120
	/// Halted due to the market-wide circuit breaker level 2.
	StatusReason_MarketWideHaltLevel2 StatusAction = 121
	/// Halted due to the market-wide circuit breaker level 3.
	StatusReason_MarketWideHaltLevel3 StatusAction = 122
	/// Halted due to the carryover of a market-wide circuit breaker from the previous
	/// trading day.
	StatusReason_MarketWideHaltCarryover StatusAction = 123
	/// Resumption due to the end of the a market-wide circuit breaker halt.
	StatusReason_MarketWideHaltResumption StatusAction = 124
	/// Halted because quotation is not available.
	StatusReason_QuotationNotAvailable StatusAction = 130
)

type StatusMsg added in v0.1.0

type StatusMsg struct {
	Header                RHeader  `json:"hd" csv:"hd"`                                             // The record header.
	TsRecv                uint64   `json:"ts_recv" csv:"ts_recv"`                                   // The capture-server-received timestamp expressed as number of nanoseconds since the UNIX epoch.
	Action                uint16   `json:"action" csv:"action"`                                     // The type of status change.
	Reason                uint16   `json:"reason" csv:"reason"`                                     // Additional details about the cause of the status change.
	TradingEvent          uint16   `json:"trading_event" csv:"trading_event"`                       // Further information about the status change and its effect on trading.
	IsTrading             uint8    `json:"is_trading" csv:"is_trading"`                             // The state of trading in the instrument.
	IsQuoting             uint8    `json:"is_quoting" csv:"is_quoting"`                             // The state of quoting in the instrument.
	IsShortSellRestricted uint8    `json:"is_short_sell_restricted" csv:"is_short_sell_restricted"` // The state of short sell restrictions for the instrument.
	Reserved              [7]uint8 // Filler for alignment.
}

Databento normalized Trading Status Update message.

func (*StatusMsg) Fill_Json added in v0.1.0

func (r *StatusMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*StatusMsg) Fill_Raw added in v0.1.0

func (r *StatusMsg) Fill_Raw(b []byte) error

func (*StatusMsg) RSize added in v0.1.0

func (*StatusMsg) RSize() uint16

func (*StatusMsg) RType added in v0.1.0

func (*StatusMsg) RType() RType

type StatusReason

type StatusReason uint8

/ The secondary enum for a [`StatusMsg`](crate::record::StatusMsg) update, explains / the cause of a halt or other change in `action`.

type SymbolMapping

type SymbolMapping struct {
	RawSymbol string            // The symbol assigned by publisher.
	Intervals []MappingInterval // The mappings of `native` for different date ranges.
}

A raw symbol and its symbol mappings for different time ranges within the query range.

type SymbolMappingMsg

type SymbolMappingMsg struct {
	Header         RHeader `json:"hd" csv:"hd"`                             // The common header.
	StypeIn        SType   `json:"stype_in" csv:"stype_in"`                 // The input symbology type of `stype_in_symbol`.
	StypeInSymbol  string  `json:"stype_in_symbol" csv:"stype_in_symbol"`   // The input symbol.
	StypeOut       SType   `json:"stype_out" csv:"stype_out"`               // The output symbology type of `stype_out_symbol`.
	StypeOutSymbol string  `json:"stype_out_symbol" csv:"stype_out_symbol"` // The output symbol.
	StartTs        uint64  `json:"start_ts" csv:"start_ts"`                 // The start of the mapping interval expressed as the number of nanoseconds since the UNIX epoch.
	EndTs          uint64  `json:"end_ts" csv:"end_ts"`                     // The end of the mapping interval expressed as the number of nanoseconds since the UNIX epoch.
}

Databento Symbol Mapping Message This is not a strict byte-layout because StypeInSymbol and StypeOutSymbol have dynamic lengths that depend on metadata's SymbolCstrLen.

func (*SymbolMappingMsg) Fill_Json

func (r *SymbolMappingMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*SymbolMappingMsg) Fill_Raw

func (r *SymbolMappingMsg) Fill_Raw(b []byte, cstrLength uint16) error

func (*SymbolMappingMsg) RSize

func (*SymbolMappingMsg) RSize(cstrLength uint16) uint16

func (*SymbolMappingMsg) RType

func (*SymbolMappingMsg) RType() RType

type SystemCode added in v0.7.0

type SystemCode uint8

A [`SystemMsg`](crate::SystemMsg) code indicating the type of message from the live subscription gateway.

func SystemCodeFromString added in v0.7.0

func SystemCodeFromString(str string) (SystemCode, error)

SystemCodeFromString converts a string to an SystemCode. Returns an error if the string is unknown.

func (SystemCode) MarshalJSON added in v0.7.0

func (s SystemCode) MarshalJSON() ([]byte, error)

func (SystemCode) String added in v0.7.0

func (s SystemCode) String() string

Returns the string representation of the SystemCode, or empty string if unknown.

func (*SystemCode) UnmarshalJSON added in v0.7.0

func (s *SystemCode) UnmarshalJSON(data []byte) error

type SystemMsg added in v0.0.8

type SystemMsg struct {
	Header  RHeader                 `json:"hd" csv:"hd"`     // The common header.
	Message [SystemMsg_MsgSize]byte `json:"msg" csv:"msg"`   // The message from the Databento Live Subscription Gateway (LSG).
	Code    SystemCode              `json:"code" csv:"code"` // The type of system message.
}

func (*SystemMsg) Fill_Json added in v0.0.8

func (r *SystemMsg) Fill_Json(val *fastjson.Value, header *RHeader) error

func (*SystemMsg) Fill_Raw added in v0.0.8

func (r *SystemMsg) Fill_Raw(b []byte) error

func (*SystemMsg) IsHeartbeat added in v0.7.0

func (r *SystemMsg) IsHeartbeat() bool

IsHeartbeat checks if the system message is a heartbeat. For fullest compatibility, it falls back to a string check

func (*SystemMsg) RSize added in v0.0.8

func (*SystemMsg) RSize() uint16

func (*SystemMsg) RType added in v0.0.8

func (*SystemMsg) RType() RType

type TradingEvent

type TradingEvent uint8

/ Further information about a status update.

const (
	/// No additional information given.
	TradingEvent_None TradingEvent = 0
	/// Order entry and modification are not allowed.
	TradingEvent_NoCancel TradingEvent = 1
	/// A change of trading session occurred. Daily statistics are reset.
	TradingEvent_ChangeTradingSession TradingEvent = 2
	/// Implied matching is available.
	TradingEvent_ImpliedMatchingOn TradingEvent = 3
	/// Implied matching is not available.
	TradingEvent_ImpliedMatchingOff TradingEvent = 4
)
const (
	/// The value is not applicable or not known.
	TriState_NotAvailable TradingEvent = '~'
	/// False
	TriState_No TradingEvent = 'N'
	/// True
	TriState_Yes TradingEvent = 'Y'
)

type TriState

type TriState uint8

/ An enum for representing unknown, true, or false values. Equivalent to / `Option<bool>` but with a human-readable repr.

type TsSymbolMap added in v0.0.8

type TsSymbolMap struct {
	// contains filtered or unexported fields
}

TsSymbolMap is a timeseries symbol map. Generally useful for working with historical data and is commonly built from a Metadata object.

func NewTsSymbolMap added in v0.0.8

func NewTsSymbolMap() *TsSymbolMap

func (*TsSymbolMap) FillFromMetadata added in v0.0.8

func (tsm *TsSymbolMap) FillFromMetadata(metadata *Metadata) error

FillFromMetadata fills the TsSymbolMap with mappings from `metadata`.

func (*TsSymbolMap) Get added in v0.0.8

func (tsm *TsSymbolMap) Get(dt time.Time, instrID uint32) string

Get returns the symbol mapping for the given date and instrument ID. Returns empty string if no mapping exists.

func (*TsSymbolMap) Insert added in v0.0.8

func (tsm *TsSymbolMap) Insert(instrID uint32, startDate uint32, endDate uint32, ticker string) error

Insert adds mappings for a date range. dates are YYYYMMDD ints

func (*TsSymbolMap) IsEmpty added in v0.0.8

func (tsm *TsSymbolMap) IsEmpty() bool

IsEmpty returns true if there are no mappings.

func (*TsSymbolMap) Len added in v0.0.8

func (tsm *TsSymbolMap) Len() int

Len returns the number of symbol mappings in the map.

type UserDefinedInstrument

type UserDefinedInstrument uint8

UserDefinedInstrument

const (
	/// The instrument is not user-defined.
	UserDefinedInstrument_No UserDefinedInstrument = 'N'
	/// The instrument is user-defined.
	UserDefinedInstrument_Yes UserDefinedInstrument = 'Y'
)

type Venue added in v0.7.0

type Venue uint16

Venue is a trading execution venue.

const (
	// CME Globex
	Venue_Glbx Venue = 1
	// Nasdaq - All Markets
	Venue_Xnas Venue = 2
	// Nasdaq OMX BX
	Venue_Xbos Venue = 3
	// Nasdaq OMX PSX
	Venue_Xpsx Venue = 4
	// Cboe BZX U.S. Equities Exchange
	Venue_Bats Venue = 5
	// Cboe BYX U.S. Equities Exchange
	Venue_Baty Venue = 6
	// Cboe EDGA U.S. Equities Exchange
	Venue_Edga Venue = 7
	// Cboe EDGX U.S. Equities Exchange
	Venue_Edgx Venue = 8
	// New York Stock Exchange, Inc.
	Venue_Xnys Venue = 9
	// NYSE National, Inc.
	Venue_Xcis Venue = 10
	// NYSE MKT LLC
	Venue_Xase Venue = 11
	// NYSE Arca
	Venue_Arcx Venue = 12
	// NYSE Texas, Inc.
	Venue_Xchi Venue = 13
	// Investors Exchange
	Venue_Iexg Venue = 14
	// FINRA/Nasdaq TRF Carteret
	Venue_Finn Venue = 15
	// FINRA/Nasdaq TRF Chicago
	Venue_Finc Venue = 16
	// FINRA/NYSE TRF
	Venue_Finy Venue = 17
	// MEMX LLC Equities
	Venue_Memx Venue = 18
	// MIAX Pearl Equities
	Venue_Eprl Venue = 19
	// NYSE American Options
	Venue_Amxo Venue = 20
	// BOX Options
	Venue_Xbox Venue = 21
	// Cboe Options
	Venue_Xcbo Venue = 22
	// MIAX Emerald
	Venue_Emld Venue = 23
	// Cboe EDGX Options
	Venue_Edgo Venue = 24
	// Nasdaq GEMX
	Venue_Gmni Venue = 25
	// Nasdaq ISE
	Venue_Xisx Venue = 26
	// Nasdaq MRX
	Venue_Mcry Venue = 27
	// MIAX Options
	Venue_Xmio Venue = 28
	// NYSE Arca Options
	Venue_Arco Venue = 29
	// Options Price Reporting Authority
	Venue_Opra Venue = 30
	// MIAX Pearl
	Venue_Mprl Venue = 31
	// Nasdaq Options
	Venue_Xndq Venue = 32
	// Nasdaq BX Options
	Venue_Xbxo Venue = 33
	// Cboe C2 Options
	Venue_C2Ox Venue = 34
	// Nasdaq PHLX
	Venue_Xphl Venue = 35
	// Cboe BZX Options
	Venue_Bato Venue = 36
	// MEMX Options
	Venue_Mxop Venue = 37
	// ICE Europe Commodities
	Venue_Ifeu Venue = 38
	// ICE Endex
	Venue_Ndex Venue = 39
	// Databento US Equities - Consolidated
	Venue_Dbeq Venue = 40
	// MIAX Sapphire
	Venue_Sphr Venue = 41
	// Long-Term Stock Exchange, Inc.
	Venue_Ltse Venue = 42
	// Off-Exchange Transactions - Listed Instruments
	Venue_Xoff Venue = 43
	// IntelligentCross ASPEN Intelligent Bid/Offer
	Venue_Aspn Venue = 44
	// IntelligentCross ASPEN Maker/Taker
	Venue_Asmt Venue = 45
	// IntelligentCross ASPEN Inverted
	Venue_Aspi Venue = 46
	// Databento US Equities - Consolidated
	Venue_Equs Venue = 47
	// ICE Futures US
	Venue_Ifus Venue = 48
	// ICE Europe Financials
	Venue_Ifll Venue = 49
	// Eurex Exchange
	Venue_Xeur Venue = 50
	// European Energy Exchange
	Venue_Xeee Venue = 51
	// Cboe Futures Exchange
	Venue_Xcbf Venue = 52
	// Blue Ocean ATS
	Venue_Ocea Venue = 53
)

func VenueFromString added in v0.7.0

func VenueFromString(str string) (Venue, error)

VenueFromString converts a string to a Venue. Returns an error if the string is unknown.

func (Venue) MarshalJSON added in v0.7.0

func (v Venue) MarshalJSON() ([]byte, error)

func (*Venue) Set added in v0.7.0

func (v *Venue) Set(value string) error

Set implements the flag.Value interface.

func (Venue) String added in v0.7.0

func (v Venue) String() string

Returns the string representation of the Venue, or empty string if unknown.

func (*Venue) Type added in v0.7.0

func (*Venue) Type() string

Type implements pflag.Value.Type. Returns "dbn.Venue".

func (*Venue) UnmarshalJSON added in v0.7.0

func (v *Venue) UnmarshalJSON(data []byte) error

type VersionUpgradePolicy

type VersionUpgradePolicy uint8

How to handle decoding DBN data from a prior version.

const (
	/// Decode data from previous versions as-is.
	VersionUpgradePolicy_AsIs VersionUpgradePolicy = 0
	/// Decode data from previous versions converting it to the latest version. This
	/// breaks zero-copy decoding for structs that need updating, but makes usage
	/// simpler.
	VersionUpgradePolicy_Upgrade VersionUpgradePolicy = 1
)

type Visitor

type Visitor interface {
	OnMbp0(record *Mbp0Msg) error
	OnMbp1(record *Mbp1Msg) error
	OnMbp10(record *Mbp10Msg) error
	OnMbo(record *MboMsg) error

	OnOhlcv(record *OhlcvMsg) error
	OnCmbp1(record *Cmbp1Msg) error
	OnBbo(record *BboMsg) error

	OnImbalance(record *ImbalanceMsg) error
	OnStatMsg(record *StatMsg) error
	OnStatusMsg(record *StatusMsg) error
	OnInstrumentDefMsg(record *InstrumentDefMsg) error

	OnErrorMsg(record *ErrorMsg) error
	OnSystemMsg(record *SystemMsg) error
	OnSymbolMappingMsg(record *SymbolMappingMsg) error

	OnStreamEnd() error
}

Directories

Path Synopsis
cmd
dbn-go-file command
dbn-go-hist command
dbn-go-live command
dbn-go-mcp-data command
dbn-go-mcp-meta command
dbn-go-tui command
internal
tui
tests
stype_matrix command
Probes the Databento symbology.resolve API to determine which stype_in and stype_out values are supported for each dataset.
Probes the Databento symbology.resolve API to determine which stype_in and stype_out values are supported for each dataset.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL