added function aggregating multiple ticker data
This commit is contained in:
@@ -6,8 +6,8 @@ use chrono::{DateTime, Duration, NaiveDate, Timelike, Utc};
|
||||
use tokio::time::{sleep, Duration as TokioDuration};
|
||||
use reqwest::Client as HttpClient;
|
||||
use serde_json::Value;
|
||||
use yfinance_rs::{YfClient, Ticker, Range, Interval, HistoryBuilder};
|
||||
use yfinance_rs::core::conversions::money_to_f64;
|
||||
//use yfinance_rs::{YfClient, Ticker, Range, Interval, HistoryBuilder};
|
||||
//use yfinance_rs::core::conversions::money_to_f64;
|
||||
|
||||
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36";
|
||||
|
||||
@@ -182,21 +182,23 @@ pub async fn fetch_daily_price_history(
|
||||
all_prices.push(CompanyPrice {
|
||||
ticker: ticker.to_string(),
|
||||
date: date_str,
|
||||
time: "".to_string(), // Empty for daily
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
adj_close,
|
||||
volume,
|
||||
currency: "USD".to_string(), // Assuming USD for now
|
||||
});
|
||||
}
|
||||
|
||||
sleep(TokioDuration::from_millis(200));
|
||||
sleep(TokioDuration::from_millis(200)).await;
|
||||
current = actual_end;
|
||||
}
|
||||
|
||||
all_prices.sort_by_key(|p| p.date.clone());
|
||||
all_prices.dedup_by_key(|p| p.date.clone());
|
||||
all_prices.sort_by_key(|p| (p.date.clone(), p.time.clone()));
|
||||
all_prices.dedup_by(|a, b| a.date == b.date && a.time == b.time);
|
||||
|
||||
println!(" Got {} daily bars for {ticker}", all_prices.len());
|
||||
Ok(all_prices)
|
||||
@@ -233,6 +235,7 @@ let now = Utc::now().timestamp();
|
||||
let ts = ts_val.as_i64().unwrap_or(0);
|
||||
let dt: DateTime<Utc> = DateTime::from_timestamp(ts, 0).unwrap_or_default();
|
||||
let date_str = dt.format("%Y-%m-%d").to_string();
|
||||
let time_str = dt.format("%H:%M:%S").to_string();
|
||||
|
||||
let open = parse_price(quote["open"].as_array().and_then(|a| a.get(i)));
|
||||
let high = parse_price(quote["high"].as_array().and_then(|a| a.get(i)));
|
||||
@@ -243,16 +246,18 @@ let now = Utc::now().timestamp();
|
||||
prices.push(CompanyPrice {
|
||||
ticker: ticker.to_string(),
|
||||
date: date_str,
|
||||
time: time_str, // Full time for 5min intraday
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
adj_close: close, // intraday usually not adjusted
|
||||
volume,
|
||||
currency: "USD".to_string(), // Assuming USD for now
|
||||
});
|
||||
}
|
||||
|
||||
prices.sort_by_key(|p| p.date.clone());
|
||||
prices.sort_by_key(|p| (p.date.clone(), p.time.clone()));
|
||||
Ok(prices)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user