MCPcopy Index your code
hub / github.com/databento/databento-rs

github.com/databento/databento-rs @v0.53.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.53.0 ↗ · + Follow
381 symbols 1,092 edges 22 files 87 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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. The library is built on top of the tokio asynchronous runtime and Databento's efficient binary encoding.

You can find getting started tutorials, full API method documentation, examples with output on the Databento docs site.

Installation

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

cargo add databento

Feature flags

  • historical: enables the historical client for data older than 24 hours
  • live: enables the live client for real-time and intraday historical data
  • chrono: enables passing chrono types as datetime parameters

By default, both the live and historical features are enabled and the historical client uses rustls for TLS. To use a different TLS implementation, disable default features for both the databento crate and reqwest.

databento = { features = ["historical"], default-features = false }
reqwest = { features = ["native-tls"], default-features = false }

Usage

Historical

Here is a simple program that fetches 10 minutes worth of historical trades for E-mini S&P 500 futures from CME Globex: ```rust no_run use std::error::Error;

use databento::{ dbn::{decode::DbnMetadata, Dataset, SType, Schema, TradeMsg}, historical::timeseries::GetRangeParams, HistoricalClient, }; use time::macros::{date, datetime};

[tokio::main]

async fn main() -> Result<(), Box> { let mut client = HistoricalClient::builder().key_from_env()?.build()?; let mut decoder = client .timeseries() .get_range( &GetRangeParams::builder() .dataset(Dataset::GlbxMdp3) .date_time_range(datetime!(2022-06-10 14:30 UTC)..datetime!(2022-06-10 14:40 UTC)) .symbols("ES.FUT") .stype_in(SType::Parent) .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::().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 historical`.

### Live

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

```rust no_run
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 live

License

Distributed under the Apache 2.0 License.

Extension points exported contracts — how you extend this code

DateTimeLike (Interface)
A datetime or object that can be non-fallibly converted to a datetime. [4 implementers]
src/lib.rs
AddToForm (Interface)
(no doc) [12 implementers]
src/historical.rs
RawApiMsg (Interface)
A raw API message to be sent to the live gateway. [3 implementers]
src/live/protocol.rs
AddToQuery (Interface)
(no doc) [3 implementers]
src/historical.rs

Core symbols most depended-on inside this repo

start
called by 48
src/live/client.rs
body_contains
called by 43
src/lib.rs
build
called by 36
src/historical/client.rs
send
called by 35
src/live/client.rs
build
called by 21
src/live.rs
dataset
called by 19
src/live/client.rs
add_to_form
called by 16
src/reference/corporate.rs
handle_response
called by 15
src/historical/client.rs

Shape

Method 181
Function 101
Class 64
Enum 31
Interface 4

Languages

Rust100%

Modules by API surface

src/live/client.rs66 symbols
src/historical/metadata.rs35 symbols
src/historical/client.rs35 symbols
src/historical/batch.rs33 symbols
src/historical.rs32 symbols
src/live.rs26 symbols
src/reference/enums.rs24 symbols
src/live/protocol.rs23 symbols
src/reference.rs22 symbols
src/lib.rs19 symbols
src/historical/timeseries.rs13 symbols
src/reference/security.rs10 symbols

For agents

$ claude mcp add databento-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page