From fe660459d91bcf9487f5962167ce43384c9bf393 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 31 Mar 2024 18:30:20 +0100 Subject: [PATCH] extract fetch_and_output_closing_data --- src/main.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0deca70..bba22b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,6 +138,18 @@ fn output_csv_line(closes: Vec, from: DateTime, symbol: &str) { ); } +async fn fetch_and_output_closing_data( + symbol: &str, + from: DateTime, + to: DateTime, +) -> std::io::Result<()> { + let closes = fetch_closing_data(&symbol, &from, &to).await?; + if !closes.is_empty() { + output_csv_line(closes, from, symbol); + } + Ok(()) +} + #[async_std::main] async fn main() -> std::io::Result<()> { let opts = Opts::parse(); @@ -147,10 +159,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(',') { - let closes = fetch_closing_data(&symbol, &from, &to).await?; - if !closes.is_empty() { - output_csv_line(closes, from, symbol); - } + fetch_and_output_closing_data(symbol, from, to).await?; } Ok(()) }