#[derive(Debug, Clone)]
pub struct FinnhubUrls {
pub rest_base: &'static str,
pub ws_url: &'static str,
}
impl FinnhubUrls {
pub const MAINNET: Self = Self {
rest_base: "https://finnhub.io/api/v1",
ws_url: "wss://ws.finnhub.io",
};
pub fn rest_url(&self) -> &str {
self.rest_base
}
pub fn websocket_url(&self) -> &str {
self.ws_url
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum FinnhubEndpoint {
Quote, StockCandles, TickData, BidAsk, StockSymbols,
CompanyProfile, BasicFinancials, FinancialStatements, CompanyPeers, CompanyExecutives,
EarningsCalendar, EpsEstimates, RevenueEstimates, PriceTarget, Recommendations, UpgradeDowngrade,
MarketNews, CompanyNews, NewsSentiment,
ForexExchanges, ForexSymbols, ForexCandles, ExchangeRates,
CryptoExchanges, CryptoSymbols, CryptoCandles,
InsiderTransactions, InsiderSentiment, CongressionalTrading, InstitutionalOwnership, PatentData, VisaApplications, UsaSpending, SupplyChain, SenateLobby,
EsgScores, ExecutiveCompensation, RevenueBreakdown,
TechnicalIndicators, PatternRecognition, SupportResistance, AggregateIndicators,
MarketStatus, MarketHoliday, EconomicCalendar,
SecFilings,
EtfHoldings, EtfProfile, EtfCountryExposure, EtfSectorExposure,
IpoCalendar, EarningsSurprise,
SocialSentiment,
CryptoProfile, }
impl FinnhubEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::Quote => "/quote",
Self::StockCandles => "/stock/candle",
Self::TickData => "/stock/tick",
Self::BidAsk => "/stock/bidask",
Self::StockSymbols => "/stock/symbol",
Self::CompanyProfile => "/stock/profile2",
Self::BasicFinancials => "/stock/metric",
Self::FinancialStatements => "/stock/financials",
Self::CompanyPeers => "/stock/peers",
Self::CompanyExecutives => "/stock/executive",
Self::EarningsCalendar => "/calendar/earnings",
Self::EpsEstimates => "/stock/eps-estimate",
Self::RevenueEstimates => "/stock/revenue-estimate",
Self::PriceTarget => "/stock/price-target",
Self::Recommendations => "/stock/recommendation",
Self::UpgradeDowngrade => "/stock/upgrade-downgrade",
Self::MarketNews => "/news",
Self::CompanyNews => "/company-news",
Self::NewsSentiment => "/news-sentiment",
Self::ForexExchanges => "/forex/exchange",
Self::ForexSymbols => "/forex/symbol",
Self::ForexCandles => "/forex/candle",
Self::ExchangeRates => "/forex/rates",
Self::CryptoExchanges => "/crypto/exchange",
Self::CryptoSymbols => "/crypto/symbol",
Self::CryptoCandles => "/crypto/candle",
Self::InsiderTransactions => "/stock/insider-transactions",
Self::InsiderSentiment => "/stock/insider-sentiment",
Self::CongressionalTrading => "/stock/congressional-trading",
Self::InstitutionalOwnership => "/stock/ownership",
Self::PatentData => "/stock/usa-patent",
Self::VisaApplications => "/stock/visa-application",
Self::UsaSpending => "/stock/usa-spending",
Self::SupplyChain => "/stock/supply-chain",
Self::SenateLobby => "/stock/lobbying",
Self::EsgScores => "/stock/esg",
Self::ExecutiveCompensation => "/stock/executive-compensation",
Self::RevenueBreakdown => "/stock/revenue-breakdown",
Self::TechnicalIndicators => "/indicator",
Self::PatternRecognition => "/scan/pattern",
Self::SupportResistance => "/scan/support-resistance",
Self::AggregateIndicators => "/scan/technical-indicator",
Self::MarketStatus => "/stock/market-status",
Self::MarketHoliday => "/stock/market-holiday",
Self::EconomicCalendar => "/calendar/economic",
Self::SecFilings => "/stock/filings",
Self::EtfHoldings => "/etf/holdings",
Self::EtfProfile => "/etf/profile",
Self::EtfCountryExposure => "/etf/country",
Self::EtfSectorExposure => "/etf/sector",
Self::IpoCalendar => "/calendar/ipo",
Self::EarningsSurprise => "/stock/earnings",
Self::SocialSentiment => "/stock/social-sentiment",
Self::CryptoProfile => "/crypto/profile",
}
}
pub fn _requires_auth(&self) -> bool {
true
}
pub fn _method(&self) -> &'static str {
"GET" }
}
pub fn format_symbol(symbol: &str) -> String {
symbol.to_uppercase()
}
pub fn map_resolution(interval: &str) -> &'static str {
match interval {
"1m" => "1",
"5m" => "5",
"15m" => "15",
"30m" => "30",
"1h" | "60m" => "60",
"1d" => "D",
"1w" => "W",
"1M" => "M",
_ => "D", }
}