Skip to content

Commit

Permalink
DOC: Update Rust client README
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Oct 24, 2023
1 parent 057bb56 commit b436692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Here is a simple program that fetches the next ES mini futures trade:
use std::error::Error;

use databento::{
dbn::{Dataset, SType, Schema, TradeMsg},
live::{Subscription, SymbolMap},
dbn::{Dataset, PitSymbolMap, SType, Schema, TradeMsg},
live::Subscription,
LiveClient,
};

Expand All @@ -51,13 +51,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
client.start().await?;

let mut symbol_map = SymbolMap::new();
let mut symbol_map = PitSymbolMap::new();
// Get the next trade
loop {
let rec = client.next_record().await?.unwrap();
if let Some(trade) = rec.get::<TradeMsg>() {
let symbol = &symbol_map[trade.hd.instrument_id];
println!("Received trade for {symbol}: {trade:?}",);
let symbol = &symbol_map[trade];
println!("Received trade for {symbol}: {trade:?}");
break;
}
symbol_map.on_record(rec)?;
Expand All @@ -78,7 +78,7 @@ use databento::{
historical::timeseries::GetRangeParams,
HistoricalClient, Symbols,
};
use time::macros::datetime;
use time::macros::{date, datetime};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -97,8 +97,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
.build(),
)
.await?;
let symbol_map = decoder
.metadata()
.symbol_map_for_date(date!(2022 - 06 - 10))?;
while let Some(trade) = decoder.decode_record::<TradeMsg>().await? {
println!("{trade:?}");
let symbol = &symbol_map[trade];
println!("Received trade for {symbol}: {trade:?}");
}
Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions tests/historical-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use databento::{
historical::timeseries::GetRangeParams,
HistoricalClient, Symbols,
};
use time::macros::datetime;
use time::macros::{date, datetime};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -25,8 +25,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
.build(),
)
.await?;
let symbol_map = decoder
.metadata()
.symbol_map_for_date(date!(2022 - 06 - 10))?;
while let Some(trade) = decoder.decode_record::<TradeMsg>().await? {
println!("{trade:?}");
let symbol = &symbol_map[trade];
println!("Received trade for {symbol}: {trade:?}");
}
Ok(())
}
10 changes: 5 additions & 5 deletions tests/live-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::error::Error;

use databento::{
dbn::{Dataset, SType, Schema, TradeMsg},
live::{Subscription, SymbolMap},
dbn::{Dataset, PitSymbolMap, SType, Schema, TradeMsg},
live::Subscription,
LiveClient,
};

Expand All @@ -26,13 +26,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
client.start().await?;

let mut symbol_map = SymbolMap::new();
let mut symbol_map = PitSymbolMap::new();
// Get the next trade
loop {
let rec = client.next_record().await?.unwrap();
if let Some(trade) = rec.get::<TradeMsg>() {
let symbol = &symbol_map[trade.hd.instrument_id];
println!("Received trade for {symbol}: {trade:?}",);
let symbol = &symbol_map[trade];
println!("Received trade for {symbol}: {trade:?}");
break;
}
symbol_map.on_record(rec)?;
Expand Down

0 comments on commit b436692

Please sign in to comment.