fetch symbols every thirty seconds

This commit is contained in:
Paul Campbell 2024-03-31 18:41:21 +01:00
parent 1337176474
commit d3091369f4

View file

@ -1,6 +1,11 @@
use async_std::prelude::*;
use chrono::prelude::*; use chrono::prelude::*;
use clap::Parser; use clap::Parser;
use std::io::{Error, ErrorKind}; use std::{
io::{Error, ErrorKind},
time::Duration,
};
use yahoo_finance_api as yahoo; use yahoo_finance_api as yahoo;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -169,7 +174,10 @@ async fn main() -> std::io::Result<()> {
// a simple way to output a CSV header // a simple way to output a CSV header
println!("period start,symbol,price,change %,min,max,30d avg"); println!("period start,symbol,price,change %,min,max,30d avg");
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?; fetch_and_output_symbol_data(&opts.symbols, from, to).await?;
}
Ok(()) Ok(())
} }