Skip to content

Commit

Permalink
feature: Use vila as the request library to improve pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRollen committed Nov 15, 2021
1 parent 3c04101 commit 252dcd0
Show file tree
Hide file tree
Showing 7 changed files with 712 additions and 38 deletions.
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ thiserror = "1.0"
tokio-tungstenite = { version = "0.15", features = ["stream", "rustls-tls"], optional = true }
tokio = { version = "1.0", default-features = false, features = ["net"], optional = true}
tracing = "0.1"
vila = { version = "1.0", optional = true }
vila = { version = "2.0", optional = true }

[dev-dependencies]
anyhow = "1.0.45"
env_logger = "0.9.0"
futures-channel = "0.3"
log = "0.4.14"
mockito = "0.30"
rust_decimal_macros = "1.11"
stream-flatten-iters = "0.2.0"
tokio = { version = "1.0", default-features = false, features = ["macros", "rt-multi-thread"] }

[features]
default = ["rest", "ws"]
rest = ["vila"]
ws = ["tokio-tungstenite", "tokio/net"]

[[example]]
name = "aggregates"
required-features = ["rest"]

[[example]]
name = "quotes"
required-features = ["rest"]
28 changes: 28 additions & 0 deletions examples/aggregates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use chrono::{NaiveDate, TimeZone, Utc};
use futures::{StreamExt, TryStreamExt};
use polygon::rest::{client, GetAggregate, Timespan};
use std::env;
use stream_flatten_iters::TryStreamExt as _;

#[tokio::main]
async fn main() {
env_logger::init();
let key = env::var("POLYGON_TOKEN").unwrap();
let client = client(&key);
let req = GetAggregate::new(
"GE",
Utc.from_utc_datetime(&NaiveDate::from_ymd(2011, 11, 5).and_hms(0, 0, 0)),
Utc.from_utc_datetime(&NaiveDate::from_ymd(2021, 11, 5).and_hms(0, 0, 0)),
)
.multiplier(1)
.timespan(Timespan::Minute)
.limit(50000);
log::debug!("{:?}", req);

client
.send_paginated(&req)
.map_ok(|x| x.results)
.try_flatten_iters()
.for_each(|x| async move { println!("{:?}", x.unwrap()) })
.await;
}
19 changes: 19 additions & 0 deletions examples/quotes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use chrono::NaiveDate;
use futures::{StreamExt, TryStreamExt};
use polygon::rest::{client, GetQuotes};
use std::env;
use stream_flatten_iters::TryStreamExt as _;

#[tokio::main]
async fn main() {
let key = env::var("POLYGON_TOKEN").unwrap();
let client = client(&key);
let req = GetQuotes::new("GE", NaiveDate::from_ymd(2021, 11, 5)).limit(50000);

client
.send_paginated(&req)
.map_ok(|x| x.results)
.try_flatten_iters()
.for_each(|x| async move { println!("{:?}", x) })
.await;
}
Loading

0 comments on commit 252dcd0

Please sign in to comment.