Skip to content

Commit

Permalink
Merge pull request #39 from Overmuse/SR/use_vila
Browse files Browse the repository at this point in the history
SR/use vila
  • Loading branch information
SebRollen authored Nov 15, 2021
2 parents 7d79e98 + 252dcd0 commit 9616460
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 58 deletions.
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition = "2018"
chrono = { version = "0.4", features = ["serde"] }
futures = { version = "0.3"}
itertools = "0.10"
rest-client = {git = "ssh://[email protected]/Overmuse/rest-client.git", tag = "v0.1.2", optional = true}
rust_decimal = { version = "1.11", features = ["serde-float"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -19,14 +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 = "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 = ["rest-client"]
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;
}
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Error {

#[cfg(feature = "rest")]
#[error(transparent)]
Rest(rest_client::Error),
Vila(vila::Error),

#[cfg(feature = "ws")]
#[error("Tungstenite error: {0}")]
Expand Down
Loading

0 comments on commit 9616460

Please sign in to comment.