26 releases (14 breaking)

0.15.0 Oct 22, 2024
0.13.0 Sep 25, 2024
0.12.0 Jul 30, 2024
0.7.1 Mar 5, 2024
0.5.0 Nov 23, 2023

#4 in Finance

Download history 2394/week @ 2024-07-18 2029/week @ 2024-07-25 2116/week @ 2024-08-01 2029/week @ 2024-08-08 1675/week @ 2024-08-15 2020/week @ 2024-08-22 1631/week @ 2024-08-29 2379/week @ 2024-09-05 1825/week @ 2024-09-12 1849/week @ 2024-09-19 3938/week @ 2024-09-26 2499/week @ 2024-10-03 1964/week @ 2024-10-10 2655/week @ 2024-10-17 2329/week @ 2024-10-24 1721/week @ 2024-10-31

9,161 downloads per month

Apache-2.0

160KB
3.5K 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
    while let Some(rec) = client.next_record().await? {
        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 and run cargo run --example historical

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 and run cargo bin --example live.

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–22MB
~292K SLoC