use std::sync::Arc;
use tokio::sync::mpsc;
use crate::{
Config, Result,
blocking::runtime::BlockingRuntime,
fundamental::{FundamentalContext, types::*},
};
pub struct FundamentalContextSync {
rt: BlockingRuntime<FundamentalContext>,
}
impl FundamentalContextSync {
pub fn new(config: Arc<Config>) -> Result<Self> {
let rt = BlockingRuntime::try_new(
move || {
let ctx = FundamentalContext::new(config);
let (tx, rx) = mpsc::unbounded_channel::<std::convert::Infallible>();
std::mem::forget(tx);
Ok::<_, crate::Error>((ctx, rx))
},
|_: std::convert::Infallible| {},
)?;
Ok(Self { rt })
}
pub fn financial_report(
&self,
symbol: impl Into<String> + Send + 'static,
kind: FinancialReportKind,
period: Option<FinancialReportPeriod>,
) -> Result<FinancialReports> {
self.rt
.call(move |ctx| async move { ctx.financial_report(symbol, kind, period).await })
}
pub fn institution_rating(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<InstitutionRating> {
self.rt
.call(move |ctx| async move { ctx.institution_rating(symbol).await })
}
pub fn institution_rating_detail(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<InstitutionRatingDetail> {
self.rt
.call(move |ctx| async move { ctx.institution_rating_detail(symbol).await })
}
pub fn dividend(&self, symbol: impl Into<String> + Send + 'static) -> Result<DividendList> {
self.rt
.call(move |ctx| async move { ctx.dividend(symbol).await })
}
pub fn dividend_detail(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<DividendList> {
self.rt
.call(move |ctx| async move { ctx.dividend_detail(symbol).await })
}
pub fn forecast_eps(&self, symbol: impl Into<String> + Send + 'static) -> Result<ForecastEps> {
self.rt
.call(move |ctx| async move { ctx.forecast_eps(symbol).await })
}
pub fn consensus(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<FinancialConsensus> {
self.rt
.call(move |ctx| async move { ctx.consensus(symbol).await })
}
pub fn valuation(&self, symbol: impl Into<String> + Send + 'static) -> Result<ValuationData> {
self.rt
.call(move |ctx| async move { ctx.valuation(symbol).await })
}
pub fn valuation_history(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<ValuationHistoryResponse> {
self.rt
.call(move |ctx| async move { ctx.valuation_history(symbol).await })
}
pub fn industry_valuation(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<IndustryValuationList> {
self.rt
.call(move |ctx| async move { ctx.industry_valuation(symbol).await })
}
pub fn industry_valuation_dist(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<IndustryValuationDist> {
self.rt
.call(move |ctx| async move { ctx.industry_valuation_dist(symbol).await })
}
pub fn company(&self, symbol: impl Into<String> + Send + 'static) -> Result<CompanyOverview> {
self.rt
.call(move |ctx| async move { ctx.company(symbol).await })
}
pub fn executive(&self, symbol: impl Into<String> + Send + 'static) -> Result<ExecutiveList> {
self.rt
.call(move |ctx| async move { ctx.executive(symbol).await })
}
pub fn shareholder(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<ShareholderList> {
self.rt
.call(move |ctx| async move { ctx.shareholder(symbol).await })
}
pub fn fund_holder(&self, symbol: impl Into<String> + Send + 'static) -> Result<FundHolders> {
self.rt
.call(move |ctx| async move { ctx.fund_holder(symbol).await })
}
pub fn corp_action(&self, symbol: impl Into<String> + Send + 'static) -> Result<CorpActions> {
self.rt
.call(move |ctx| async move { ctx.corp_action(symbol).await })
}
pub fn invest_relation(
&self,
symbol: impl Into<String> + Send + 'static,
) -> Result<InvestRelations> {
self.rt
.call(move |ctx| async move { ctx.invest_relation(symbol).await })
}
pub fn operating(&self, symbol: impl Into<String> + Send + 'static) -> Result<OperatingList> {
self.rt
.call(move |ctx| async move { ctx.operating(symbol).await })
}
pub fn buyback(&self, symbol: impl Into<String> + Send + 'static) -> Result<BuybackData> {
self.rt
.call(move |ctx| async move { ctx.buyback(symbol).await })
}
pub fn ratings(&self, symbol: impl Into<String> + Send + 'static) -> Result<StockRatings> {
self.rt
.call(move |ctx| async move { ctx.ratings(symbol).await })
}
}