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