mod api;
mod model;
mod fetch;
mod wire;
pub use model::{
BalanceSheetRow, Calendar, CashflowRow, Earnings, EarningsQuarter, EarningsQuarterEps,
EarningsYear, IncomeStatementRow, ShareCount,
};
use crate::{
YfClient, YfError,
core::client::{CacheMode, RetryConfig},
};
use paft::prelude::Currency;
pub struct FundamentalsBuilder {
client: YfClient,
symbol: String,
cache_mode: CacheMode,
retry_override: Option<RetryConfig>,
}
impl FundamentalsBuilder {
pub fn new(client: &YfClient, symbol: impl Into<String>) -> Self {
Self {
client: client.clone(),
symbol: symbol.into(),
cache_mode: CacheMode::Use,
retry_override: None,
}
}
#[must_use]
pub const fn cache_mode(mut self, mode: CacheMode) -> Self {
self.cache_mode = mode;
self
}
#[must_use]
pub fn retry_policy(mut self, cfg: Option<RetryConfig>) -> Self {
self.retry_override = cfg;
self
}
pub async fn income_statement(
&self,
quarterly: bool,
override_currency: Option<Currency>,
) -> Result<Vec<IncomeStatementRow>, YfError> {
let currency = self
.client
.reporting_currency(&self.symbol, override_currency)
.await;
api::income_statement(
&self.client,
&self.symbol,
quarterly,
currency,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
pub async fn balance_sheet(
&self,
quarterly: bool,
override_currency: Option<Currency>,
) -> Result<Vec<BalanceSheetRow>, YfError> {
let currency = self
.client
.reporting_currency(&self.symbol, override_currency)
.await;
api::balance_sheet(
&self.client,
&self.symbol,
quarterly,
currency,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
pub async fn cashflow(
&self,
quarterly: bool,
override_currency: Option<Currency>,
) -> Result<Vec<CashflowRow>, YfError> {
let currency = self
.client
.reporting_currency(&self.symbol, override_currency)
.await;
api::cashflow(
&self.client,
&self.symbol,
quarterly,
currency,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
pub async fn earnings(&self, override_currency: Option<Currency>) -> Result<Earnings, YfError> {
let currency = self
.client
.reporting_currency(&self.symbol, override_currency)
.await;
api::earnings(
&self.client,
&self.symbol,
currency,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
pub async fn calendar(&self) -> Result<Calendar, YfError> {
api::calendar(
&self.client,
&self.symbol,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
pub async fn shares(&self, quarterly: bool) -> Result<Vec<ShareCount>, YfError> {
api::shares(
&self.client,
&self.symbol,
None,
None,
quarterly,
self.cache_mode,
self.retry_override.as_ref(),
)
.await
}
}