databento_sandbox/
sandbox.rs1use std::env;
2
3use databento::{
4 LiveClient,
5 dbn::{Dataset::GlbxMdp3, MboMsg, SType, Schema, TradeMsg},
6 live::Subscription,
7};
8use time::OffsetDateTime;
9
10#[tokio::main]
11async fn main() {
12 let mut client = LiveClient::builder()
13 .key(env::var("DATABENTO_API_KEY").unwrap())
14 .unwrap()
15 .dataset(GlbxMdp3)
16 .build()
17 .await
18 .unwrap();
19
20 client
21 .subscribe(
22 Subscription::builder()
23 .schema(Schema::Mbo)
24 .stype_in(SType::RawSymbol)
25 .symbols("ESM4")
26 .start(OffsetDateTime::from_unix_timestamp_nanos(0).unwrap())
27 .build(),
28 )
29 .await
30 .unwrap();
31
32 client.start().await.unwrap();
33
34 let mut count = 0;
35
36 while let Some(record) = client.next_record().await.unwrap() {
37 if let Some(msg) = record.get::<TradeMsg>() {
38 println!("{msg:#?}");
39 }
40 if let Some(msg) = record.get::<MboMsg>() {
41 println!(
42 "Received delta: {} {} flags={}",
43 count,
44 msg.hd.ts_event,
45 msg.flags.raw(),
46 );
47 count += 1;
48 }
49 }
50}