1use super::{Capability, Provider};
4use crate::error::FinanceError;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13#[non_exhaustive]
14pub enum Operation {
15 Quote,
17 Chart,
19 ChartRange,
21 Financials,
23 News,
25 Recommendations,
27 Options,
29 Events,
31 QuotesBatch,
33 Spark,
35 CryptoQuote,
37 CryptoNews,
39 EconomicSeries,
41 ForexQuote,
43 ForexNews,
45 IndicesQuote,
47 FuturesQuote,
49 CommoditiesQuote,
51 Filings,
53 SymbolSearch,
55 SymbolDetails,
57 Exchanges,
59 Screener,
61 EarningsCalendar,
63 IpoCalendar,
65 DividendCalendar,
67 SplitCalendar,
69 EconomicCalendar,
71 SectorPerformance,
73 MarketMovers,
75 SectorPerformanceHistory,
77 HolidayCalendar,
79 MarketStatus,
81 IndexConstituents,
83 IndexConstituentChanges,
85 ShortInterest,
87 ShortVolume,
89 ShareFloat,
91 FilingSections,
93 RiskFactors,
95 PressReleases,
97 EarningsTranscript,
99 #[cfg(feature = "defi")]
101 ProtocolTvl,
102 #[cfg(feature = "defi")]
104 ProtocolTvlHistory,
105 #[cfg(feature = "cftc")]
107 CommitmentsOfTraders,
108 PriceTargetConsensus,
110 PriceTargetSummary,
112 RatingConsensus,
114 KeyMetricsTtm,
116 RatiosTtm,
118 ExecutiveCompensation,
120 EmployeeCount,
122 CompanyProfile,
124 UnifiedSnapshot,
126 FilingSearch,
128 InsiderTrades,
130 InstitutionalHoldings,
132 CongressionalTrades,
134 FailsToDeliver,
136 EconomicSeriesAsOf,
138 EconomicSearch,
140 EconomicCategories,
142 EconomicReleases,
144 #[cfg(feature = "fiscaldata")]
146 TreasuryAuctions,
147 #[cfg(feature = "fiscaldata")]
149 UpcomingAuctions,
150 EtfProfile,
152 EarningsSurprises,
154 GradingHistory,
156 ListingStatus,
158 GroupedDaily,
160 CryptoGroupedDaily,
162 ForexGroupedDaily,
164 #[cfg(feature = "crypto")]
166 CryptoTrending,
167 #[cfg(feature = "crypto")]
169 CryptoGlobal,
170}
171
172impl Operation {
173 pub fn as_str(self) -> &'static str {
175 match self {
176 Self::Quote => "quote",
177 Self::Chart => "chart",
178 Self::ChartRange => "chart_range",
179 Self::Financials => "financials",
180 Self::News => "news",
181 Self::Recommendations => "recommendations",
182 Self::Options => "options",
183 Self::Events => "events",
184 Self::QuotesBatch => "quotes_batch",
185 Self::Spark => "spark",
186 Self::CryptoQuote => "crypto_quote",
187 Self::CryptoNews => "crypto_news",
188 Self::EconomicSeries => "economic_series",
189 Self::ForexQuote => "forex_quote",
190 Self::ForexNews => "forex_news",
191 Self::IndicesQuote => "indices_quote",
192 Self::FuturesQuote => "futures_quote",
193 Self::CommoditiesQuote => "commodities_quote",
194 Self::Filings => "filings",
195 Self::SymbolSearch => "symbol_search",
196 Self::SymbolDetails => "symbol_details",
197 Self::Exchanges => "exchanges",
198 Self::Screener => "screener",
199 Self::EarningsCalendar => "earnings_calendar",
200 Self::IpoCalendar => "ipo_calendar",
201 Self::DividendCalendar => "dividend_calendar",
202 Self::SplitCalendar => "split_calendar",
203 Self::EconomicCalendar => "economic_calendar",
204 Self::SectorPerformance => "sector_performance",
205 Self::MarketMovers => "market_movers",
206 Self::SectorPerformanceHistory => "sector_performance_history",
207 Self::HolidayCalendar => "holiday_calendar",
208 Self::MarketStatus => "market_status",
209 Self::IndexConstituents => "index_constituents",
210 Self::IndexConstituentChanges => "index_constituent_changes",
211 Self::ShortInterest => "short_interest",
212 Self::ShortVolume => "short_volume",
213 Self::ShareFloat => "share_float",
214 Self::FilingSections => "filing_sections",
215 Self::RiskFactors => "risk_factors",
216 Self::PressReleases => "press_releases",
217 Self::EarningsTranscript => "earnings_transcript",
218 #[cfg(feature = "defi")]
219 Self::ProtocolTvl => "protocol_tvl",
220 #[cfg(feature = "defi")]
221 Self::ProtocolTvlHistory => "protocol_tvl_history",
222 #[cfg(feature = "cftc")]
223 Self::CommitmentsOfTraders => "commitments_of_traders",
224 Self::PriceTargetConsensus => "price_target_consensus",
225 Self::PriceTargetSummary => "price_target_summary",
226 Self::RatingConsensus => "rating_consensus",
227 Self::KeyMetricsTtm => "key_metrics_ttm",
228 Self::RatiosTtm => "ratios_ttm",
229 Self::ExecutiveCompensation => "executive_compensation",
230 Self::EmployeeCount => "employee_count",
231 Self::CompanyProfile => "company_profile",
232 Self::UnifiedSnapshot => "unified_snapshot",
233 Self::FilingSearch => "filing_search",
234 Self::InsiderTrades => "insider_trades",
235 Self::InstitutionalHoldings => "institutional_holdings",
236 Self::CongressionalTrades => "congressional_trades",
237 Self::FailsToDeliver => "fails_to_deliver",
238 Self::EconomicSeriesAsOf => "economic_series_as_of",
239 Self::EconomicSearch => "economic_search",
240 Self::EconomicCategories => "economic_categories",
241 Self::EconomicReleases => "economic_releases",
242 #[cfg(feature = "fiscaldata")]
243 Self::TreasuryAuctions => "treasury_auctions",
244 #[cfg(feature = "fiscaldata")]
245 Self::UpcomingAuctions => "upcoming_auctions",
246 Self::EtfProfile => "etf_profile",
247 Self::EarningsSurprises => "earnings_surprises",
248 Self::GradingHistory => "grading_history",
249 Self::ListingStatus => "listing_status",
250 Self::GroupedDaily => "grouped_daily",
251 Self::CryptoGroupedDaily => "crypto_grouped_daily",
252 Self::ForexGroupedDaily => "forex_grouped_daily",
253 #[cfg(feature = "crypto")]
254 Self::CryptoTrending => "crypto_trending",
255 #[cfg(feature = "crypto")]
256 Self::CryptoGlobal => "crypto_global",
257 }
258 }
259
260 pub fn capability(self) -> Capability {
262 match self {
263 Self::Quote | Self::QuotesBatch | Self::UnifiedSnapshot => Capability::QUOTE,
264 Self::Chart
265 | Self::ChartRange
266 | Self::Spark
267 | Self::GroupedDaily
268 | Self::CryptoGroupedDaily
269 | Self::ForexGroupedDaily => Capability::CHART,
270 Self::Financials
271 | Self::ShortInterest
272 | Self::ShortVolume
273 | Self::ShareFloat
274 | Self::PriceTargetConsensus
275 | Self::PriceTargetSummary
276 | Self::RatingConsensus
277 | Self::KeyMetricsTtm
278 | Self::RatiosTtm
279 | Self::EtfProfile
280 | Self::EarningsSurprises
281 | Self::GradingHistory
282 | Self::CompanyProfile => Capability::FUNDAMENTALS,
283 Self::News
284 | Self::Recommendations
285 | Self::Events
286 | Self::PressReleases
287 | Self::ExecutiveCompensation
288 | Self::EmployeeCount
289 | Self::EarningsTranscript => Capability::CORPORATE,
290 Self::Options => Capability::OPTIONS,
291 Self::CryptoQuote | Self::CryptoNews => Capability::CRYPTO,
292 #[cfg(feature = "defi")]
293 Self::ProtocolTvl | Self::ProtocolTvlHistory => Capability::CRYPTO,
294 #[cfg(feature = "crypto")]
295 Self::CryptoTrending | Self::CryptoGlobal => Capability::CRYPTO,
296 Self::EconomicSeries
297 | Self::EconomicSeriesAsOf
298 | Self::EconomicSearch
299 | Self::EconomicCategories
300 | Self::EconomicReleases => Capability::ECONOMIC,
301 #[cfg(feature = "fiscaldata")]
302 Self::TreasuryAuctions | Self::UpcomingAuctions => Capability::ECONOMIC,
303 Self::ForexQuote | Self::ForexNews => Capability::FOREX,
304 Self::IndicesQuote | Self::IndexConstituents | Self::IndexConstituentChanges => {
305 Capability::INDICES
306 }
307 Self::FuturesQuote => Capability::FUTURES,
308 #[cfg(feature = "cftc")]
309 Self::CommitmentsOfTraders => Capability::FUTURES,
310 Self::CommoditiesQuote => Capability::COMMODITIES,
311 Self::Filings
312 | Self::FilingSections
313 | Self::RiskFactors
314 | Self::FilingSearch
315 | Self::InsiderTrades
316 | Self::InstitutionalHoldings
317 | Self::CongressionalTrades
318 | Self::FailsToDeliver => Capability::FILINGS,
319 Self::SymbolSearch
320 | Self::SymbolDetails
321 | Self::Exchanges
322 | Self::Screener
323 | Self::ListingStatus => Capability::DISCOVERY,
324 Self::EarningsCalendar
325 | Self::IpoCalendar
326 | Self::DividendCalendar
327 | Self::SplitCalendar
328 | Self::EconomicCalendar
329 | Self::HolidayCalendar
330 | Self::MarketStatus => Capability::CALENDAR,
331 Self::SectorPerformance | Self::MarketMovers | Self::SectorPerformanceHistory => {
332 Capability::MARKET
333 }
334 }
335 }
336
337 pub(crate) fn not_supported(self, provider: Provider) -> FinanceError {
343 FinanceError::NotSupported {
344 provider,
345 operation: self,
346 candidates: self.capability().candidate_providers(),
347 }
348 }
349}
350
351impl std::fmt::Display for Operation {
352 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
353 f.write_str(self.as_str())
354 }
355}