From d3091369f485747eff27465e088ac6232d23e1d2 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 31 Mar 2024 18:41:21 +0100 Subject: [PATCH] fetch symbols every thirty seconds --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b60ba60..ee41bee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,11 @@ +use async_std::prelude::*; use chrono::prelude::*; + use clap::Parser; -use std::io::{Error, ErrorKind}; +use std::{ + io::{Error, ErrorKind}, + time::Duration, +}; use yahoo_finance_api as yahoo; #[derive(Parser, Debug)] @@ -169,7 +174,10 @@ async fn main() -> std::io::Result<()> { // a simple way to output a CSV header println!("period start,symbol,price,change %,min,max,30d avg"); - fetch_and_output_symbol_data(&opts.symbols, from, to).await?; + let mut interval = async_std::stream::interval(Duration::from_secs(30)); + while let Some(_) = interval.next().await { + fetch_and_output_symbol_data(&opts.symbols, from, to).await?; + } Ok(()) }