databento_sandbox/sandbox.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::env;
17
18use databento::{
19 LiveClient,
20 dbn::{Dataset::GlbxMdp3, MboMsg, SType, Schema, TradeMsg},
21 live::Subscription,
22};
23use nautilus_core::consts::NAUTILUS_USER_AGENT;
24use time::OffsetDateTime;
25
26#[tokio::main]
27async fn main() {
28 let mut client = LiveClient::builder()
29 .user_agent_extension(NAUTILUS_USER_AGENT.into())
30 .key(env::var("DATABENTO_API_KEY").unwrap())
31 .unwrap()
32 .dataset(GlbxMdp3)
33 .build()
34 .await
35 .unwrap();
36
37 client
38 .subscribe(
39 Subscription::builder()
40 .schema(Schema::Mbo)
41 .stype_in(SType::RawSymbol)
42 .symbols("ESM4")
43 .start(OffsetDateTime::from_unix_timestamp_nanos(0).unwrap())
44 .build(),
45 )
46 .await
47 .unwrap();
48
49 client.start().await.unwrap();
50
51 let mut count = 0;
52
53 while let Some(record) = client.next_record().await.unwrap() {
54 if let Some(msg) = record.get::<TradeMsg>() {
55 println!("{msg:#?}");
56 }
57 if let Some(msg) = record.get::<MboMsg>() {
58 println!(
59 "Received delta: {} {} flags={}",
60 count,
61 msg.hd.ts_event,
62 msg.flags.raw(),
63 );
64 count += 1;
65 }
66 }
67}