UNPKG

@fin.cx/opendata

Version:

A comprehensive TypeScript library for accessing business data and real-time financial information. Features include German company data management with MongoDB integration, JSONL bulk processing, automated Handelsregister interactions, and real-time stoc

102 lines (101 loc) 3.13 kB
import type { IStockProvider, IProviderConfig } from '../interfaces/provider.js'; import type { IStockPrice, IStockDataRequest } from '../interfaces/stockprice.js'; /** * CoinGecko Crypto Price Provider * * Documentation: https://docs.coingecko.com/v3.0.1/reference/endpoint-overview * * Features: * - Current crypto prices (single and batch) * - Historical price data with OHLCV * - 13M+ tokens, 240+ networks, 1600+ exchanges * - Accepts both ticker symbols (BTC, ETH) and CoinGecko IDs (bitcoin, ethereum) * - 24/7 market data (crypto never closes) * * Rate Limits: * - Free tier (no key): 5-15 requests/minute * - Demo plan (free with registration): ~30 requests/minute, 10,000/month * - Paid plans: Higher limits * * API Authentication: * - Optional API key for Demo/paid plans * - Header: x-cg-demo-api-key (Demo) or x-cg-pro-api-key (paid) */ export declare class CoinGeckoProvider implements IStockProvider { private config?; name: string; priority: number; readonly requiresAuth = false; readonly rateLimit: { requestsPerMinute: number; requestsPerDay: number; }; private logger; private baseUrl; private apiKey?; private rateLimiter; private coinMapCache; private coinListLoadedAt; private readonly coinListCacheTTL; private readonly priorityTickerMap; constructor(apiKey?: string, config?: IProviderConfig | undefined); /** * Unified data fetching method supporting all request types */ fetchData(request: IStockDataRequest): Promise<IStockPrice | IStockPrice[]>; /** * Fetch current price for a single crypto */ private fetchCurrentPrice; /** * Fetch batch current prices for multiple cryptos */ private fetchBatchCurrentPrices; /** * Fetch historical prices with OHLCV data */ private fetchHistoricalPrices; /** * Fetch intraday prices with hourly intervals */ private fetchIntradayPrices; /** * Check if CoinGecko API is available */ isAvailable(): Promise<boolean>; /** * Check if a market/network is supported * CoinGecko supports 240+ networks */ supportsMarket(market: string): boolean; /** * Check if a ticker format is supported * Supports both ticker symbols (BTC) and CoinGecko IDs (bitcoin) */ supportsTicker(ticker: string): boolean; /** * Resolve ticker symbol or CoinGecko ID to canonical CoinGecko ID * Supports both formats: "BTC" -> "bitcoin", "bitcoin" -> "bitcoin" */ private resolveCoinId; /** * Load complete coin list from CoinGecko API */ private loadCoinList; /** * Map CoinGecko simple/price response to IStockPrice */ private mapToStockPrice; /** * Build HTTP headers with optional API key */ private buildHeaders; /** * Check if response indicates a rate limit error (429) */ private isRateLimitError; /** * Wrapper for fetch operations with automatic rate limit retry and exponential backoff */ private fetchWithRateLimitRetry; }