diff --git a/src/init.rs b/src/init.rs index dca3b2b..0fc425e 100644 --- a/src/init.rs +++ b/src/init.rs @@ -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.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, ) diff --git a/src/threads/data/backfill.rs b/src/threads/data/backfill.rs index 9fb48eb..565a2bf 100644 --- a/src/threads/data/backfill.rs +++ b/src/threads/data/backfill.rs @@ -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, ) -> 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, ) -> 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, ) diff --git a/src/types/alpaca/api/outgoing/bar.rs b/src/types/alpaca/api/outgoing/bar.rs index b8c81da..d548a03 100644 --- a/src/types/alpaca/api/outgoing/bar.rs +++ b/src/types/alpaca/api/outgoing/bar.rs @@ -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, + #[serde(serialize_with = "ser::timeframe")] + pub timeframe: Duration, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "time::serde::rfc3339::option")] + pub start: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "time::serde::rfc3339::option")] + pub end: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub adjustment: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "time::serde::rfc3339::option")] + pub asof: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub feed: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub currency: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub page_token: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub sort: Option, +} + +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, + #[serde(serialize_with = "ser::timeframe")] + pub timeframe: Duration, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "time::serde::rfc3339::option")] + pub start: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "time::serde::rfc3339::option")] + pub end: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub page_token: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub sort: Option, +} + +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, - #[serde(serialize_with = "ser::timeframe")] - timeframe: Duration, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "time::serde::rfc3339::option")] - start: Option, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "time::serde::rfc3339::option")] - end: Option, - #[serde(skip_serializing_if = "Option::is_none")] - limit: Option, - #[serde(skip_serializing_if = "Option::is_none")] - adjustment: Option, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "time::serde::rfc3339::option")] - asof: Option, - #[serde(skip_serializing_if = "Option::is_none")] - feed: Option, - #[serde(skip_serializing_if = "Option::is_none")] - currency: Option, - #[serde(skip_serializing_if = "Option::is_none")] - page_token: Option, - #[serde(skip_serializing_if = "Option::is_none")] - sort: Option, - }, - Crypto { - #[serde(serialize_with = "ser::join_symbols")] - symbols: Vec, - #[serde(serialize_with = "ser::timeframe")] - timeframe: Duration, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "time::serde::rfc3339::option")] - start: Option, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "time::serde::rfc3339::option")] - end: Option, - #[serde(skip_serializing_if = "Option::is_none")] - limit: Option, - #[serde(skip_serializing_if = "Option::is_none")] - page_token: Option, - #[serde(skip_serializing_if = "Option::is_none")] - sort: Option, - }, + UsEquity(UsEquity), + Crypto(Crypto), } diff --git a/src/types/alpaca/api/outgoing/news.rs b/src/types/alpaca/api/outgoing/news.rs index b50df11..aae45d1 100644 --- a/src/types/alpaca/api/outgoing/news.rs +++ b/src/types/alpaca/api/outgoing/news.rs @@ -23,3 +23,18 @@ pub struct News { #[serde(skip_serializing_if = "Option::is_none")] pub sort: Option, } + +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), + } + } +} diff --git a/src/types/alpaca/api/outgoing/order.rs b/src/types/alpaca/api/outgoing/order.rs index 4d31f83..4b66d72 100644 --- a/src/types/alpaca/api/outgoing/order.rs +++ b/src/types/alpaca/api/outgoing/order.rs @@ -36,3 +36,18 @@ pub struct Order { #[serde(skip_serializing_if = "Option::is_none")] pub side: Option, } + +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, + } + } +}