AsyncDbnStore::decode_record

Decode a single record of a specific type. If the record type is unknown, such as when working with Live data where the stream can contain several different record types, use decode_record_ref.

Parameters

Parameter
Type
Description
T
HasRType
A DBN record type.

Returns

A reference to the decoded record of type T or Ok(None) if the stream has been exhausted.

This function will return an error if the record is not of type T or there's an error reading from the input stream.

API method
pub async fn decode_record<T: HasRType>(
    &mut self,
) -> dbn::Result<Option<&T>>;
Example usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use databento::{
    HistoricalClient,
    dbn::{Dataset, OhlcvMsg, Schema},
    historical::timeseries::GetRangeParams,
};
use time::macros::datetime;

let mut client =
    HistoricalClient::builder().key("$YOUR_API_KEY")?.build()?;
let mut decoder = client
    .timeseries()
    .get_range(
        &GetRangeParams::builder()
            .dataset(Dataset::XnasItch)
            .date_time_range(
                datetime!(2023-08-07 00:00 UTC)
                    ..datetime!(2023-08-08 00:00 UTC),
            )
            .symbols("AAPL")
            .schema(Schema::Ohlcv1M)
            .build(),
    )
    .await?;
let bar = decoder.decode_record::<OhlcvMsg>().await?.unwrap();
println!("{bar:#?}");
Example response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
OhlcvMsg {
    hd: RecordHeader {
        length: 14,
        rtype: Ohlcv1M,
        publisher_id: XnasItchXnas,
        instrument_id: 32,
        ts_event: 1691395200000000000,
    },
    open: 183.440000000,
    high: 183.460000000,
    low: 182.750000000,
    close: 183.300000000,
    volume: 2030,
}