use crate::adapters::yahoo::client::{ClientConfig, YahooClient};
use crate::constants::{Interval, TimeRange};
use crate::error::Result;
use std::sync::Arc;
pub(crate) struct YahooProvider {
client: Arc<YahooClient>,
}
impl YahooProvider {
pub(crate) async fn new(config: &ClientConfig) -> Result<Self> {
Ok(Self {
client: Arc::new(YahooClient::new(config.clone()).await?),
})
}
pub(crate) fn from_client(client: Arc<YahooClient>) -> Self {
Self { client }
}
pub(crate) fn client_arc(&self) -> Arc<YahooClient> {
Arc::clone(&self.client)
}
}
#[async_trait::async_trait]
impl super::ProviderAdapter for YahooProvider {
fn id(&self) -> &'static str {
"yahoo"
}
fn capabilities(&self) -> super::Capability {
super::Capability::QUOTE
| super::Capability::CHART
| super::Capability::FUNDAMENTALS
| super::Capability::CORPORATE
| super::Capability::OPTIONS
}
async fn fetch_quote(
&self,
symbol: &str,
) -> Result<crate::models::quote::QuoteSummaryResponse> {
crate::adapters::yahoo::quote::summary::fetch_summary(&self.client, symbol).await
}
async fn fetch_chart(
&self,
symbol: &str,
interval: Interval,
range: TimeRange,
) -> Result<crate::models::chart::Chart> {
crate::adapters::yahoo::chart::fetch_chart(&self.client, symbol, interval, range).await
}
async fn fetch_chart_range(
&self,
symbol: &str,
interval: Interval,
start: i64,
end: i64,
) -> Result<crate::models::chart::Chart> {
crate::adapters::yahoo::chart::fetch_chart_with_dates(
&self.client,
symbol,
interval,
start,
end,
)
.await
}
async fn fetch_financials(
&self,
symbol: &str,
stmt_type: crate::StatementType,
frequency: crate::Frequency,
) -> Result<crate::models::fundamentals::FinancialStatement> {
let mut stmt =
crate::adapters::yahoo::fundamentals::fetch(&self.client, symbol, stmt_type, frequency)
.await?;
stmt.provider_id = Some(super::Provider::Yahoo);
Ok(stmt)
}
async fn fetch_news(&self, symbol: &str) -> Result<Vec<crate::models::corporate::news::News>> {
crate::adapters::yahoo::corporate::news::fetch_news(symbol).await
}
async fn fetch_similar_symbols(
&self,
symbol: &str,
limit: u32,
) -> Result<Vec<crate::models::corporate::recommendation::SimilarSymbol>> {
crate::adapters::yahoo::corporate::recommendations::fetch(&self.client, symbol, limit).await
}
async fn fetch_options(
&self,
symbol: &str,
date: Option<i64>,
) -> Result<crate::models::options::Options> {
crate::adapters::yahoo::options::fetch(&self.client, symbol, date).await
}
async fn fetch_events(
&self,
symbol: &str,
) -> Result<crate::models::chart::events::ChartEvents> {
crate::adapters::yahoo::chart::fetch_events(&self.client, symbol).await
}
async fn fetch_quotes_batch(
&self,
symbols: &[&str],
) -> Result<Vec<(String, crate::models::quote::QuoteSummaryResponse)>> {
crate::adapters::yahoo::quote::quotes::fetch_quotes_batch(&self.client, symbols).await
}
}