fetching 5min data only for the last 60 days

This commit is contained in:
2025-11-23 21:43:53 +01:00
parent 462f7ca672
commit 7b680f960f
4 changed files with 192 additions and 46 deletions

View File

@@ -1,6 +1,7 @@
// src/corporate/update.rs
use super::{scraper::*, storage::*, helpers::*, types::*};
use crate::config::Config;
use yfinance_rs::{Range, Interval};
use chrono::Local;
use std::collections::HashMap;
@@ -21,8 +22,27 @@ pub async fn run_full_update(client: &fantoccini::Client, tickers: Vec<String>,
println!("{} earnings, {} changes", new_events.len(), result.changes.len());
}
if let Ok(prices) = fetch_price_history(ticker, &config.corporate_start_date, &today).await {
save_prices_for_ticker(ticker, prices).await?;
// DAILY full history
if let Ok(prices) = fetch_daily_price_history(ticker, &config.corporate_start_date, &today).await {
save_prices_for_ticker(ticker, "daily", prices).await?;
}
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
// 5-MINUTE only last 60 days (Yahoo limit for intraday)
let sixty_days_ago = (chrono::Local::now() - chrono::Duration::days(60))
.format("%Y-%m-%d")
.to_string();
if let Ok(prices) = fetch_price_history_5min(ticker, &sixty_days_ago, &today).await {
if !prices.is_empty() {
save_prices_for_ticker(ticker, "5min", prices.clone()).await?;
println!(" Saved {} 5min bars for {ticker}", prices.len());
} else {
println!(" No 5min data available for {ticker} (market closed? retry later)");
}
} else {
println!(" 5min fetch failed for {ticker} (rate limit? try again)");
}
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;