Skip to content

Commit

Permalink
SR/updated time handling (#42)
Browse files Browse the repository at this point in the history
* fix: Use Eastern dates in pagination

* feat: More endpoints and examples

* doc: add more examples
  • Loading branch information
SebRollen authored Dec 27, 2021
1 parent b548387 commit 080b989
Show file tree
Hide file tree
Showing 17 changed files with 569 additions and 188 deletions.
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
chrono-tz = { version = "0.6.0", features = ["serde"] }
futures = { version = "0.3"}
itertools = "0.10"
rust_decimal = { version = "1.11", features = ["serde-float"] }
Expand All @@ -18,7 +19,8 @@ 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 = "2.0", optional = true }
vila = { version = "2.1", optional = true, features = ["progress"] }
uuid = { version = "0.8.2", features = ["serde"] }

[dev-dependencies]
anyhow = "1.0.45"
Expand All @@ -42,3 +44,11 @@ required-features = ["rest"]
[[example]]
name = "quotes"
required-features = ["rest"]

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

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

Expand All @@ -9,20 +9,29 @@ async fn main() {
env_logger::init();
let key = env::var("POLYGON_TOKEN").unwrap();
let client = client(&key);
let req = GetAggregate::new(
let req1 = 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)),
NaiveDate::from_ymd(2011, 11, 5).and_hms(0, 0, 0),
NaiveDate::from_ymd(2021, 11, 5).and_hms(0, 0, 0),
)
.multiplier(1)
.timespan(Timespan::Minute)
.limit(50000);
log::debug!("{:?}", req);
.limit(1);
let req2 = GetAggregate::new(
"AAPL",
NaiveDate::from_ymd(2011, 11, 5).and_hms(0, 0, 0),
NaiveDate::from_ymd(2021, 11, 5).and_hms(0, 0, 0),
)
.limit(1);
let reqs = [req1, req2];

client
.send_paginated(&req)
.map_ok(|x| x.results)
.try_flatten_iters()
.for_each(|x| async move { println!("{:?}", x.unwrap()) })
.await;
futures::stream::select_all(client.send_all_paginated(&reqs).map(|stream| {
stream
.map_ok(|x| {
let ticker = x.ticker.clone();
x.results.into_iter().map(move |r| (ticker.clone(), r))
})
.try_flatten_iters()
.take(10)
}))
.for_each_concurrent(None, |x| async move { println!("{:?}", x) })
.await;
}
1 change: 1 addition & 0 deletions examples/quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn main() {
.send_paginated(&req)
.map_ok(|x| x.results)
.try_flatten_iters()
.take(10)
.for_each(|x| async move { println!("{:?}", x) })
.await;
}
14 changes: 14 additions & 0 deletions examples/stock_dividends.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use polygon::rest::{client, GetStockDividends};
use std::env;

#[tokio::main]
async fn main() {
env_logger::init();
let key = env::var("POLYGON_TOKEN").unwrap();
let client = client(&key);
let req = GetStockDividends {
stocks_ticker: "AAPL".to_string(),
};

println!("{:#?}", client.send(&req).await);
}
14 changes: 14 additions & 0 deletions examples/stock_splits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use polygon::rest::{client, GetStockSplits};
use std::env;

#[tokio::main]
async fn main() {
env_logger::init();
let key = env::var("POLYGON_TOKEN").unwrap();
let client = client(&key);
let req = GetStockSplits {
stocks_ticker: "AAPL".to_string(),
};

println!("{:#?}", client.send(&req).await);
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate chrono;
extern crate chrono_tz;
pub mod errors;
#[cfg(feature = "rest")]
pub mod rest;
Expand Down
Loading

0 comments on commit 080b989

Please sign in to comment.