9 releases (5 breaking)

0.6.0 Jan 16, 2024
0.5.0 Nov 23, 2023
0.4.2 Oct 23, 2023
0.4.0 Sep 21, 2023
0.1.0 Aug 3, 2023

#7 in Finance

Download history 2263/week @ 2023-11-02 1131/week @ 2023-11-09 1795/week @ 2023-11-16 1307/week @ 2023-11-23 2342/week @ 2023-11-30 1630/week @ 2023-12-07 1605/week @ 2023-12-14 960/week @ 2023-12-21 1159/week @ 2023-12-28 1852/week @ 2024-01-04 1764/week @ 2024-01-11 2235/week @ 2024-01-18 2534/week @ 2024-01-25 2336/week @ 2024-02-01 2063/week @ 2024-02-08 1425/week @ 2024-02-15

8,703 downloads per month

Apache-2.0

135KB
3K SLoC

databento-rs

build Documentation license Current Crates.io Version Slack

The official Rust client library for Databento. The clients support fast and safe streaming of both real-time and historical market data through similar interfaces.

Installation

To add the crate to an existing project, run the following command:

cargo add databento

Usage

Live

Real-time and intraday replay is provided through the Live clients. Here is a simple program that fetches the next ES mini futures trade:

use std::error::Error;

use databento::{
    dbn::{Dataset, PitSymbolMap, SType, Schema, TradeMsg},
    live::Subscription,
    LiveClient,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut client = LiveClient::builder()
        .key_from_env()?
        .dataset(Dataset::GlbxMdp3)
        .build()
        .await?;
    client
        .subscribe(
            &Subscription::builder()
                .symbols("ES.FUT")
                .schema(Schema::Trades)
                .stype_in(SType::Parent)
                .build(),
        )
        .await
        .unwrap();
    client.start().await?;

    let mut symbol_map = PitSymbolMap::new();
    // Get the next trade
    loop {
        let rec = client.next_record().await?.unwrap();
        if let Some(trade) = rec.get::<TradeMsg>() {
            let symbol = &symbol_map[trade];
            println!("Received trade for {symbol}: {trade:?}");
            break;
        }
        symbol_map.on_record(rec)?;
    }
    Ok(())
}

To run this program, set the DATABENTO_API_KEY environment variable with an API key.

Historical

Here is a simple program that fetches 10 minutes worth of historical trades for the entire CME Globex market:

use std::error::Error;

use databento::{
    dbn::{Schema, TradeMsg},
    historical::timeseries::GetRangeParams,
    HistoricalClient, Symbols,
};
use time::macros::{date, datetime};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut client = HistoricalClient::builder().key_from_env()?.build()?;
    let mut decoder = client
        .timeseries()
        .get_range(
            &GetRangeParams::builder()
                .dataset("GLBX.MDP3")
                .date_time_range((
                    datetime!(2022-06-10 14:30 UTC),
                    datetime!(2022-06-10 14:40 UTC),
                ))
                .symbols(Symbols::All)
                .schema(Schema::Trades)
                .build(),
        )
        .await?;
    let symbol_map = decoder
        .metadata()
        .symbol_map_for_date(date!(2022 - 06 - 10))?;
    while let Some(trade) = decoder.decode_record::<TradeMsg>().await? {
        let symbol = &symbol_map[trade];
        println!("Received trade for {symbol}: {trade:?}");
    }
    Ok(())
}

To run this program, set the DATABENTO_API_KEY environment variable with an API key.

Documentation

You can find more detailed examples and the full API documentation on the Databento docs site.

License

Distributed under the Apache 2.0 License.

Dependencies

~9–23MB
~319K SLoC