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

@@ -2,7 +2,7 @@
use super::types::{CompanyEvent, CompanyPrice, CompanyEventChange};
use super::helpers::*;
use tokio::fs;
use chrono::{Local, NaiveDate, Datelike};
use chrono::{Datelike, NaiveDate};
use std::collections::HashMap;
pub async fn load_existing_events() -> anyhow::Result<HashMap<String, CompanyEvent>> {
@@ -86,10 +86,10 @@ pub async fn save_changes(changes: &[CompanyEventChange]) -> anyhow::Result<()>
Ok(())
}
pub async fn save_prices_for_ticker(ticker: &str, mut prices: Vec<CompanyPrice>) -> anyhow::Result<()> {
pub async fn save_prices_for_ticker(ticker: &str, timeframe: &str, mut prices: Vec<CompanyPrice>) -> anyhow::Result<()> {
let dir = std::path::Path::new("corporate_prices");
fs::create_dir_all(dir).await?;
let path = dir.join(format!("{}.json", ticker));
let path = dir.join(format!("{}_{}.json", ticker.replace(".", "_"), timeframe));
prices.sort_by_key(|p| p.date.clone());