@fin.cx/opendata 3.2.2 â 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/stocks/index.d.ts +1 -0
- package/dist_ts/stocks/index.js +2 -1
- package/dist_ts/stocks/providers/provider.coingecko.d.ts +101 -0
- package/dist_ts/stocks/providers/provider.coingecko.js +596 -0
- package/package.json +1 -1
- package/readme.hints.md +45 -1
- package/readme.md +62 -2
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/stocks/index.ts +2 -1
- package/ts/stocks/providers/provider.coingecko.ts +757 -0
package/readme.hints.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Stocks Module
|
|
4
4
|
|
|
5
5
|
### Overview
|
|
6
|
-
The stocks module provides real-time stock price data through various provider implementations. Currently supports Yahoo Finance with an extensible architecture for additional providers.
|
|
6
|
+
The stocks module provides real-time stock price data and cryptocurrency prices through various provider implementations. Currently supports Yahoo Finance, Marketstack, and CoinGecko with an extensible architecture for additional providers.
|
|
7
7
|
|
|
8
8
|
### Architecture
|
|
9
9
|
- **Provider Pattern**: Each stock data source implements the `IStockProvider` interface
|
|
@@ -31,11 +31,55 @@ const price = await stockService.getPrice({ ticker: 'AAPL' });
|
|
|
31
31
|
console.log(`${price.ticker}: $${price.price}`);
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
### CoinGecko Provider Notes
|
|
35
|
+
- Cryptocurrency price provider supporting 13M+ tokens
|
|
36
|
+
- Three main endpoints:
|
|
37
|
+
- `/simple/price` - Current prices with market data (batch supported)
|
|
38
|
+
- `/coins/{id}/market_chart` - Historical and intraday prices with OHLCV
|
|
39
|
+
- `/coins/list` - Complete coin list for ticker-to-ID mapping
|
|
40
|
+
- **Rate Limiting**:
|
|
41
|
+
- Free tier: 5-15 calls/minute (no registration)
|
|
42
|
+
- Demo plan: 30 calls/minute, 10,000/month (free with registration)
|
|
43
|
+
- Custom rate limiter tracks requests per minute
|
|
44
|
+
- **Ticker Resolution**:
|
|
45
|
+
- Accepts both ticker symbols (BTC, ETH) and CoinGecko IDs (bitcoin, ethereum)
|
|
46
|
+
- Lazy-loads coin list on first ticker resolution
|
|
47
|
+
- Caches coin mappings for 24 hours
|
|
48
|
+
- IDs with hyphens (wrapped-bitcoin) assumed to be CoinGecko IDs
|
|
49
|
+
- **24/7 Markets**: Crypto markets always return `marketState: 'REGULAR'`
|
|
50
|
+
- **Optional API Key**: Pass key to constructor for higher rate limits
|
|
51
|
+
- Demo plan: `x-cg-demo-api-key` header
|
|
52
|
+
- Paid plans: `x-cg-pro-api-key` header
|
|
53
|
+
- **Data Granularity**:
|
|
54
|
+
- Historical: Daily data for date ranges
|
|
55
|
+
- Intraday: Hourly data only (1-90 days based on `days` param)
|
|
56
|
+
- Current: Real-time prices with 24h change and volume
|
|
57
|
+
|
|
58
|
+
### Usage Example (Crypto)
|
|
59
|
+
```typescript
|
|
60
|
+
import { StockPriceService, CoinGeckoProvider } from '@fin.cx/opendata';
|
|
61
|
+
|
|
62
|
+
const stockService = new StockPriceService({ ttl: 30000 });
|
|
63
|
+
const coingeckoProvider = new CoinGeckoProvider(); // or new CoinGeckoProvider('api-key')
|
|
64
|
+
stockService.register(coingeckoProvider);
|
|
65
|
+
|
|
66
|
+
// Using ticker symbol
|
|
67
|
+
const btc = await stockService.getPrice({ ticker: 'BTC' });
|
|
68
|
+
console.log(`${btc.ticker}: $${btc.price}`);
|
|
69
|
+
|
|
70
|
+
// Using CoinGecko ID
|
|
71
|
+
const ethereum = await stockService.getPrice({ ticker: 'ethereum' });
|
|
72
|
+
|
|
73
|
+
// Batch fetch
|
|
74
|
+
const cryptos = await stockService.getPrices({ tickers: ['BTC', 'ETH', 'USDT'] });
|
|
75
|
+
```
|
|
76
|
+
|
|
34
77
|
### Testing
|
|
35
78
|
- Tests use real API calls (be mindful of rate limits)
|
|
36
79
|
- Mock invalid ticker 'INVALID_TICKER_XYZ' for error testing
|
|
37
80
|
- Clear cache between tests to ensure fresh data
|
|
38
81
|
- The spark endpoint may return fewer results than requested
|
|
82
|
+
- CoinGecko tests may take longer due to rate limiting (wait between requests)
|
|
39
83
|
|
|
40
84
|
### Future Providers
|
|
41
85
|
To add a new provider:
|
package/readme.md
CHANGED
|
@@ -87,6 +87,56 @@ const apple = await stockService.getData({ type: 'current', ticker: 'AAPL' });
|
|
|
87
87
|
console.log(`${apple.companyFullName}: $${apple.price}`);
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
### đĒ Cryptocurrency Prices
|
|
91
|
+
|
|
92
|
+
Get real-time crypto prices with the CoinGecko provider:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { StockPriceService, CoinGeckoProvider } from '@fin.cx/opendata';
|
|
96
|
+
|
|
97
|
+
const stockService = new StockPriceService({ ttl: 30000 });
|
|
98
|
+
|
|
99
|
+
// Optional: Pass API key for higher rate limits
|
|
100
|
+
// const provider = new CoinGeckoProvider('your-api-key');
|
|
101
|
+
const provider = new CoinGeckoProvider();
|
|
102
|
+
|
|
103
|
+
stockService.register(provider);
|
|
104
|
+
|
|
105
|
+
// Fetch single crypto price (using ticker symbol)
|
|
106
|
+
const btc = await stockService.getPrice({ ticker: 'BTC' });
|
|
107
|
+
console.log(`${btc.ticker}: $${btc.price.toLocaleString()}`);
|
|
108
|
+
console.log(`24h Change: ${btc.changePercent.toFixed(2)}%`);
|
|
109
|
+
console.log(`24h Volume: $${btc.volume?.toLocaleString()}`);
|
|
110
|
+
|
|
111
|
+
// Or use CoinGecko ID directly
|
|
112
|
+
const ethereum = await stockService.getPrice({ ticker: 'ethereum' });
|
|
113
|
+
|
|
114
|
+
// Batch fetch multiple cryptos
|
|
115
|
+
const cryptos = await stockService.getPrices({
|
|
116
|
+
tickers: ['BTC', 'ETH', 'USDT', 'BNB', 'SOL']
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
cryptos.forEach(crypto => {
|
|
120
|
+
console.log(`${crypto.ticker}: $${crypto.price.toFixed(2)} (${crypto.changePercent >= 0 ? '+' : ''}${crypto.changePercent.toFixed(2)}%)`);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Historical crypto prices
|
|
124
|
+
const history = await stockService.getData({
|
|
125
|
+
type: 'historical',
|
|
126
|
+
ticker: 'BTC',
|
|
127
|
+
from: new Date('2025-01-01'),
|
|
128
|
+
to: new Date('2025-01-31')
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Intraday crypto prices (hourly)
|
|
132
|
+
const intraday = await stockService.getData({
|
|
133
|
+
type: 'intraday',
|
|
134
|
+
ticker: 'ETH',
|
|
135
|
+
interval: '1hour',
|
|
136
|
+
limit: 24 // Last 24 hours
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
90
140
|
### đ° Fundamentals-Only Data (Alternative)
|
|
91
141
|
|
|
92
142
|
If you only need fundamentals without prices:
|
|
@@ -149,9 +199,10 @@ const details = await openData.handelsregister.getSpecificCompany({
|
|
|
149
199
|
|
|
150
200
|
## Features
|
|
151
201
|
|
|
152
|
-
### đ Stock Market Module
|
|
202
|
+
### đ Stock & Crypto Market Module
|
|
153
203
|
|
|
154
|
-
- **Real-Time Prices** - Live and EOD
|
|
204
|
+
- **Real-Time Prices** - Live and EOD prices from Yahoo Finance, Marketstack, and CoinGecko
|
|
205
|
+
- **Cryptocurrency Support** - 13M+ crypto tokens with 24/7 market data via CoinGecko
|
|
155
206
|
- **Company Names** - Automatic company name extraction (e.g., "Apple Inc (NASDAQ:AAPL)")
|
|
156
207
|
- **Historical Data** - Up to 15 years of daily EOD prices with pagination
|
|
157
208
|
- **OHLCV Data** - Open, High, Low, Close, Volume for technical analysis
|
|
@@ -622,6 +673,15 @@ interface IStockFundamentals {
|
|
|
622
673
|
- â
Company names included
|
|
623
674
|
- â ī¸ Rate limits may apply
|
|
624
675
|
|
|
676
|
+
**CoinGeckoProvider**
|
|
677
|
+
- â
Cryptocurrency prices (Bitcoin, Ethereum, 13M+ tokens)
|
|
678
|
+
- â
Current, historical, and intraday data
|
|
679
|
+
- â
24/7 market data (crypto never closes)
|
|
680
|
+
- â
OHLCV data with market cap and volume
|
|
681
|
+
- â
Supports both ticker symbols (BTC, ETH) and CoinGecko IDs (bitcoin, ethereum)
|
|
682
|
+
- â
240+ networks, 1600+ exchanges
|
|
683
|
+
- âšī¸ Optional API key (free tier: 30 requests/min, 10K/month)
|
|
684
|
+
|
|
625
685
|
**OpenData**
|
|
626
686
|
- `start()` - Initialize MongoDB connection
|
|
627
687
|
- `buildInitialDb()` - Import bulk data
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@fin.cx/opendata',
|
|
6
|
-
version: '3.
|
|
6
|
+
version: '3.3.0',
|
|
7
7
|
description: '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 stock market data from multiple providers.'
|
|
8
8
|
}
|
package/ts/stocks/index.ts
CHANGED
|
@@ -15,4 +15,5 @@ export * from './classes.baseproviderservice.js';
|
|
|
15
15
|
// Export providers
|
|
16
16
|
export * from './providers/provider.yahoo.js';
|
|
17
17
|
export * from './providers/provider.marketstack.js';
|
|
18
|
-
export * from './providers/provider.secedgar.js';
|
|
18
|
+
export * from './providers/provider.secedgar.js';
|
|
19
|
+
export * from './providers/provider.coingecko.js';
|