UNPKG

@fin.cx/opendata

Version:

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 stoc

122 lines (121 loc) 3.75 kB
import type { IStockProvider, IProviderConfig } from './interfaces/provider.js'; import type { IFundamentalsProvider, IFundamentalsProviderConfig, IStockFundamentals } from './interfaces/fundamentals.js'; import type { IStockPrice } from './interfaces/stockprice.js'; import type { IStockData, IStockDataServiceConfig, ICompleteStockDataRequest, ICompleteStockDataBatchRequest } from './interfaces/stockdata.js'; /** * Unified service for managing both stock prices and fundamentals * Provides automatic enrichment and convenient combined data access */ export declare class StockDataService { private priceProviders; private fundamentalsProviders; private priceCache; private fundamentalsCache; private logger; private config; constructor(config?: IStockDataServiceConfig); /** * Register a price provider */ registerPriceProvider(provider: IStockProvider, config?: IProviderConfig): void; /** * Register a fundamentals provider */ registerFundamentalsProvider(provider: IFundamentalsProvider, config?: IFundamentalsProviderConfig): void; /** * Unregister a price provider */ unregisterPriceProvider(providerName: string): void; /** * Unregister a fundamentals provider */ unregisterFundamentalsProvider(providerName: string): void; /** * Get all registered price providers */ getPriceProviders(): IStockProvider[]; /** * Get all registered fundamentals providers */ getFundamentalsProviders(): IFundamentalsProvider[]; /** * Get enabled price providers sorted by priority */ private getEnabledPriceProviders; /** * Get enabled fundamentals providers sorted by priority */ private getEnabledFundamentalsProviders; /** * Get current price for a single ticker */ getPrice(ticker: string): Promise<IStockPrice>; /** * Get current prices for multiple tickers */ getPrices(tickers: string[]): Promise<IStockPrice[]>; /** * Get fundamentals for a single ticker */ getFundamentals(ticker: string): Promise<IStockFundamentals>; /** * Get fundamentals for multiple tickers */ getBatchFundamentals(tickers: string[]): Promise<IStockFundamentals[]>; /** * ✨ Get complete stock data (price + fundamentals) with automatic enrichment */ getStockData(request: string | ICompleteStockDataRequest): Promise<IStockData>; /** * ✨ Get complete stock data for multiple tickers with automatic enrichment */ getBatchStockData(request: string[] | ICompleteStockDataBatchRequest): Promise<IStockData[]>; /** * Enrich fundamentals with calculated metrics using current price */ private enrichWithPrice; /** * Fetch with retry logic */ private fetchWithRetry; /** * Get from cache if not expired */ private getFromCache; /** * Add to cache with TTL */ private addToCache; /** * Check health of all providers (both price and fundamentals) */ checkProvidersHealth(): Promise<Map<string, boolean>>; /** * Get statistics for all providers */ getProviderStats(): Map<string, { type: 'price' | 'fundamentals'; successCount: number; errorCount: number; lastError?: string; lastErrorTime?: Date; }>; /** * Clear all caches */ clearCache(): void; /** * Get cache statistics */ getCacheStats(): { priceCache: { size: number; ttl: number; }; fundamentalsCache: { size: number; ttl: number; }; maxEntries: number; }; }