From 61904a1ef1ba9995b291c587bcbb66897e728f91 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 31 Mar 2024 18:34:23 +0100 Subject: [PATCH] extract fetch_and_output_symbol_data --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bba22b1..b60ba60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,6 +150,17 @@ async fn fetch_and_output_closing_data( Ok(()) } +async fn fetch_and_output_symbol_data( + symbols: &str, + from: DateTime, + to: DateTime, +) -> std::io::Result<()> { + for symbol in symbols.split(',') { + fetch_and_output_closing_data(symbol, from, to).await?; + } + Ok(()) +} + #[async_std::main] async fn main() -> std::io::Result<()> { let opts = Opts::parse(); @@ -158,9 +169,7 @@ async fn main() -> std::io::Result<()> { // a simple way to output a CSV header println!("period start,symbol,price,change %,min,max,30d avg"); - for symbol in opts.symbols.split(',') { - fetch_and_output_closing_data(symbol, from, to).await?; - } + fetch_and_output_symbol_data(&opts.symbols, from, to).await?; Ok(()) }