extract output_csv_line
This commit is contained in:
parent
45841db4ed
commit
15d919e62c
1 changed files with 21 additions and 18 deletions
27
src/main.rs
27
src/main.rs
|
@ -118,18 +118,7 @@ async fn fetch_closing_data(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::main]
|
fn output_csv_line(closes: Vec<f64>, from: DateTime<Utc>, symbol: &str) {
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
let opts = Opts::parse();
|
|
||||||
let from: DateTime<Utc> = opts.from.parse().expect("Couldn't parse 'from' date");
|
|
||||||
let to = Utc::now();
|
|
||||||
|
|
||||||
// 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() {
|
|
||||||
// min/max of the period. unwrap() because those are Option types
|
|
||||||
let period_max: f64 = max(&closes).unwrap();
|
let period_max: f64 = max(&closes).unwrap();
|
||||||
let period_min: f64 = min(&closes).unwrap();
|
let period_min: f64 = min(&closes).unwrap();
|
||||||
let last_price = *closes.last().unwrap_or(&0.0);
|
let last_price = *closes.last().unwrap_or(&0.0);
|
||||||
|
@ -147,6 +136,20 @@ async fn main() -> std::io::Result<()> {
|
||||||
period_max,
|
period_max,
|
||||||
sma.last().unwrap_or(&0.0)
|
sma.last().unwrap_or(&0.0)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let opts = Opts::parse();
|
||||||
|
let from: DateTime<Utc> = opts.from.parse().expect("Couldn't parse 'from' date");
|
||||||
|
let to = Utc::now();
|
||||||
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue