use super::urls::api;
use crate::client::YahooClient;
use crate::error::Result;
use tracing::info;
#[allow(dead_code)]
pub(crate) async fn fetch(client: &YahooClient, symbols: &[&str]) -> Result<serde_json::Value> {
super::common::validate_symbols(symbols)?;
info!("Fetching batch quotes for {} symbols", symbols.len());
let params = [("symbols", symbols.join(","))];
let response = client.request_with_params(api::QUOTES, ¶ms).await?;
Ok(response.json().await?)
}
#[allow(dead_code)]
pub(crate) async fn fetch_with_fields(
client: &YahooClient,
symbols: &[&str],
fields: Option<&[&str]>,
formatted: bool,
include_logo: bool,
) -> Result<serde_json::Value> {
super::common::validate_symbols(symbols)?;
info!(
"Fetching batch quotes for {} symbols with custom fields (formatted={}, include_logo={})",
symbols.len(),
formatted,
include_logo
);
let config = client.config();
let mut params: Vec<(&str, std::borrow::Cow<str>)> = vec![
("symbols", symbols.join(",").into()),
(
"formatted",
if formatted {
"true".into()
} else {
"false".into()
},
),
];
if let Some(field_list) = fields {
params.push(("fields", field_list.join(",").into()));
}
if include_logo {
params.push(("imgHeights", "50".into()));
params.push(("imgWidths", "50".into()));
params.push(("imgLabels", "logoUrl".into()));
}
params.push(("overnightPrice", "true".into()));
params.push(("lang", (&*config.lang).into()));
params.push(("region", (&*config.region).into()));
let response = client.request_with_params(api::QUOTES, ¶ms).await?;
Ok(response.json().await?)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::ClientConfig;
#[tokio::test]
#[ignore] async fn test_fetch_batch_quotes() {
let client = YahooClient::new(ClientConfig::default()).await.unwrap();
let result = fetch(&client, &["AAPL", "GOOGL"]).await;
assert!(result.is_ok());
let json = result.unwrap();
assert!(json.get("quoteResponse").is_some());
}
#[tokio::test]
#[ignore = "requires network access - validation tested in common::tests"]
async fn test_empty_symbols() {
let client = YahooClient::new(ClientConfig::default()).await.unwrap();
let result = fetch(&client, &[]).await;
assert!(result.is_err());
}
}