extract fetch_and_output_closing_data
This commit is contained in:
parent
15d919e62c
commit
fe660459d9
1 changed files with 13 additions and 4 deletions
17
src/main.rs
17
src/main.rs
|
@ -138,6 +138,18 @@ fn output_csv_line(closes: Vec<f64>, from: DateTime<Utc>, symbol: &str) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn fetch_and_output_closing_data(
|
||||||
|
symbol: &str,
|
||||||
|
from: DateTime<Utc>,
|
||||||
|
to: DateTime<Utc>,
|
||||||
|
) -> 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_std::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
|
@ -147,10 +159,7 @@ 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");
|
||||||
for symbol in opts.symbols.split(',') {
|
for symbol in opts.symbols.split(',') {
|
||||||
let closes = fetch_closing_data(&symbol, &from, &to).await?;
|
fetch_and_output_closing_data(symbol, from, to).await?;
|
||||||
if !closes.is_empty() {
|
|
||||||
output_csv_line(closes, from, symbol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue