diff --git a/src/lib/types/alpaca/api/incoming/asset.rs b/src/lib/types/alpaca/api/incoming/asset.rs index bfa4ab7..093c43e 100644 --- a/src/lib/types/alpaca/api/incoming/asset.rs +++ b/src/lib/types/alpaca/api/incoming/asset.rs @@ -138,9 +138,8 @@ pub async fn get_by_symbols( backoff: Option, api_base: &str, ) -> Result, Error> { - if symbols.len() < 2 { - let symbol = symbols.first().unwrap(); - let asset = get_by_symbol(client, rate_limiter, symbol, backoff, api_base).await?; + if symbols.len() == 1 { + let asset = get_by_symbol(client, rate_limiter, &symbols[0], backoff, api_base).await?; return Ok(vec![asset]); } diff --git a/src/lib/types/alpaca/api/incoming/position.rs b/src/lib/types/alpaca/api/incoming/position.rs index 2342eb1..f95113c 100644 --- a/src/lib/types/alpaca/api/incoming/position.rs +++ b/src/lib/types/alpaca/api/incoming/position.rs @@ -157,9 +157,8 @@ pub async fn get_by_symbols( backoff: Option, api_base: &str, ) -> Result, reqwest::Error> { - if symbols.len() < 2 { - let symbol = symbols.first().unwrap(); - let position = get_by_symbol(client, rate_limiter, symbol, backoff, api_base).await?; + if symbols.len() == 1 { + let position = get_by_symbol(client, rate_limiter, &symbols[0], backoff, api_base).await?; return Ok(position.into_iter().collect()); } diff --git a/src/threads/data/backfill/bars.rs b/src/threads/data/backfill/bars.rs index 61ec584..0486ea7 100644 --- a/src/threads/data/backfill/bars.rs +++ b/src/threads/data/backfill/bars.rs @@ -96,7 +96,7 @@ impl super::Handler for Handler { } async fn queue_backfill(&self, jobs: &HashMap) { - if *ALPACA_SOURCE == Source::Sip { + if jobs.is_empty() || *ALPACA_SOURCE == Source::Sip { return; } @@ -109,6 +109,10 @@ impl super::Handler for Handler { } async fn backfill(&self, jobs: HashMap) { + if jobs.is_empty() { + return; + } + let symbols = jobs.keys().cloned().collect::>(); let fetch_from = jobs.values().map(|job| job.fetch_from).min().unwrap(); let fetch_to = jobs.values().map(|job| job.fetch_to).max().unwrap(); diff --git a/src/threads/data/backfill/mod.rs b/src/threads/data/backfill/mod.rs index 473e23f..0a38dba 100644 --- a/src/threads/data/backfill/mod.rs +++ b/src/threads/data/backfill/mod.rs @@ -174,6 +174,10 @@ async fn handle_backfill_message( )); } + if jobs.is_empty() { + return; + } + let jobs = jobs .into_iter() .sorted_unstable_by_key(|job| job.1.fetch_from) diff --git a/src/threads/data/backfill/news.rs b/src/threads/data/backfill/news.rs index ffc2486..0bb4d16 100644 --- a/src/threads/data/backfill/news.rs +++ b/src/threads/data/backfill/news.rs @@ -57,7 +57,7 @@ impl super::Handler for Handler { } async fn queue_backfill(&self, jobs: &HashMap) { - if *ALPACA_SOURCE == Source::Sip { + if jobs.is_empty() || *ALPACA_SOURCE == Source::Sip { return; } @@ -71,6 +71,10 @@ impl super::Handler for Handler { #[allow(clippy::too_many_lines)] async fn backfill(&self, jobs: HashMap) { + if jobs.is_empty() { + return; + } + let symbols = jobs.keys().cloned().collect::>(); let fetch_from = jobs.values().map(|job| job.fetch_from).min().unwrap(); let fetch_to = jobs.values().map(|job| job.fetch_to).max().unwrap();