Add defaults for outgoing types
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, ALPACA_MODE},
|
config::{Config, ALPACA_MODE},
|
||||||
database,
|
database,
|
||||||
types::alpaca::{self, shared::Sort},
|
types::alpaca,
|
||||||
};
|
};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
@@ -50,13 +50,8 @@ pub async fn rehydrate_orders(config: &Arc<Config>) {
|
|||||||
&config.alpaca_rate_limiter,
|
&config.alpaca_rate_limiter,
|
||||||
&alpaca::api::outgoing::order::Order {
|
&alpaca::api::outgoing::order::Order {
|
||||||
status: Some(alpaca::api::outgoing::order::Status::All),
|
status: Some(alpaca::api::outgoing::order::Status::All),
|
||||||
limit: Some(500),
|
|
||||||
after: Some(after),
|
after: Some(after),
|
||||||
until: None,
|
..Default::default()
|
||||||
direction: Some(Sort::Asc),
|
|
||||||
nested: Some(true),
|
|
||||||
symbols: None,
|
|
||||||
side: None,
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@@ -6,10 +6,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
database,
|
database,
|
||||||
types::{
|
types::{
|
||||||
alpaca::{
|
alpaca::{self, shared::Source},
|
||||||
self,
|
|
||||||
shared::{Sort, Source},
|
|
||||||
},
|
|
||||||
news::Prediction,
|
news::Prediction,
|
||||||
Backfill, Bar, Class, News,
|
Backfill, Bar, Class, News,
|
||||||
},
|
},
|
||||||
@@ -176,19 +173,13 @@ fn us_equity_query_constructor(
|
|||||||
fetch_to: OffsetDateTime,
|
fetch_to: OffsetDateTime,
|
||||||
next_page_token: Option<String>,
|
next_page_token: Option<String>,
|
||||||
) -> alpaca::api::outgoing::bar::Bar {
|
) -> alpaca::api::outgoing::bar::Bar {
|
||||||
alpaca::api::outgoing::bar::Bar::UsEquity {
|
alpaca::api::outgoing::bar::Bar::UsEquity(alpaca::api::outgoing::bar::UsEquity {
|
||||||
symbols: vec![symbol],
|
symbols: vec![symbol],
|
||||||
timeframe: ONE_MINUTE,
|
|
||||||
start: Some(fetch_from),
|
start: Some(fetch_from),
|
||||||
end: Some(fetch_to),
|
end: Some(fetch_to),
|
||||||
limit: Some(10000),
|
|
||||||
adjustment: Some(alpaca::api::outgoing::bar::Adjustment::All),
|
|
||||||
asof: None,
|
|
||||||
feed: Some(*ALPACA_SOURCE),
|
|
||||||
currency: None,
|
|
||||||
page_token: next_page_token,
|
page_token: next_page_token,
|
||||||
sort: Some(Sort::Asc),
|
..Default::default()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crypto_query_constructor(
|
fn crypto_query_constructor(
|
||||||
@@ -197,15 +188,13 @@ fn crypto_query_constructor(
|
|||||||
fetch_to: OffsetDateTime,
|
fetch_to: OffsetDateTime,
|
||||||
next_page_token: Option<String>,
|
next_page_token: Option<String>,
|
||||||
) -> alpaca::api::outgoing::bar::Bar {
|
) -> alpaca::api::outgoing::bar::Bar {
|
||||||
alpaca::api::outgoing::bar::Bar::Crypto {
|
alpaca::api::outgoing::bar::Bar::Crypto(alpaca::api::outgoing::bar::Crypto {
|
||||||
symbols: vec![symbol],
|
symbols: vec![symbol],
|
||||||
timeframe: ONE_MINUTE,
|
|
||||||
start: Some(fetch_from),
|
start: Some(fetch_from),
|
||||||
end: Some(fetch_to),
|
end: Some(fetch_to),
|
||||||
limit: Some(10000),
|
|
||||||
page_token: next_page_token,
|
page_token: next_page_token,
|
||||||
sort: Some(Sort::Asc),
|
..Default::default()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -335,11 +324,8 @@ impl Handler for NewsHandler {
|
|||||||
symbols: vec![symbol.clone()],
|
symbols: vec![symbol.clone()],
|
||||||
start: Some(fetch_from),
|
start: Some(fetch_from),
|
||||||
end: Some(fetch_to),
|
end: Some(fetch_to),
|
||||||
limit: Some(50),
|
|
||||||
include_content: Some(true),
|
|
||||||
exclude_contentless: Some(false),
|
|
||||||
page_token: next_page_token.clone(),
|
page_token: next_page_token.clone(),
|
||||||
sort: Some(Sort::Asc),
|
..Default::default()
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
config::ALPACA_SOURCE,
|
||||||
types::alpaca::shared::{Sort, Source},
|
types::alpaca::shared::{Sort, Source},
|
||||||
utils::ser,
|
utils::{ser, ONE_MINUTE},
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -16,52 +17,90 @@ pub enum Adjustment {
|
|||||||
All,
|
All,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct UsEquity {
|
||||||
|
#[serde(serialize_with = "ser::join_symbols")]
|
||||||
|
pub symbols: Vec<String>,
|
||||||
|
#[serde(serialize_with = "ser::timeframe")]
|
||||||
|
pub timeframe: Duration,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
|
pub start: Option<OffsetDateTime>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
|
pub end: Option<OffsetDateTime>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub adjustment: Option<Adjustment>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
|
pub asof: Option<OffsetDateTime>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub feed: Option<Source>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub currency: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub page_token: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub sort: Option<Sort>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for UsEquity {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
symbols: vec![],
|
||||||
|
timeframe: ONE_MINUTE,
|
||||||
|
start: None,
|
||||||
|
end: None,
|
||||||
|
limit: Some(10000),
|
||||||
|
adjustment: Some(Adjustment::All),
|
||||||
|
asof: None,
|
||||||
|
feed: Some(*ALPACA_SOURCE),
|
||||||
|
currency: None,
|
||||||
|
page_token: None,
|
||||||
|
sort: Some(Sort::Asc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct Crypto {
|
||||||
|
#[serde(serialize_with = "ser::join_symbols")]
|
||||||
|
pub symbols: Vec<String>,
|
||||||
|
#[serde(serialize_with = "ser::timeframe")]
|
||||||
|
pub timeframe: Duration,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
|
pub start: Option<OffsetDateTime>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
|
pub end: Option<OffsetDateTime>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub page_token: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub sort: Option<Sort>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Crypto {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
symbols: vec![],
|
||||||
|
timeframe: ONE_MINUTE,
|
||||||
|
start: None,
|
||||||
|
end: None,
|
||||||
|
limit: Some(10000),
|
||||||
|
page_token: None,
|
||||||
|
sort: Some(Sort::Asc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum Bar {
|
pub enum Bar {
|
||||||
UsEquity {
|
UsEquity(UsEquity),
|
||||||
#[serde(serialize_with = "ser::join_symbols")]
|
Crypto(Crypto),
|
||||||
symbols: Vec<String>,
|
|
||||||
#[serde(serialize_with = "ser::timeframe")]
|
|
||||||
timeframe: Duration,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
|
||||||
start: Option<OffsetDateTime>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
|
||||||
end: Option<OffsetDateTime>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
limit: Option<i64>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
adjustment: Option<Adjustment>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
|
||||||
asof: Option<OffsetDateTime>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
feed: Option<Source>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
currency: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
page_token: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
sort: Option<Sort>,
|
|
||||||
},
|
|
||||||
Crypto {
|
|
||||||
#[serde(serialize_with = "ser::join_symbols")]
|
|
||||||
symbols: Vec<String>,
|
|
||||||
#[serde(serialize_with = "ser::timeframe")]
|
|
||||||
timeframe: Duration,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
|
||||||
start: Option<OffsetDateTime>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
|
||||||
end: Option<OffsetDateTime>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
limit: Option<i64>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
page_token: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
sort: Option<Sort>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
@@ -23,3 +23,18 @@ pub struct News {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub sort: Option<Sort>,
|
pub sort: Option<Sort>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for News {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
symbols: vec![],
|
||||||
|
start: None,
|
||||||
|
end: None,
|
||||||
|
limit: Some(50),
|
||||||
|
include_content: Some(true),
|
||||||
|
exclude_contentless: Some(false),
|
||||||
|
page_token: None,
|
||||||
|
sort: Some(Sort::Asc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -36,3 +36,18 @@ pub struct Order {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub side: Option<Side>,
|
pub side: Option<Side>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Order {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
status: Some(Status::All),
|
||||||
|
limit: Some(500),
|
||||||
|
after: None,
|
||||||
|
until: None,
|
||||||
|
direction: Some(Sort::Asc),
|
||||||
|
nested: Some(true),
|
||||||
|
symbols: None,
|
||||||
|
side: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user