BREAKING CHANGE(stocks): Unify stock provider API to discriminated IStockDataRequest and add company name/fullname enrichment

This commit is contained in:
2025-10-31 15:05:48 +00:00
parent 596be63554
commit ec3e4dde75
9 changed files with 266 additions and 211 deletions

View File

@@ -93,6 +93,8 @@ stockService.register(new MarketstackProvider('YOUR_API_KEY'), {
const apple = await stockService.getData({ type: 'current', ticker: 'AAPL' });
console.log(`Apple: $${apple.price} (${apple.changePercent.toFixed(2)}%)`);
console.log(`OHLCV: O=${apple.open} H=${apple.high} L=${apple.low} V=${apple.volume}`);
console.log(`Company: ${apple.companyName}`); // "Apple Inc"
console.log(`Full: ${apple.companyFullName}`); // "Apple Inc (NASDAQ:AAPL)"
// Get historical data (1 year of daily prices)
const history = await stockService.getData({
@@ -117,11 +119,25 @@ const vodNYSE = await stockService.getData({
exchange: 'XNYS' // New York Stock Exchange
});
// Batch current prices
// Batch current prices with company names
const prices = await stockService.getData({
type: 'batch',
tickers: ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA']
});
// Display with company names (automatically included - zero extra API calls!)
for (const stock of prices) {
console.log(`${stock.companyName}: $${stock.price}`);
// Output:
// Apple Inc: $271.40
// Microsoft Corporation: $525.76
// Alphabet Inc - Class A: $281.48
// Amazon.com Inc: $222.86
// Tesla Inc: $440.10
}
// Use companyFullName for richer context
console.log(prices[0].companyFullName); // "Apple Inc (NASDAQ:AAPL)"
```
### 🏢 German Business Data
@@ -164,6 +180,7 @@ await openData.buildInitialDb();
### 🎯 Stock Market Module (v2.1 Enhanced)
- **Company Names** - Automatic company name extraction with zero extra API calls (e.g., "Apple Inc (NASDAQ:AAPL)")
- **Historical Data** - Up to 15 years of daily EOD prices with automatic pagination
- **Exchange Filtering** - Query specific exchanges via MIC codes (XNAS, XLON, XNYS, etc.)
- **OHLCV Data** - Open, High, Low, Close, Volume for comprehensive analysis