Skip to main content

Module live

Module live 

Source
Expand description

Live streaming connector for Databento.

Provides real-time market data streaming via DatabentoLive.

§Architecture

  • One connection per dataset: Each DatabentoLive connects to one dataset (e.g., GLBX.MDP3). For multiple datasets, create multiple instances.
  • Multiple symbols per connection: Databento recommends consolidating subscriptions within a dataset. Subscribe to multiple symbols before calling start().
  • Symbol resolution: DBN records contain numeric instrument_id. We use PitSymbolMap to resolve these to symbol strings, then map to user-provided instrument keys.

§Example

ⓘ
use rustrade_data::exchange::databento::DatabentoLive;
use rustrade_instrument::exchange::ExchangeId;
use databento::dbn::Schema;
use std::collections::HashMap;
use futures::StreamExt;

// Map symbols to your instrument keys
let instruments: HashMap<String, String> = [
    ("ESM5".to_string(), "ES-front".to_string()),
    ("NQM5".to_string(), "NQ-front".to_string()),
].into_iter().collect();

let mut client = DatabentoLive::from_env(
    "GLBX.MDP3",
    ExchangeId::DatabentoGlbx,
    instruments,
).await?;

// Subscribe to symbols (can call multiple times)
client.subscribe(&["ESM5", "NQM5"], Schema::Trades).await?;

// Start streaming (consumes client)
let mut stream = client.start().await?;

while let Some(event) = stream.next().await {
    match event {
        Ok(market_event) => println!("{:?}", market_event),
        Err(e) => eprintln!("Error: {}", e),
    }
}

Structs§

DatabentoLive
Live streaming client for Databento.