Table of Contents

Struct StatMsg

Namespace
DatabentoDotNet.Dbn
Assembly
DatabentoDotNet.Dbn.dll

A statistic disseminated by a publisher. The record of the Statistics schema; StatType says which statistic it carries.

public readonly struct StatMsg : IRecord<StatMsg>
Implements
Inherited Members

Examples

if (record.TryGet(out StatMsg stat))
{
    // Which statistic this is decides which field carries its value: a settlement is a price, an
    // open interest is a quantity, and reading the wrong one gives a number rather than an error.
    string value = stat.StatType switch
    {
        StatType.OpeningPrice or StatType.SettlementPrice or StatType.ClosePrice =>
            ((decimal)stat.Price / DbnConstants.FixedPriceScale).ToString(),
        _ => stat.Quantity.ToString(),
    };

    Console.WriteLine($"{DbnTime.ToInstant(stat.IndexTs)} {stat.StatType} {value}");

    // TsRef is the moment the statistic refers to rather than the moment it arrived, and it is
    // absent for most statistic types.
    if (DbnTime.TryToInstant(stat.TsRef, out Instant referenced))
    {
        Console.WriteLine($"refers to {referenced}");
    }
}

Remarks

This is the DBN v3 layout, 80 bytes. Versions 1 and 2 share a different, 64-byte layout — see StatMsgV1. Field order is transcribed from the #[repr(C)] Rust declaration, not from its encode_order attributes.

Fields

ChannelId

The channel ID assigned by Databento, an integer counting up from zero.

public readonly ushort ChannelId

Field Value

ushort

Header

The common header.

public readonly RecordHeader Header

Field Value

RecordHeader

Price

The value for price statistics, where every 1 unit corresponds to 1e-9. UndefPrice when unused.

public readonly long Price

Field Value

long

Quantity

The value for non-price statistics. UndefStatQuantity when unused.

public readonly long Quantity

Field Value

long

Remarks

64-bit as of DBN v3; it is 32-bit in StatMsgV1, and so is its sentinel.

RawStatType

The raw wire value behind StatType. Not validated on decode — pass it to TryFromStatType(ushort, out StatType) for a checked conversion.

public readonly ushort RawStatType

Field Value

ushort

RawUpdateAction

The raw wire byte behind UpdateAction. Not validated on decode — pass it to TryFromStatUpdateAction(byte, out StatUpdateAction) for a checked conversion.

public readonly byte RawUpdateAction

Field Value

byte

Sequence

The message sequence number assigned at the venue.

public readonly uint Sequence

Field Value

uint

StatFlags

Additional flags associated with certain statistic types.

public readonly byte StatFlags

Field Value

byte

TsInDelta

The matching-engine-sending timestamp, in nanoseconds before TsRecv.

public readonly int TsInDelta

Field Value

int

TsRecv

The capture-server-received timestamp, in nanoseconds since the UNIX epoch. This, not TsEvent, is the record's index timestamp.

public readonly ulong TsRecv

Field Value

ulong

TsRef

The reference timestamp of the statistic value, in nanoseconds since the UNIX epoch. UndefTimestamp when unused.

public readonly ulong TsRef

Field Value

ulong

Properties

IndexTs

The record's index timestamp: the one to sort by, and the one to key a symbol map with. Nanoseconds since the UNIX epoch.

public ulong IndexTs { get; }

Property Value

ulong

Remarks

This is usually ts_recv, not TsEvent. Fourteen of the twenty-one record structs carry a ts_recv and index on it; the rest have no ts_recv at all and fall back to the header's ts_event. Port of upstream's Record::raw_index_ts (record/traits.rs:52-54), whose default body is ts_event and which the #[dbn(index_ts)] field attribute overrides per struct (record.rs, compat.rs).

The distinction is not cosmetic: ts_event and ts_recv can fall on opposite sides of UTC midnight, so resolving a symbol by the wrong one silently returns the previous day's symbol, or nothing, with no error anywhere.

This is a raw timestamp and can be UndefTimestamp. Convert it with ToUtcDate(ulong) or TryToUtcDate(ulong, out LocalDate), which check the sentinel.

StatType

The statistic this record carries. Undefined wire values cast through to an unnamed value rather than throwing; see RawStatType.

public StatType StatType { get; }

Property Value

StatType

UpdateAction

Whether the statistic is newly added or deleted. Undefined wire bytes cast through to an unnamed value rather than throwing; see RawUpdateAction.

public StatUpdateAction UpdateAction { get; }

Property Value

StatUpdateAction

WireSize

The struct's exact size on the wire, in bytes, excluding any trailing ts_out.

public static int WireSize { get; }

Property Value

int

Methods

HasRType(RType)

Reports whether StatMsg is the layout for records carrying rtype.

public static bool HasRType(RType rtype)

Parameters

rtype RType

The record type read from a record header.

Returns

bool

true if rtype is one of the record types this struct decodes. This is necessary but not sufficient to identify the record — see the remarks on IRecord<TSelf>.