BREAKING CHANGE(stocks): Unify stock provider API to discriminated IStockDataRequest and add company name/fullname enrichment
This commit is contained in:
@@ -2,15 +2,11 @@ import * as plugins from '../../plugins.js';
|
||||
import type { IStockProvider, IProviderConfig } from '../interfaces/provider.js';
|
||||
import type {
|
||||
IStockPrice,
|
||||
IStockQuoteRequest,
|
||||
IStockBatchQuoteRequest,
|
||||
IStockDataRequest,
|
||||
IStockCurrentRequest,
|
||||
IStockHistoricalRequest,
|
||||
IStockIntradayRequest,
|
||||
IStockBatchCurrentRequest,
|
||||
IPaginatedResponse,
|
||||
TSortOrder
|
||||
IStockBatchCurrentRequest
|
||||
} from '../interfaces/stockprice.js';
|
||||
|
||||
/**
|
||||
@@ -239,30 +235,6 @@ export class MarketstackProvider implements IStockProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy: Fetch latest EOD price for a single ticker
|
||||
* @deprecated Use fetchData with IStockDataRequest instead
|
||||
*/
|
||||
public async fetchPrice(request: IStockQuoteRequest): Promise<IStockPrice> {
|
||||
// Map legacy request to new format
|
||||
return this.fetchCurrentPrice({
|
||||
type: 'current',
|
||||
ticker: request.ticker
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy: Fetch latest EOD prices for multiple tickers
|
||||
* @deprecated Use fetchData with IStockDataRequest instead
|
||||
*/
|
||||
public async fetchPrices(request: IStockBatchQuoteRequest): Promise<IStockPrice[]> {
|
||||
// Map legacy request to new format
|
||||
return this.fetchBatchCurrentPrices({
|
||||
type: 'batch',
|
||||
tickers: request.tickers
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Marketstack API is available and accessible
|
||||
*/
|
||||
@@ -349,12 +321,49 @@ export class MarketstackProvider implements IStockProvider {
|
||||
low: data.low,
|
||||
adjusted: data.adj_close !== undefined, // If adj_close exists, price is adjusted
|
||||
dataType: dataType,
|
||||
fetchedAt: fetchedAt
|
||||
fetchedAt: fetchedAt,
|
||||
|
||||
// Company identification
|
||||
companyName: data.company_name || data.name || undefined,
|
||||
companyFullName: this.buildCompanyFullName(data)
|
||||
};
|
||||
|
||||
return stockPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build full company name with exchange and ticker information
|
||||
* Example: "Apple Inc (NASDAQ:AAPL)"
|
||||
*/
|
||||
private buildCompanyFullName(data: any): string | undefined {
|
||||
// Check if API already provides full name
|
||||
if (data.full_name || data.long_name) {
|
||||
return data.full_name || data.long_name;
|
||||
}
|
||||
|
||||
// Build from available data
|
||||
const companyName = data.company_name || data.name;
|
||||
const exchangeCode = data.exchange_code; // e.g., "NASDAQ"
|
||||
const symbol = data.symbol; // e.g., "AAPL"
|
||||
|
||||
if (!companyName) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// If we have exchange and symbol, build full name: "Apple Inc (NASDAQ:AAPL)"
|
||||
if (exchangeCode && symbol) {
|
||||
return `${companyName} (${exchangeCode}:${symbol})`;
|
||||
}
|
||||
|
||||
// If we only have symbol: "Apple Inc (AAPL)"
|
||||
if (symbol) {
|
||||
return `${companyName} (${symbol})`;
|
||||
}
|
||||
|
||||
// Otherwise just return company name
|
||||
return companyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format date to YYYY-MM-DD for API requests
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user