@fin.cx/opendata 1.5.3 → 1.6.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 +3 -3
- package/dist_ts/index.d.ts +1 -0
- package/dist_ts/index.js +2 -1
- package/dist_ts/plugins.d.ts +2 -1
- package/dist_ts/plugins.js +3 -2
- package/dist_ts/stocks/classes.stockservice.d.ts +32 -0
- package/dist_ts/stocks/classes.stockservice.js +221 -0
- package/dist_ts/stocks/index.d.ts +4 -0
- package/dist_ts/stocks/index.js +8 -0
- package/dist_ts/stocks/interfaces/provider.d.ts +30 -0
- package/dist_ts/stocks/interfaces/provider.js +2 -0
- package/dist_ts/stocks/interfaces/stockprice.d.ts +27 -0
- package/dist_ts/stocks/interfaces/stockprice.js +2 -0
- package/dist_ts/stocks/providers/provider.yahoo.d.ts +22 -0
- package/dist_ts/stocks/providers/provider.yahoo.js +139 -0
- package/package.json +11 -11
- package/readme.hints.md +45 -0
- package/readme.md +209 -560
- package/readme.plan.md +193 -0
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/index.ts +1 -0
- package/ts/plugins.ts +2 -0
- package/ts/stocks/classes.stockservice.ts +309 -0
- package/ts/stocks/index.ts +9 -0
- package/ts/stocks/interfaces/provider.ts +36 -0
- package/ts/stocks/interfaces/stockprice.ts +30 -0
- package/ts/stocks/providers/provider.yahoo.ts +159 -0
package/readme.hints.md
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# OpenData Project Hints
|
|
2
|
+
|
|
3
|
+
## Stocks Module
|
|
4
|
+
|
|
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.
|
|
7
|
+
|
|
8
|
+
### Architecture
|
|
9
|
+
- **Provider Pattern**: Each stock data source implements the `IStockProvider` interface
|
|
10
|
+
- **Service Registry**: `StockPriceService` manages providers with priority-based selection
|
|
11
|
+
- **Caching**: Built-in cache with configurable TTL to reduce API calls
|
|
12
|
+
- **Fallback Logic**: Automatic failover between providers if one fails
|
|
13
|
+
|
|
14
|
+
### Yahoo Finance Provider Notes
|
|
15
|
+
- Uses public API endpoints (no authentication required)
|
|
16
|
+
- Two main endpoints:
|
|
17
|
+
- `/v8/finance/chart/{ticker}` - Single ticker with full data
|
|
18
|
+
- `/v8/finance/spark?symbols={tickers}` - Multiple tickers with basic data
|
|
19
|
+
- Response data is in `response.body` when using smartrequest
|
|
20
|
+
- Requires User-Agent header to avoid rate limiting
|
|
21
|
+
|
|
22
|
+
### Usage Example
|
|
23
|
+
```typescript
|
|
24
|
+
import { StockPriceService, YahooFinanceProvider } from '@fin.cx/opendata';
|
|
25
|
+
|
|
26
|
+
const stockService = new StockPriceService({ ttl: 60000 });
|
|
27
|
+
const yahooProvider = new YahooFinanceProvider();
|
|
28
|
+
stockService.register(yahooProvider);
|
|
29
|
+
|
|
30
|
+
const price = await stockService.getPrice({ ticker: 'AAPL' });
|
|
31
|
+
console.log(`${price.ticker}: $${price.price}`);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Testing
|
|
35
|
+
- Tests use real API calls (be mindful of rate limits)
|
|
36
|
+
- Mock invalid ticker 'INVALID_TICKER_XYZ' for error testing
|
|
37
|
+
- Clear cache between tests to ensure fresh data
|
|
38
|
+
- The spark endpoint may return fewer results than requested
|
|
39
|
+
|
|
40
|
+
### Future Providers
|
|
41
|
+
To add a new provider:
|
|
42
|
+
1. Create `ts/stocks/providers/provider.{name}.ts`
|
|
43
|
+
2. Implement the `IStockProvider` interface
|
|
44
|
+
3. Register with `StockPriceService`
|
|
45
|
+
4. No changes needed to existing code
|