feat(stocks/CoinGeckoProvider): Add CoinGecko provider for cryptocurrency prices, export and tests, and update documentation

This commit is contained in:
2025-11-02 16:34:24 +00:00
parent fdea1bb149
commit 47fd770e48
7 changed files with 1137 additions and 5 deletions

View File

@@ -87,6 +87,56 @@ const apple = await stockService.getData({ type: 'current', ticker: 'AAPL' });
console.log(`${apple.companyFullName}: $${apple.price}`);
```
### 🪙 Cryptocurrency Prices
Get real-time crypto prices with the CoinGecko provider:
```typescript
import { StockPriceService, CoinGeckoProvider } from '@fin.cx/opendata';
const stockService = new StockPriceService({ ttl: 30000 });
// Optional: Pass API key for higher rate limits
// const provider = new CoinGeckoProvider('your-api-key');
const provider = new CoinGeckoProvider();
stockService.register(provider);
// Fetch single crypto price (using ticker symbol)
const btc = await stockService.getPrice({ ticker: 'BTC' });
console.log(`${btc.ticker}: $${btc.price.toLocaleString()}`);
console.log(`24h Change: ${btc.changePercent.toFixed(2)}%`);
console.log(`24h Volume: $${btc.volume?.toLocaleString()}`);
// Or use CoinGecko ID directly
const ethereum = await stockService.getPrice({ ticker: 'ethereum' });
// Batch fetch multiple cryptos
const cryptos = await stockService.getPrices({
tickers: ['BTC', 'ETH', 'USDT', 'BNB', 'SOL']
});
cryptos.forEach(crypto => {
console.log(`${crypto.ticker}: $${crypto.price.toFixed(2)} (${crypto.changePercent >= 0 ? '+' : ''}${crypto.changePercent.toFixed(2)}%)`);
});
// Historical crypto prices
const history = await stockService.getData({
type: 'historical',
ticker: 'BTC',
from: new Date('2025-01-01'),
to: new Date('2025-01-31')
});
// Intraday crypto prices (hourly)
const intraday = await stockService.getData({
type: 'intraday',
ticker: 'ETH',
interval: '1hour',
limit: 24 // Last 24 hours
});
```
### 💰 Fundamentals-Only Data (Alternative)
If you only need fundamentals without prices:
@@ -149,9 +199,10 @@ const details = await openData.handelsregister.getSpecificCompany({
## Features
### 📊 Stock Market Module
### 📊 Stock & Crypto Market Module
- **Real-Time Prices** - Live and EOD stock prices from Yahoo Finance and Marketstack
- **Real-Time Prices** - Live and EOD prices from Yahoo Finance, Marketstack, and CoinGecko
- **Cryptocurrency Support** - 13M+ crypto tokens with 24/7 market data via CoinGecko
- **Company Names** - Automatic company name extraction (e.g., "Apple Inc (NASDAQ:AAPL)")
- **Historical Data** - Up to 15 years of daily EOD prices with pagination
- **OHLCV Data** - Open, High, Low, Close, Volume for technical analysis
@@ -622,6 +673,15 @@ interface IStockFundamentals {
- ✅ Company names included
- ⚠️ Rate limits may apply
**CoinGeckoProvider**
- ✅ Cryptocurrency prices (Bitcoin, Ethereum, 13M+ tokens)
- ✅ Current, historical, and intraday data
- ✅ 24/7 market data (crypto never closes)
- ✅ OHLCV data with market cap and volume
- ✅ Supports both ticker symbols (BTC, ETH) and CoinGecko IDs (bitcoin, ethereum)
- ✅ 240+ networks, 1600+ exchanges
- Optional API key (free tier: 30 requests/min, 10K/month)
**OpenData**
- `start()` - Initialize MongoDB connection
- `buildInitialDb()` - Import bulk data