/* * ============================================================================= * VibeQuant (vquant) — AI-Powered Financial Intelligence Platform * ----------------------------------------------------------------------------- * File: server/services/fmpService.ts * * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * Website: https://www.spboucher.ai * Demo: https://www.vquant.ai * License: MIT (see LICENSE) * * Copyright © 2026 Simon-Pierre Boucher. All rights reserved. * ============================================================================= */ import axios from 'axios'; const FMP_API_KEY = process.env.FMP_API_KEY; const FMP_BASE_URL = 'https://financialmodelingprep.com/stable'; const FMP_V4_URL = 'https://financialmodelingprep.com/stable'; interface FMPResponse { data: T; error?: string; } export interface CompanyProfile { symbol: string; companyName: string; currency: string; cik: string; isin: string; cusip: string; exchange: string; exchangeShortName: string; industry: string; website: string; description: string; ceo: string; sector: string; country: string; fullTimeEmployees: string; phone: string; address: string; city: string; state: string; zip: string; dcfDiff: number; dcf: number; image: string; ipoDate: string; defaultImage: boolean; isEtf: boolean; isActivelyTrading: boolean; isAdr: boolean; isFund: boolean; price: number; beta: number; volAvg: number; mktCap: number; lastDiv: number; range: string; changes: number; } export interface IncomeStatement { date: string; symbol: string; reportedCurrency: string; cik: string; fillingDate: string; acceptedDate: string; calendarYear: string; period: string; revenue: number; costOfRevenue: number; grossProfit: number; grossProfitRatio: number; researchAndDevelopmentExpenses: number; generalAndAdministrativeExpenses: number; sellingAndMarketingExpenses: number; sellingGeneralAndAdministrativeExpenses: number; otherExpenses: number; operatingExpenses: number; costAndExpenses: number; interestIncome: number; interestExpense: number; depreciationAndAmortization: number; ebitda: number; ebitdaratio: number; operatingIncome: number; operatingIncomeRatio: number; totalOtherIncomeExpensesNet: number; incomeBeforeTax: number; incomeBeforeTaxRatio: number; incomeTaxExpense: number; netIncome: number; netIncomeRatio: number; eps: number; epsdiluted: number; weightedAverageShsOut: number; weightedAverageShsOutDil: number; link: string; finalLink: string; } export interface BalanceSheet { date: string; symbol: string; reportedCurrency: string; cik: string; fillingDate: string; acceptedDate: string; calendarYear: string; period: string; cashAndCashEquivalents: number; shortTermInvestments: number; cashAndShortTermInvestments: number; netReceivables: number; inventory: number; otherCurrentAssets: number; totalCurrentAssets: number; propertyPlantEquipmentNet: number; goodwill: number; intangibleAssets: number; goodwillAndIntangibleAssets: number; longTermInvestments: number; taxAssets: number; otherNonCurrentAssets: number; totalNonCurrentAssets: number; otherAssets: number; totalAssets: number; accountPayables: number; shortTermDebt: number; taxPayables: number; deferredRevenue: number; otherCurrentLiabilities: number; totalCurrentLiabilities: number; longTermDebt: number; deferredRevenueNonCurrent: number; deferredTaxLiabilitiesNonCurrent: number; otherNonCurrentLiabilities: number; totalNonCurrentLiabilities: number; otherLiabilities: number; capitalLeaseObligations: number; totalLiabilities: number; preferredStock: number; commonStock: number; retainedEarnings: number; accumulatedOtherComprehensiveIncomeLoss: number; othertotalStockholdersEquity: number; totalStockholdersEquity: number; totalEquity: number; totalLiabilitiesAndStockholdersEquity: number; minorityInterest: number; totalLiabilitiesAndTotalEquity: number; totalInvestments: number; totalDebt: number; netDebt: number; link: string; finalLink: string; } export interface CashFlowStatement { date: string; symbol: string; reportedCurrency: string; cik: string; fillingDate: string; acceptedDate: string; calendarYear: string; period: string; netIncome: number; depreciationAndAmortization: number; deferredIncomeTax: number; stockBasedCompensation: number; changeInWorkingCapital: number; accountsReceivables: number; inventory: number; accountsPayables: number; otherWorkingCapital: number; otherNonCashItems: number; netCashProvidedByOperatingActivities: number; investmentsInPropertyPlantAndEquipment: number; acquisitionsNet: number; purchasesOfInvestments: number; salesMaturitiesOfInvestments: number; otherInvestingActivites: number; netCashUsedForInvestingActivites: number; debtRepayment: number; commonStockIssued: number; commonStockRepurchased: number; dividendsPaid: number; otherFinancingActivites: number; netCashUsedProvidedByFinancingActivities: number; effectOfForexChangesOnCash: number; netChangeInCash: number; cashAtEndOfPeriod: number; cashAtBeginningOfPeriod: number; operatingCashFlow: number; capitalExpenditure: number; freeCashFlow: number; link: string; finalLink: string; } export interface KeyMetrics { symbol: string; date: string; calendarYear: string; period: string; revenuePerShare: number; netIncomePerShare: number; operatingCashFlowPerShare: number; freeCashFlowPerShare: number; cashPerShare: number; bookValuePerShare: number; tangibleBookValuePerShare: number; shareholdersEquityPerShare: number; interestDebtPerShare: number; marketCap: number; enterpriseValue: number; peRatio: number; priceToSalesRatio: number; pocfratio: number; pfcfRatio: number; pbRatio: number; ptbRatio: number; evToSales: number; enterpriseValueOverEBITDA: number; evToOperatingCashFlow: number; evToFreeCashFlow: number; earningsYield: number; freeCashFlowYield: number; debtToEquity: number; debtToAssets: number; netDebtToEBITDA: number; currentRatio: number; interestCoverage: number; incomeQuality: number; dividendYield: number; payoutRatio: number; salesGeneralAndAdministrativeToRevenue: number; researchAndDdevelopementToRevenue: number; intangiblesToTotalAssets: number; capexToOperatingCashFlow: number; capexToRevenue: number; capexToDepreciation: number; stockBasedCompensationToRevenue: number; grahamNumber: number; roic: number; returnOnTangibleAssets: number; grahamNetNet: number; workingCapital: number; tangibleAssetValue: number; netCurrentAssetValue: number; investedCapital: number; averageReceivables: number; averagePayables: number; averageInventory: number; daysSalesOutstanding: number; daysPayablesOutstanding: number; daysOfInventoryOnHand: number; receivablesTurnover: number; payablesTurnover: number; inventoryTurnover: number; roe: number; capexPerShare: number; } export interface FinancialRatios { symbol: string; date: string; calendarYear: string; period: string; currentRatio: number; quickRatio: number; cashRatio: number; daysOfSalesOutstanding: number; daysOfInventoryOutstanding: number; operatingCycle: number; daysOfPayablesOutstanding: number; cashConversionCycle: number; grossProfitMargin: number; operatingProfitMargin: number; pretaxProfitMargin: number; netProfitMargin: number; effectiveTaxRate: number; returnOnAssets: number; returnOnEquity: number; returnOnCapitalEmployed: number; netIncomePerEBT: number; ebtPerEbit: number; ebitPerRevenue: number; debtRatio: number; debtEquityRatio: number; longTermDebtToCapitalization: number; totalDebtToCapitalization: number; interestCoverage: number; cashFlowToDebtRatio: number; companyEquityMultiplier: number; receivablesTurnover: number; payablesTurnover: number; inventoryTurnover: number; fixedAssetTurnover: number; assetTurnover: number; operatingCashFlowPerShare: number; freeCashFlowPerShare: number; cashPerShare: number; payoutRatio: number; operatingCashFlowSalesRatio: number; freeCashFlowOperatingCashFlowRatio: number; cashFlowCoverageRatios: number; shortTermCoverageRatios: number; capitalExpenditureCoverageRatio: number; dividendPaidAndCapexCoverageRatio: number; dividendPayoutRatio: number; priceBookValueRatio: number; priceToBookRatio: number; priceToSalesRatio: number; priceEarningsRatio: number; priceToFreeCashFlowsRatio: number; priceToOperatingCashFlowsRatio: number; priceCashFlowRatio: number; priceEarningsToGrowthRatio: number; priceSalesRatio: number; dividendYield: number; enterpriseValueMultiple: number; priceFairValue: number; } export interface StockQuote { symbol: string; name: string; price: number; changesPercentage: number; change: number; dayLow: number; dayHigh: number; yearHigh: number; yearLow: number; marketCap: number; priceAvg50: number; priceAvg200: number; exchange: string; volume: number; avgVolume: number; open: number; previousClose: number; eps: number; pe: number; earningsAnnouncement: string; sharesOutstanding: number; timestamp: number; } export interface HistoricalPrice { date: string; open: number; high: number; low: number; close: number; adjClose: number; volume: number; unadjustedVolume: number; change: number; changePercent: number; vwap: number; label: string; changeOverTime: number; } export interface FinancialNews { symbol: string; publishedDate: string; title: string; image: string; site: string; text: string; url: string; } async function fmpRequest(endpoint: string, params: Record = {}): Promise { if (!FMP_API_KEY) { throw new Error('FMP_API_KEY not configured'); } try { const response = await axios.get(`${FMP_BASE_URL}${endpoint}`, { params: { ...params, apikey: FMP_API_KEY, }, timeout: 15000, }); return response.data; } catch (error) { console.error(`FMP API error for ${endpoint}:`, error); throw new Error(`Failed to fetch from FMP: ${(error as Error).message}`); } } async function fmpV4Request(endpoint: string, params: Record = {}): Promise { if (!FMP_API_KEY) { throw new Error('FMP_API_KEY not configured'); } try { const response = await axios.get(`${FMP_V4_URL}${endpoint}`, { params: { ...params, apikey: FMP_API_KEY, }, timeout: 15000, }); return response.data; } catch (error) { console.error(`FMP API error for ${endpoint}:`, error); throw new Error(`Failed to fetch from FMP: ${(error as Error).message}`); } } export async function getCompanyProfile(symbol: string): Promise { return fmpRequest('/profile', { symbol }); } export async function getIncomeStatement(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/income-statement', { symbol, period, limit }); } export async function getBalanceSheet(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/balance-sheet-statement', { symbol, period, limit }); } export async function getCashFlowStatement(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/cash-flow-statement', { symbol, period, limit }); } export async function getKeyMetrics(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/key-metrics', { symbol, period, limit }); } export async function getFinancialRatios(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/ratios', { symbol, period, limit }); } export async function getStockQuote(symbol: string): Promise { return fmpRequest('/quote', { symbol }); } export async function getHistoricalPrice(symbol: string, from?: string, to?: string): Promise<{ symbol: string; historical: HistoricalPrice[] }> { const params: Record = {}; if (from) params.from = from; // If 'to' is not provided, default to today's date to ensure current data if (to) { params.to = to; } else { params.to = new Date().toISOString().split('T')[0]; // YYYY-MM-DD format } params.symbol = symbol; const data = await fmpRequest('/historical-price-eod/full', params); // Stable API returns flat array; wrap to match legacy { symbol, historical } format let historical = Array.isArray(data) ? data : (data as any).historical || []; // Limit to 504 most recent data points (2 years) for Monte Carlo simulations // This provides enough data for robust statistical analysis while staying within reasonable context limits // The tool result truncation in routes.ts will further limit if needed if (historical.length > 504) { historical = historical.slice(0, 504); } return { symbol, historical }; } export async function getFinancialNews(symbol?: string, limit: number = 5): Promise { // Limit to 5 articles to avoid context overflow const actualLimit = Math.min(limit, 5); if (symbol) { return fmpRequest('/news/stock', { symbols: symbol, limit: actualLimit }); } return fmpRequest('/news/stock', { limit: actualLimit }); } export async function searchCompanies(query: string, limit: number = 10): Promise> { return fmpRequest('/search-symbol', { query, limit }); } export async function getStockPeers(symbol: string): Promise { return fmpRequest('/stock-peers', { symbol }); } export interface TechnicalIndicator { date: string; [key: string]: number | string; } export interface EconomicCalendar { event: string; date: string; country: string; actual: number | null; previous: number | null; change: number | null; changePercentage: number | null; estimate: number | null; impact: string; } export interface TreasuryRate { date: string; month1: number; month2: number; month3: number; month6: number; year1: number; year2: number; year3: number; year5: number; year7: number; year10: number; year20: number; year30: number; } export interface EconomicIndicator { date: string; value: number; } export interface InsiderTrade { symbol: string; filingDate: string; transactionDate: string; reportingName: string; typeOfOwner: string; acquistionOrDisposition: string; formType: string; securitiesOwned: number; securitiesTransacted: number; price: number; securityName: string; link: string; } export interface InsiderTradeStatistics { symbol: string; cik: string; name: string; trades: number; buyTransactions: number; sellTransactions: number; totalBought: number; totalSold: number; avgBuyPrice: number; avgSellPrice: number; } export interface EarningsCalendar { date: string; symbol: string; eps: number | null; epsEstimated: number | null; time: string; revenue: number | null; revenueEstimated: number | null; fiscalDateEnding: string; updatedFromDate: string; } export interface EarningsSurprise { date: string; symbol: string; actualEarningResult: number; estimatedEarning: number; } export interface AnalystEstimate { date: string; symbol: string; estimatedRevenueLow: number; estimatedRevenueHigh: number; estimatedRevenueAvg: number; estimatedEbitdaLow: number; estimatedEbitdaHigh: number; estimatedEbitdaAvg: number; estimatedEbitLow: number; estimatedEbitHigh: number; estimatedEbitAvg: number; estimatedNetIncomeLow: number; estimatedNetIncomeHigh: number; estimatedNetIncomeAvg: number; estimatedSgaExpenseLow: number; estimatedSgaExpenseHigh: number; estimatedSgaExpenseAvg: number; estimatedEpsAvg: number; estimatedEpsHigh: number; estimatedEpsLow: number; numberAnalystEstimatedRevenue: number; numberAnalystsEstimatedEps: number; } export interface ForexQuote { ticker: string; bid: number; ask: number; open: number; low: number; high: number; changes: number; date: string; } export interface CommodityQuote { symbol: string; name: string; price: number; changesPercentage: number; change: number; dayLow: number; dayHigh: number; yearHigh: number; yearLow: number; marketCap: number | null; priceAvg50: number; priceAvg200: number; volume: number; avgVolume: number; exchange: string; open: number; previousClose: number; timestamp: number; } export interface COTReport { date: string; symbol: string; name: string; exchange: string; currentLongMarketSituation: number; currentShortMarketSituation: number; marketSituation: string; netPosition: number; percentOfOI_Long: number; percentOfOI_Short: number; } export interface PressRelease { symbol: string; date: string; title: string; text: string; } export interface Dividend { date: string; label: string; adjDividend: number; dividend: number; recordDate: string; paymentDate: string; declarationDate: string; } export interface StockSplit { date: string; label: string; symbol: string; numerator: number; denominator: number; } export interface IPOCalendar { date: string; company: string; symbol: string; exchange: string; actions: string; shares: number | null; priceRange: string; marketCap: number | null; } export async function getRSI(symbol: string, period: number = 14, timePeriod: string = '1day'): Promise { const result = await fmpRequest('/technical-indicators/rsi', { symbol, timeframe: timePeriod, periodLength: period }); return result.slice(0, 10); } export async function getMACD(symbol: string, timePeriod: string = '1day'): Promise { // MACD not available in FMP stable API — compute from historical prices const { historical } = await getHistoricalPrice(symbol); if (!historical || historical.length < 35) return []; const closes = historical.map(h => h.close).reverse(); // oldest first const ema12 = computeEMA(closes, 12); const ema26 = computeEMA(closes, 26); const macdLine: number[] = []; for (let i = 0; i < ema26.length; i++) { macdLine.push(ema12[i + (ema12.length - ema26.length)] - ema26[i]); } const signal = computeEMA(macdLine, 9); const results: TechnicalIndicator[] = []; const offset = macdLine.length - signal.length; const dates = historical.slice().reverse(); const dateOffset = dates.length - signal.length - (closes.length - ema12.length) - (ema12.length - ema26.length); for (let i = signal.length - 1; i >= Math.max(0, signal.length - 10); i--) { const idx = dates.length - (signal.length - i); const d = dates[idx]; if (!d) continue; results.push({ date: d.date, open: d.open, high: d.high, low: d.low, close: d.close, volume: d.volume, macd: macdLine[i + offset], macdSignal: signal[i], macdHistogram: macdLine[i + offset] - signal[i], } as any); } return results; } export async function getEMA(symbol: string, period: number = 50, timePeriod: string = '1day'): Promise { const result = await fmpRequest('/technical-indicators/ema', { symbol, timeframe: timePeriod, periodLength: period }); return result.slice(0, 10); } export async function getSMA(symbol: string, period: number = 50, timePeriod: string = '1day'): Promise { const result = await fmpRequest('/technical-indicators/sma', { symbol, timeframe: timePeriod, periodLength: period }); return result.slice(0, 10); } export async function getADX(symbol: string, period: number = 14, timePeriod: string = '1day'): Promise { const result = await fmpRequest('/technical-indicators/adx', { symbol, timeframe: timePeriod, periodLength: period }); return result.slice(0, 10); } export async function getWilliamsR(symbol: string, period: number = 14, timePeriod: string = '1day'): Promise { const result = await fmpRequest('/technical-indicators/williams', { symbol, timeframe: timePeriod, periodLength: period }); return result.slice(0, 10); } export async function getCCI(symbol: string, period: number = 20, timePeriod: string = '1day'): Promise { // CCI not available in FMP stable API — compute from historical prices const { historical } = await getHistoricalPrice(symbol); if (!historical || historical.length < period + 10) return []; const data = historical.slice().reverse(); // oldest first const results: TechnicalIndicator[] = []; for (let i = data.length - 1; i >= Math.max(period - 1, data.length - 10); i--) { const window = data.slice(i - period + 1, i + 1); const tps = window.map(d => (d.high + d.low + d.close) / 3); const meanTP = tps.reduce((a, b) => a + b, 0) / tps.length; const meanDev = tps.reduce((a, tp) => a + Math.abs(tp - meanTP), 0) / tps.length; const cci = meanDev === 0 ? 0 : (tps[tps.length - 1] - meanTP) / (0.015 * meanDev); const d = data[i]; results.push({ date: d.date, open: d.open, high: d.high, low: d.low, close: d.close, volume: d.volume, cci, } as any); } return results; } export async function getStochasticOscillator(symbol: string, period: number = 14, timePeriod: string = '1day'): Promise { // Stochastic not available in FMP stable API — compute from historical prices const { historical } = await getHistoricalPrice(symbol); if (!historical || historical.length < period + 10) return []; const data = historical.slice().reverse(); // oldest first // Compute %K values const kValues: number[] = []; for (let i = period - 1; i < data.length; i++) { const window = data.slice(i - period + 1, i + 1); const lowestLow = Math.min(...window.map(d => d.low)); const highestHigh = Math.max(...window.map(d => d.high)); const range = highestHigh - lowestLow; const k = range === 0 ? 50 : ((data[i].close - lowestLow) / range) * 100; kValues.push(k); } // %D = 3-period SMA of %K const results: TechnicalIndicator[] = []; for (let i = kValues.length - 1; i >= Math.max(2, kValues.length - 10); i--) { const d3 = (kValues[i] + kValues[i - 1] + kValues[i - 2]) / 3; const dataIdx = i + (period - 1); const d = data[dataIdx]; results.push({ date: d.date, open: d.open, high: d.high, low: d.low, close: d.close, volume: d.volume, stochK: kValues[i], stochD: d3, } as any); } return results; } // Helper: compute EMA from an array of values (oldest first) function computeEMA(values: number[], period: number): number[] { if (values.length < period) return []; const k = 2 / (period + 1); let ema = values.slice(0, period).reduce((a, b) => a + b, 0) / period; const result = [ema]; for (let i = period; i < values.length; i++) { ema = values[i] * k + ema * (1 - k); result.push(ema); } return result; } export async function getEconomicCalendar(from?: string, to?: string): Promise { // If no dates specified, get last 30 days + next 30 days if (!from && !to) { const now = new Date(); const past30Days = new Date(now); past30Days.setDate(past30Days.getDate() - 30); const future30Days = new Date(now); future30Days.setDate(future30Days.getDate() + 30); from = past30Days.toISOString().split('T')[0]; to = future30Days.toISOString().split('T')[0]; } const params: Record = {}; if (from) params.from = from; if (to) params.to = to; const result = await fmpRequest('/economic-calendar', params); // Filter to high/medium impact events and limit to avoid context overflow const filtered = result.filter(event => event.impact === 'High' || event.impact === 'Medium'); // Sort by date (most recent first) and limit to 15 total events return filtered .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 15); } export async function getTreasuryRates(from?: string, to?: string): Promise { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; const result = await fmpRequest('/treasury', params); // Limit to most recent 15 days to avoid context overflow return result.slice(0, 15); } export async function getEconomicIndicator(indicator: string, from?: string, to?: string): Promise { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; const result = await fmpRequest('/economic-indicators', { name: indicator, ...params }); // Limit to most recent 15 data points to avoid context overflow return result.slice(0, 15); } export async function getInsiderTrading(symbol?: string, limit: number = 20): Promise { // Limit to 20 trades to avoid context overflow const actualLimit = Math.min(limit, 20); const params: Record = { limit: actualLimit }; if (symbol) params.symbol = symbol; return fmpRequest('/insider-trading/search', params); } export async function getInsiderTradeStatistics(symbol: string): Promise { return fmpRequest('/insider-trade-statistics', { symbol }); } export async function getEarningsCalendar(from?: string, to?: string): Promise { // If no dates specified, get last 30 days + next 30 days if (!from && !to) { const now = new Date(); const past30Days = new Date(now); past30Days.setDate(past30Days.getDate() - 30); const future30Days = new Date(now); future30Days.setDate(future30Days.getDate() + 30); from = past30Days.toISOString().split('T')[0]; to = future30Days.toISOString().split('T')[0]; } const params: Record = {}; if (from) params.from = from; if (to) params.to = to; const result = await fmpRequest('/earnings-calendar', params); // Sort by date (most recent first) and limit to avoid context overflow return result .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 15); } export async function getEarningsSurprises(symbol: string): Promise { return fmpRequest('/earnings-surprises', { symbol }); } export async function getAnalystEstimates(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/analyst-estimates', { symbol, period, limit }); } export async function getForexQuote(pair: string): Promise { return fmpRequest('/fx', { symbol: pair }); } export async function getForexList(): Promise> { return fmpRequest('/forex-currency-pairs'); } export async function getCommodityQuotes(): Promise { return fmpRequest('/batch-commodity-quote'); } export async function getCOTReport(symbol: string): Promise { return fmpRequest('/commitment-of-traders-report', { symbol }); } export async function getCOTAnalysis(symbol: string): Promise { return fmpRequest('/commitment-of-traders-report-analysis', { symbol }); } export async function getPressReleases(symbol: string, limit: number = 20): Promise { return fmpRequest('/press-releases', { symbol, limit }); } export async function getDividendHistory(symbol: string): Promise { const data = await fmpRequest('/dividends', { symbol }); // Stable API returns flat array const dividends = Array.isArray(data) ? data : (data as any).historical || []; // Limit to last 10 dividends to avoid context overflow return dividends.slice(0, 10); } export async function getStockSplitHistory(symbol: string): Promise { const data = await fmpRequest('/splits', { symbol }); // Stable API returns flat array const splits = Array.isArray(data) ? data : (data as any).historical || []; return splits; } export async function getIPOCalendar(from?: string, to?: string): Promise { // If no dates specified, get last 30 days + next 90 days (IPOs are announced in advance) if (!from && !to) { const now = new Date(); const past30Days = new Date(now); past30Days.setDate(past30Days.getDate() - 30); const future90Days = new Date(now); future90Days.setDate(future90Days.getDate() + 90); from = past30Days.toISOString().split('T')[0]; to = future90Days.toISOString().split('T')[0]; } const params: Record = {}; if (from) params.from = from; if (to) params.to = to; const result = await fmpRequest('/ipo-calendar', params); // Sort by date (most recent first) and limit to avoid context overflow return result .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 20); } // Intraday Price Data export interface IntradayPrice { date: string; open: number; high: number; low: number; close: number; volume: number; } export interface IntradayPriceResponse { symbol: string; interval: string; data: IntradayPrice[]; } export async function getIntradayPrice(symbol: string, interval: string = '15min'): Promise { const result = await fmpRequest(`/historical-chart/${interval}`, { symbol }); // Limit to last 15 data points to avoid context overflow const limitedData = result.slice(0, 15); return { symbol, interval, data: limitedData }; } // Price Target Data export interface PriceTarget { symbol: string; publishedDate: string; newsURL: string; newsTitle: string; analystName: string; analystCompany: string; priceTarget: number; adjPriceTarget: number; priceWhenPosted: number; newsPublisher: string; newsBaseURL: string; } export async function getPriceTarget(symbol: string): Promise { return fmpRequest('/price-target', { symbol }); } export interface PriceTargetSummary { symbol: string; lastMonth: number; lastMonthAvgPriceTarget: number; lastQuarter: number; lastQuarterAvgPriceTarget: number; lastYear: number; lastYearAvgPriceTarget: number; allTime: number; allTimeAvgPriceTarget: number; publishers: string[]; } export async function getPriceTargetSummary(symbol: string): Promise { return fmpRequest('/price-target-summary', { symbol }); } // Upgrades and Downgrades export interface UpgradeDowngrade { symbol: string; publishedDate: string; newsURL: string; newsTitle: string; newsPublisher: string; newsBaseURL: string; action: string; analystName: string; analystCompany: string; priceWhenPosted: number; priceTarget: number; newGrade: string; previousGrade: string; gradingCompany: string; } export async function getUpgradesDowngrades(symbol: string): Promise { return fmpRequest('/grades', { symbol }); } // Institutional Holders export interface InstitutionalHolder { holder: string; shares: number; dateReported: string; change: number; symbol: string; } export async function getInstitutionalHolders(symbol: string): Promise { return fmpRequest('/institutional-ownership/latest', { symbol }); } // ESG Score export interface ESGScore { symbol: string; companyName: string; formattedDate: string; environmentalScore: number; socialScore: number; governanceScore: number; ESGScore: number; } export async function getESGScore(symbol: string): Promise { return fmpRequest('/esg-environmental-social-governance-data', { symbol }); } // Social Sentiment export interface SocialSentiment { date: string; symbol: string; stocktwitsPosts: number; twitterPosts: number; stocktwitsComments: number; twitterComments: number; stocktwitsLikes: number; twitterLikes: number; stocktwitsImpressions: number; twitterImpressions: number; stocktwitsSentiment: number; twitterSentiment: number; } export async function getSocialSentiment(symbol: string, limit: number = 10): Promise { // Limit to 10 records to avoid context overflow const actualLimit = Math.min(limit, 10); const result = await fmpRequest('/social-sentiments/trending', { type: 'bullish', source: 'stocktwits' }); return result.slice(0, actualLimit); } // Congressional Trading export interface CongressionalTrade { transactionDate: string; transactionType: string; ticker: string; assetDescription: string; assetType: string; type: string; amount: string; representative: string; representativeLink: string; transactionLink: string; disclosureDate: string; } export async function getCongressionalTrading(symbol?: string): Promise { const params: Record = {}; if (symbol) params.symbol = symbol; return fmpRequest('/senate-trading', params); } export async function getSenateTrading(symbol?: string): Promise { const params: Record = {}; if (symbol) params.symbol = symbol; return fmpRequest('/senate-disclosure', params); } // Search by CIK, CUSIP, ISIN export interface CompanySearchResult { symbol: string; name: string; currency: string; stockExchange: string; exchangeShortName: string; } export async function searchByCIK(cik: string): Promise { return fmpRequest('/search-cik', { cik }); } export async function searchByCUSIP(cusip: string): Promise { return fmpRequest('/search-cusip', { cusip }); } export async function searchByISIN(isin: string): Promise { return fmpRequest('/search-isin', { isin }); } // Stock Screener export interface ScreenerResult { symbol: string; companyName: string; marketCap: number; sector: string; industry: string; beta: number; price: number; lastAnnualDividend: number; volume: number; exchange: string; exchangeShortName: string; country: string; isEtf: boolean; isActivelyTrading: boolean; } export async function getStockScreener(filters: { marketCapMoreThan?: number; marketCapLowerThan?: number; betaMoreThan?: number; betaLowerThan?: number; volumeMoreThan?: number; sector?: string; industry?: string; exchange?: string; limit?: number; }): Promise { return fmpRequest('/stock-screener', filters); } // Market Hours export interface MarketHours { stockExchangeName: string; stockMarketHours: { openingHour: string; closingHour: string; }; stockMarketHolidays: string[]; isTheStockMarketOpen: boolean; isTheEuronextMarketOpen: boolean; isTheForexMarketOpen: boolean; isTheCryptoMarketOpen: boolean; } export async function getMarketHours(): Promise { return fmpRequest('/all-exchange-market-hours'); } // Market Movers export interface MarketMover { symbol: string; name: string; change: number; price: number; changesPercentage: number; } export async function getGainers(): Promise { return fmpRequest('/biggest-gainers'); } export async function getLosers(): Promise { return fmpRequest('/biggest-losers'); } export async function getActives(): Promise { return fmpRequest('/most-actives'); } // ETF Holdings export interface ETFHolding { asset: string; name: string; sharesNumber: number; weightPercentage: number; marketValue: number; } export async function getETFHoldings(symbol: string): Promise { return fmpRequest('/etf-holder', { symbol }); } // ETF Sector Weightings export interface ETFSectorWeighting { sector: string; weightPercentage: string; } export async function getETFSectorWeightings(symbol: string): Promise { return fmpRequest('/etf-sector-weightings', { symbol }); } // ETF Country Weightings export interface ETFCountryWeighting { country: string; weightPercentage: string; } export async function getETFCountryWeightings(symbol: string): Promise { return fmpRequest('/etf-country-weightings', { symbol }); } // Financial Growth export interface FinancialGrowth { date: string; symbol: string; period: string; calendarYear: string; revenueGrowth: number; grossProfitGrowth: number; ebitgrowth: number; operatingIncomeGrowth: number; netIncomeGrowth: number; epsgrowth: number; epsdilutedGrowth: number; weightedAverageSharesGrowth: number; weightedAverageSharesDilutedGrowth: number; dividendsperShareGrowth: number; operatingCashFlowGrowth: number; freeCashFlowGrowth: number; tenYRevenueGrowthPerShare: number; fiveYRevenueGrowthPerShare: number; threeYRevenueGrowthPerShare: number; tenYOperatingCFGrowthPerShare: number; fiveYOperatingCFGrowthPerShare: number; threeYOperatingCFGrowthPerShare: number; tenYNetIncomeGrowthPerShare: number; fiveYNetIncomeGrowthPerShare: number; threeYNetIncomeGrowthPerShare: number; tenYShareholdersEquityGrowthPerShare: number; fiveYShareholdersEquityGrowthPerShare: number; threeYShareholdersEquityGrowthPerShare: number; tenYDividendperShareGrowthPerShare: number; fiveYDividendperShareGrowthPerShare: number; threeYDividendperShareGrowthPerShare: number; receivablesGrowth: number; inventoryGrowth: number; assetGrowth: number; bookValueperShareGrowth: number; debtGrowth: number; rdexpenseGrowth: number; sgaexpensesGrowth: number; } export async function getFinancialGrowth(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise { return fmpRequest('/financial-growth', { symbol, period, limit }); } // Company Outlook export interface CompanyOutlook { profile: CompanyProfile; metrics: any; ratios: any[]; insiderTrades: any[]; keyExecutives: any[]; splitHistory: any[]; stockDividend: any[]; stockNews: any[]; rating: any[]; financialsAnnual: any; financialsQuarter: any; } export async function getCompanyOutlook(symbol: string): Promise { return fmpRequest('/company-outlook', { symbol }); } // Stock News Sentiment export interface StockNewsSentiment { symbol: string; publishedDate: string; title: string; image: string; site: string; text: string; url: string; sentiment: string; sentimentScore: number; } export async function getStockNewsSentiment(symbol: string, limit: number = 5): Promise { // Limit to 5 articles to avoid context overflow const actualLimit = Math.min(limit, 5); return fmpRequest('/stock-news-sentiment-rss-feed', { tickers: symbol, limit: actualLimit }); } // Crypto Quote export interface CryptoQuote { symbol: string; name: string; price: number; changesPercentage: number; change: number; dayLow: number; dayHigh: number; yearHigh: number; yearLow: number; marketCap: number; priceAvg50: number; priceAvg200: number; volume: number; avgVolume: number; exchange: string; open: number; previousClose: number; timestamp: number; } export async function getCryptoQuote(symbol: string): Promise { return fmpRequest('/quote', { symbol }); } export async function getCryptoList(): Promise> { return fmpRequest('/available-cryptocurrencies'); } // Forex Historical export interface ForexHistorical { date: string; open: number; high: number; low: number; close: number; adjClose: number; volume: number; } export async function getForexHistorical(pair: string, from?: string, to?: string): Promise<{ symbol: string; historical: ForexHistorical[] }> { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; params.symbol = pair; const data = await fmpRequest('/historical-price-eod/full', params); // Stable API returns flat array; wrap to match legacy format let historical = Array.isArray(data) ? data : (data as any).historical || []; // Limit to last 20 days if (historical.length > 20) { historical = historical.slice(0, 20); } return { symbol: pair, historical }; } // SEC Filings export interface SECFiling { symbol: string; cik: string; acceptedDate: string; type: string; link: string; finalLink: string; } export async function getSECFilings(symbol: string, type?: string, limit: number = 20): Promise { // Limit to 20 filings to avoid context overflow const actualLimit = Math.min(limit, 20); const params: Record = { limit: actualLimit }; if (type) params.type = type; return fmpRequest('/sec-filings', { symbol, ...params }); } // Company Notes export interface CompanyNote { symbol: string; cik: string; acceptedDate: string; period: string; formType: string; notes: string; } export async function getCompanyNotes(symbol: string): Promise { return fmpRequest('/company-notes', { symbol }); } // Earnings Call Transcript export interface EarningsCallTranscript { symbol: string; quarter: number; year: number; date: string; content: string; } export async function getEarningsCallTranscript(symbol: string, year: number, quarter: number): Promise { return fmpRequest('/earning-call-transcript', { symbol, quarter, year }); } // Advanced Chart Data APIs // fmpStableRequest now uses the same base URL as fmpRequest (all migrated to /stable) async function fmpStableRequest(endpoint: string, params: Record = {}): Promise { return fmpRequest(endpoint, params); } export interface ChartDataLight { symbol: string; date: string; price: number; volume: number; } export interface ChartDataFull { symbol: string; date: string; open: number; high: number; low: number; close: number; volume: number; change: number; changePercent: number; vwap: number; } export interface ChartDataIntraday { date: string; open: number; high: number; low: number; close: number; volume: number; } // Stock Chart Light API export async function getChartLight(symbol: string, from?: string, to?: string): Promise { const params: Record = { symbol }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/historical-price-eod/light', params); } // Stock Price and Volume Data API (Full) export async function getChartFull(symbol: string, from?: string, to?: string): Promise { const params: Record = { symbol }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/historical-price-eod/full', params); } // Unadjusted Stock Price API export async function getChartUnadjusted(symbol: string, from?: string, to?: string): Promise { const params: Record = { symbol }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/historical-price-eod/non-split-adjusted', params); } // Dividend Adjusted Price Chart API export async function getChartDividendAdjusted(symbol: string, from?: string, to?: string): Promise { const params: Record = { symbol }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/historical-price-eod/dividend-adjusted', params); } // Intraday Chart APIs export async function getChartIntraday( symbol: string, interval: '1min' | '5min' | '15min' | '30min' | '1hour' | '4hour', from?: string, to?: string, nonadjusted: boolean = false ): Promise { const params: Record = { symbol }; if (from) params.from = from; if (to) params.to = to; if (nonadjusted) params.nonadjusted = 'true'; return fmpStableRequest(`/historical-chart/${interval}`, params); } // ========================================== // SEARCH & DISCOVERY APIs // ========================================== // Search Symbol API export async function searchSymbol(query: string): Promise> { return fmpStableRequest('/search-symbol', { query }); } // Search Name API export async function searchName(query: string): Promise> { return fmpStableRequest('/search-name', { query }); } // Search Exchange Variants API export async function searchExchangeVariants(symbol: string): Promise> { return fmpStableRequest('/search-exchange-variants', { symbol }); } // Stock List API export async function getStockList(): Promise> { return fmpStableRequest('/stock-list'); } // Financial Statement Symbol List API export async function getFinancialStatementSymbolList(): Promise> { return fmpStableRequest('/financial-statement-symbol-list'); } // CIK List API export async function getCIKList(page: number = 0, limit: number = 1000): Promise> { return fmpStableRequest('/cik-list', { page, limit }); } // Symbol Change API export async function getSymbolChange(): Promise> { return fmpStableRequest('/symbol-change'); } // ETF List API export async function getETFList(): Promise> { return fmpStableRequest('/etf-list'); } // Actively Trading List API export async function getActivelyTradingList(): Promise> { return fmpStableRequest('/actively-trading-list'); } // Earnings Transcript List API export async function getEarningsTranscriptList(): Promise> { return fmpStableRequest('/earnings-transcript-list'); } // Available Exchanges API export async function getAvailableExchanges(): Promise> { return fmpStableRequest('/available-exchanges'); } // Available Sectors API export async function getAvailableSectors(): Promise> { return fmpStableRequest('/available-sectors'); } // Available Industries API export async function getAvailableIndustries(): Promise> { return fmpStableRequest('/available-industries'); } // Available Countries API export async function getAvailableCountries(): Promise> { return fmpStableRequest('/available-countries'); } // ========================================== // ADVANCED COMPANY DATA APIs // ========================================== // Profile by CIK API export async function getProfileByCIK(cik: string): Promise { return fmpStableRequest('/profile-cik', { cik }); } // Delisted Companies API export async function getDelistedCompanies(page: number = 0, limit: number = 100): Promise> { return fmpStableRequest('/delisted-companies', { page, limit }); } // Employee Count API export async function getEmployeeCount(symbol: string): Promise> { return fmpStableRequest('/employee-count', { symbol }); } // Historical Employee Count API export async function getHistoricalEmployeeCount(symbol: string): Promise> { return fmpStableRequest('/historical-employee-count', { symbol }); } // Market Capitalization API export async function getMarketCapitalization(symbol: string): Promise> { return fmpStableRequest('/market-capitalization', { symbol }); } // Batch Market Capitalization API export async function getBatchMarketCapitalization(symbols: string): Promise> { return fmpStableRequest('/market-capitalization-batch', { symbols }); } // Historical Market Capitalization API export async function getHistoricalMarketCapitalization(symbol: string, limit: number = 100): Promise> { return fmpStableRequest('/historical-market-capitalization', { symbol, limit }); } // Shares Float API export async function getSharesFloat(symbol: string): Promise> { return fmpStableRequest('/shares-float', { symbol }); } // All Shares Float API export async function getAllSharesFloat(page: number = 0, limit: number = 1000): Promise> { return fmpStableRequest('/shares-float-all', { page, limit }); } // Latest Mergers and Acquisitions API export async function getLatestMergersAcquisitions(page: number = 0, limit: number = 100): Promise> { return fmpStableRequest('/mergers-acquisitions-latest', { page, limit }); } // Search Mergers and Acquisitions API export async function searchMergersAcquisitions(name: string): Promise> { return fmpStableRequest('/mergers-acquisitions-search', { name }); } // Key Executives API export async function getKeyExecutives(symbol: string): Promise> { return fmpStableRequest('/key-executives', { symbol }); } // Executive Compensation API export async function getExecutiveCompensation(symbol: string): Promise> { return fmpStableRequest('/governance-executive-compensation', { symbol }); } // Executive Compensation Benchmark API export async function getExecutiveCompensationBenchmark(year?: number): Promise> { const params: Record = {}; if (year) params.year = year; return fmpStableRequest('/executive-compensation-benchmark', params); } // ========================================== // QUOTES & MARKET DATA APIs // ========================================== // Quote Short API export async function getQuoteShort(symbol: string): Promise> { return fmpStableRequest('/quote-short', { symbol }); } // Aftermarket Trade API export async function getAftermarketTrade(symbol: string): Promise> { return fmpStableRequest('/aftermarket-trade', { symbol }); } // Aftermarket Quote API export async function getAftermarketQuote(symbol: string): Promise> { return fmpStableRequest('/aftermarket-quote', { symbol }); } // Stock Price Change API export async function getStockPriceChange(symbol: string): Promise> { return fmpStableRequest('/stock-price-change', { symbol }); } // Batch Quote API export async function getBatchQuote(symbols: string): Promise { return fmpStableRequest('/batch-quote', { symbols }); } // Batch Quote Short API export async function getBatchQuoteShort(symbols: string): Promise> { return fmpStableRequest('/batch-quote-short', { symbols }); } // Batch Aftermarket Trade API export async function getBatchAftermarketTrade(symbols: string): Promise> { return fmpStableRequest('/batch-aftermarket-trade', { symbols }); } // Batch Aftermarket Quote API export async function getBatchAftermarketQuote(symbols: string): Promise> { return fmpStableRequest('/batch-aftermarket-quote', { symbols }); } // Exchange Stock Quotes API export async function getBatchExchangeQuote(exchange: string): Promise { return fmpStableRequest('/batch-exchange-quote', { exchange }); } // Mutual Fund Quotes API export async function getBatchMutualfundQuotes(): Promise { return fmpStableRequest('/batch-mutualfund-quotes'); } // ETF Quotes API export async function getBatchETFQuotes(): Promise { return fmpStableRequest('/batch-etf-quotes'); } // Commodity Quotes API (Batch) export async function getBatchCommodityQuotes(): Promise { return fmpStableRequest('/batch-commodity-quotes'); } // Crypto Quotes API (Batch) export async function getBatchCryptoQuotes(): Promise { return fmpStableRequest('/batch-crypto-quotes'); } // Forex Quotes API (Batch) export async function getBatchForexQuotes(): Promise { return fmpStableRequest('/batch-forex-quotes'); } // Index Quotes API (Batch) export async function getBatchIndexQuotes(): Promise { return fmpStableRequest('/batch-index-quotes'); } // ========================================== // FINANCIAL STATEMENTS - TTM & AS REPORTED // ========================================== // Latest Financial Statements API export async function getLatestFinancialStatements(page: number = 0, limit: number = 250): Promise> { return fmpStableRequest('/latest-financial-statements', { page, limit }); } // Income Statement TTM API export async function getIncomeStatementTTM(symbol: string): Promise { return fmpStableRequest('/income-statement-ttm', { symbol }); } // Balance Sheet TTM API export async function getBalanceSheetTTM(symbol: string): Promise { return fmpStableRequest('/balance-sheet-statement-ttm', { symbol }); } // Cash Flow Statement TTM API export async function getCashflowStatementTTM(symbol: string): Promise { return fmpStableRequest('/cash-flow-statement-ttm', { symbol }); } // Key Metrics TTM API export async function getKeyMetricsTTM(symbol: string): Promise { return fmpStableRequest('/key-metrics-ttm', { symbol }); } // Ratios TTM API export async function getRatiosTTM(symbol: string): Promise { return fmpStableRequest('/ratios-ttm', { symbol }); } // Financial Scores API export async function getFinancialScores(symbol: string): Promise> { return fmpStableRequest('/financial-scores', { symbol }); } // Owner Earnings API export async function getOwnerEarnings(symbol: string): Promise> { return fmpStableRequest('/owner-earnings', { symbol }); } // Enterprise Values API export async function getEnterpriseValues(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise> { return fmpStableRequest('/enterprise-values', { symbol, period, limit }); } // Financial Reports Dates API export async function getFinancialReportsDates(symbol: string): Promise> { return fmpStableRequest('/financial-reports-dates', { symbol }); } // Annual Reports 10K JSON API export async function getAnnualReports10K(symbol: string, year: number, period: string): Promise { return fmpStableRequest('/financial-reports-json', { symbol, year, period }); } // Annual Reports 10K XLSX API export async function getAnnualReports10KXLSX(symbol: string, year: number, period: string): Promise { return fmpStableRequest('/financial-reports-xlsx', { symbol, year, period }); } // Revenue Product Segmentation API export async function getRevenueProductSegmentation(symbol: string, period: 'annual' | 'quarter' = 'annual'): Promise> { return fmpStableRequest('/revenue-product-segmentation', { symbol, period }); } // Revenue Geographic Segmentation API export async function getRevenueGeographicSegmentation(symbol: string, period: 'annual' | 'quarter' = 'annual'): Promise> { return fmpStableRequest('/revenue-geographic-segmentation', { symbol, period }); } // Income Statement As Reported API export async function getIncomeStatementAsReported(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise> { return fmpStableRequest('/income-statement-as-reported', { symbol, period, limit }); } // Balance Sheet As Reported API export async function getBalanceSheetAsReported(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise> { return fmpStableRequest('/balance-sheet-statement-as-reported', { symbol, period, limit }); } // Cash Flow As Reported API export async function getCashFlowAsReported(symbol: string, period: 'annual' | 'quarter' = 'annual', limit: number = 5): Promise> { return fmpStableRequest('/cash-flow-statement-as-reported', { symbol, period, limit }); } // Full Financial Statement As Reported API export async function getFullFinancialStatementAsReported(symbol: string, period: 'annual' | 'quarter' = 'annual'): Promise { return fmpStableRequest('/financial-statement-full-as-reported', { symbol, period }); } // ========================================== // ECONOMIC DATA & DIVIDENDS // ========================================== // Market Risk Premium API export async function getMarketRiskPremium(country?: string): Promise> { const params: Record = {}; if (country) params.country = country; return fmpStableRequest('/market-risk-premium', params); } // Dividends Company API export async function getDividendsCompany(symbol: string): Promise { return fmpStableRequest('/dividends', { symbol }); } // Dividends Calendar API export async function getDividendsCalendar(from?: string, to?: string): Promise> { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/dividends-calendar', params); } // Earnings Report API export async function getEarningsReport(symbol: string): Promise> { return fmpStableRequest('/earnings', { symbol }); } // IPO Disclosures API export async function getIPODisclosures(from?: string, to?: string): Promise> { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/ipos-disclosure', params); } // IPO Prospectus API export async function getIPOProspectus(from?: string, to?: string): Promise> { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/ipos-prospectus', params); } // Splits API export async function getSplits(symbol: string): Promise { return fmpStableRequest('/splits', { symbol }); } // Splits Calendar API export async function getSplitsCalendar(from?: string, to?: string): Promise { const params: Record = {}; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/splits-calendar', params); } // ========================================== // NEWS & TRANSCRIPTS APIs // ========================================== // Latest Earning Transcripts API export async function getLatestEarningTranscripts(): Promise> { return fmpStableRequest('/earning-call-transcript-latest'); } // Earning Call Transcript Dates API export async function getEarningCallTranscriptDates(symbol: string): Promise> { return fmpStableRequest('/earning-call-transcript-dates', { symbol }); } // FMP Articles API export async function getFMPArticles(page: number = 0, limit: number = 20): Promise> { return fmpStableRequest('/fmp-articles', { page, limit }); } // General News API export async function getGeneralNews(page: number = 0, limit: number = 20): Promise { return fmpStableRequest('/news/general-latest', { page, limit }); } // Press Releases Latest API export async function getPressReleasesLatest(page: number = 0, limit: number = 20): Promise { return fmpStableRequest('/news/press-releases-latest', { page, limit }); } // Stock News Latest API export async function getStockNewsLatest(page: number = 0, limit: number = 20): Promise { return fmpStableRequest('/news/stock-latest', { page, limit }); } // Crypto News API export async function getCryptoNews(page: number = 0, limit: number = 20): Promise { return fmpStableRequest('/news/crypto-latest', { page, limit }); } // Forex News API export async function getForexNews(page: number = 0, limit: number = 20): Promise { return fmpStableRequest('/news/forex-latest', { page, limit }); } // Search Press Releases API export async function searchPressReleasesNew(symbols: string): Promise { return fmpStableRequest('/news/press-releases', { symbols }); } // Search Stock News API export async function searchStockNews(symbols: string): Promise { return fmpStableRequest('/news/stock', { symbols }); } // Search Crypto News API export async function searchCryptoNews(symbols: string): Promise { return fmpStableRequest('/news/crypto', { symbols }); } // Search Forex News API export async function searchForexNews(symbols: string): Promise { return fmpStableRequest('/news/forex', { symbols }); } // ========================================== // FORM 13F & INSTITUTIONAL OWNERSHIP APIs // ========================================== // Institutional Ownership Filings API export async function getInstitutionalOwnershipFilings(page: number = 0, limit: number = 100): Promise> { return fmpStableRequest('/institutional-ownership/latest', { page, limit }); } // SEC Filings Extract API export async function extractSECFilings(cik: string, year: number, quarter: number): Promise> { return fmpStableRequest('/institutional-ownership/extract', { cik, year, quarter }); } // Form 13F Filings Dates API export async function getForm13FFilingsDates(cik: string): Promise> { return fmpStableRequest('/institutional-ownership/dates', { cik }); } // Filings Extract With Analytics By Holder API export async function getFilingsExtractWithAnalytics(symbol: string, year: number, quarter: number, page: number = 0, limit: number = 10): Promise> { return fmpStableRequest('/institutional-ownership/extract-analytics/holder', { symbol, year, quarter, page, limit }); } // Holder Performance Summary API export async function getHolderPerformanceSummary(cik: string, page: number = 0): Promise> { return fmpStableRequest('/institutional-ownership/holder-performance-summary', { cik, page }); } // Holders Industry Breakdown API export async function getHoldersIndustryBreakdown(cik: string, year: number, quarter: number): Promise> { return fmpStableRequest('/institutional-ownership/holder-industry-breakdown', { cik, year, quarter }); } // Positions Summary API export async function getPositionsSummary(symbol: string, year: number, quarter: number): Promise> { return fmpStableRequest('/institutional-ownership/symbol-positions-summary', { symbol, year, quarter }); } // Industry Performance Summary API export async function getIndustryPerformanceSummary(year: number, quarter: number): Promise> { return fmpStableRequest('/institutional-ownership/industry-summary', { year, quarter }); } // ========================================== // ANALYST RATINGS & ESTIMATES APIs // ========================================== // Ratings Snapshot API export async function getRatingsSnapshot(symbol: string): Promise> { return fmpStableRequest('/ratings-snapshot', { symbol }); } // Historical Ratings API export async function getHistoricalRatings(symbol: string, limit: number = 100): Promise> { return fmpStableRequest('/ratings-historical', { symbol, limit }); } // Price Target Consensus API export async function getPriceTargetConsensus(symbol: string): Promise> { return fmpStableRequest('/price-target-consensus', { symbol }); } // Grades API export async function getGrades(symbol: string, limit: number = 100): Promise> { return fmpStableRequest('/grades', { symbol, limit }); } // Historical Grades API export async function getHistoricalGrades(symbol: string, limit: number = 100): Promise> { return fmpStableRequest('/grades-historical', { symbol, limit }); } // Grades Summary API export async function getGradesSummary(symbol: string): Promise> { return fmpStableRequest('/grades-consensus', { symbol }); } // ========================================== // MARKET PERFORMANCE & SECTORS APIs // ========================================== // Market Sector Performance Snapshot API export async function getMarketSectorPerformanceSnapshot(date?: string): Promise> { const params: Record = {}; if (date) params.date = date; return fmpStableRequest('/sector-performance-snapshot', params); } // Industry Performance Snapshot API export async function getIndustryPerformanceSnapshot(date?: string): Promise> { const params: Record = {}; if (date) params.date = date; return fmpStableRequest('/industry-performance-snapshot', params); } // Historical Sector Performance API export async function getHistoricalSectorPerformance(sector: string, limit: number = 100): Promise> { return fmpStableRequest('/historical-sector-performance', { sector, limit }); } // Historical Industry Performance API export async function getHistoricalIndustryPerformance(industry: string, limit: number = 100): Promise> { return fmpStableRequest('/historical-industry-performance', { industry, limit }); } // Sector P/E Snapshot API export async function getSectorPESnapshot(date?: string): Promise> { const params: Record = {}; if (date) params.date = date; return fmpStableRequest('/sector-pe-snapshot', params); } // Industry P/E Snapshot API export async function getIndustryPESnapshot(date?: string): Promise> { const params: Record = {}; if (date) params.date = date; return fmpStableRequest('/industry-pe-snapshot', params); } // Historical Sector P/E API export async function getHistoricalSectorPE(sector: string, limit: number = 100): Promise> { return fmpStableRequest('/historical-sector-pe', { sector, limit }); } // Historical Industry P/E API export async function getHistoricalIndustryPE(industry: string, limit: number = 100): Promise> { return fmpStableRequest('/historical-industry-pe', { industry, limit }); } // ========================================== // ADDITIONAL TECHNICAL INDICATORS APIs // ========================================== // Weighted Moving Average API export async function getWMA(symbol: string, periodLength: number = 10, timeframe: string = '1day'): Promise { const result = await fmpStableRequest('/technical-indicators/wma', { symbol, periodLength, timeframe }); return result.slice(0, 10); } // Double Exponential Moving Average API export async function getDEMA(symbol: string, periodLength: number = 10, timeframe: string = '1day'): Promise { const result = await fmpStableRequest('/technical-indicators/dema', { symbol, periodLength, timeframe }); return result.slice(0, 10); } // Triple Exponential Moving Average API export async function getTEMA(symbol: string, periodLength: number = 10, timeframe: string = '1day'): Promise { const result = await fmpStableRequest('/technical-indicators/tema', { symbol, periodLength, timeframe }); return result.slice(0, 10); } // Standard Deviation API export async function getStandardDeviation(symbol: string, periodLength: number = 10, timeframe: string = '1day'): Promise { const result = await fmpStableRequest('/technical-indicators/standarddeviation', { symbol, periodLength, timeframe }); return result.slice(0, 10); } // ========================================== // ETF & MUTUAL FUNDS APIs // ========================================== // ETF Asset Exposure API export async function getETFAssetExposure(symbol: string): Promise> { return fmpStableRequest('/etf/asset-exposure', { symbol }); } // Mutual Fund Disclosure Latest API export async function getMutualFundDisclosureLatest(symbol: string): Promise> { return fmpStableRequest('/funds/disclosure-holders-latest', { symbol }); } // Mutual Fund Disclosure API export async function getMutualFundDisclosure(symbol: string, year: number, quarter: number): Promise { return fmpStableRequest('/funds/disclosure', { symbol, year, quarter }); } // Mutual Fund Disclosure Search API export async function getMutualFundDisclosureSearch(name: string): Promise> { return fmpStableRequest('/funds/disclosure-holders-search', { name }); } // Fund Disclosure Dates API export async function getMutualFundDisclosureDates(symbol: string): Promise> { return fmpStableRequest('/funds/disclosure-dates', { symbol }); } // ========================================== // SEC FILINGS - ADVANCED APIs // ========================================== // Latest 8-K SEC Filings API export async function getLatest8KSECFilings(from?: string, to?: string, page: number = 0, limit: number = 100): Promise> { const params: Record = { page, limit }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/sec-filings-8k', params); } // Latest SEC Filings API export async function getLatestSECFilings(from?: string, to?: string, page: number = 0, limit: number = 100): Promise> { const params: Record = { page, limit }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/sec-filings-financials', params); } // SEC Filings By Form Type API export async function getSECFilingsByFormType(formType: string, from?: string, to?: string, page: number = 0, limit: number = 100): Promise> { const params: Record = { formType, page, limit }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/sec-filings-search/form-type', params); } // SEC Filings By Symbol API export async function getSECFilingsBySymbol(symbol: string, from?: string, to?: string, page: number = 0, limit: number = 100): Promise> { const params: Record = { symbol, page, limit }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/sec-filings-search/symbol', params); } // SEC Filings By CIK API export async function getSECFilingsByCIK(cik: string, from?: string, to?: string, page: number = 0, limit: number = 100): Promise> { const params: Record = { cik, page, limit }; if (from) params.from = from; if (to) params.to = to; return fmpStableRequest('/sec-filings-search/cik', params); } // SEC Filings By Name API export async function getSECFilingsByName(company: string): Promise> { return fmpStableRequest('/sec-filings-company-search/name', { company }); } // SEC Filings Company Search By Symbol API export async function getSECFilingsCompanySearchBySymbol(symbol: string): Promise> { return fmpStableRequest('/sec-filings-company-search/symbol', { symbol }); } // SEC Filings Company Search By CIK API export async function getSECFilingsCompanySearchByCIK(cik: string): Promise> { return fmpStableRequest('/sec-filings-company-search/cik', { cik }); } // SEC Company Full Profile API export async function getSECCompanyFullProfile(symbol: string): Promise { return fmpStableRequest('/sec-profile', { symbol }); } // Industry Classification List API export async function getIndustryClassificationList(): Promise> { return fmpStableRequest('/standard-industrial-classification-list'); } // Industry Classification Search API export async function searchIndustryClassification(industryTitle?: string, sicCode?: string): Promise> { const params: Record = {}; if (industryTitle) params.industryTitle = industryTitle; if (sicCode) params.sicCode = sicCode; return fmpStableRequest('/industry-classification-search', params); } // All Industry Classification API export async function getAllIndustryClassification(): Promise> { return fmpStableRequest('/all-industry-classification'); } // ========================================== // INSIDER TRADES - ADVANCED APIs // ========================================== // Latest Insider Trading API export async function getLatestInsiderTrading(page: number = 0, limit: number = 100): Promise { return fmpStableRequest('/insider-trading/latest', { page, limit }); } // Search Insider Trades API export async function searchInsiderTrades(symbol?: string, companyName?: string, reportingName?: string, page: number = 0, limit: number = 100): Promise { const params: Record = { page, limit }; if (symbol) params.symbol = symbol; if (companyName) params.companyName = companyName; if (reportingName) params.reportingName = reportingName; return fmpStableRequest('/insider-trading/search', params); } // Search Insider Trades By Name API export async function searchInsiderTradesByName(name: string): Promise { return fmpStableRequest('/insider-trading/reporting-name', { name }); } // All Insider Transaction Types API export async function getAllInsiderTransactionTypes(): Promise> { return fmpStableRequest('/insider-trading-transaction-type'); } // Acquisition Of Beneficial Ownership API export async function getAcquisitionOfBeneficialOwnership(symbol: string): Promise> { return fmpStableRequest('/acquisition-of-beneficial-ownership', { symbol }); } // ========================================== // INDEXES APIs // ========================================== // Index List API export async function getIndexList(): Promise> { return fmpStableRequest('/index-list'); } // S&P 500 Constituent API export async function getSP500Constituent(): Promise> { return fmpStableRequest('/sp500-constituent'); } // Nasdaq Constituent API export async function getNasdaqConstituent(): Promise> { return fmpStableRequest('/nasdaq-constituent'); } // Dow Jones Constituent API export async function getDowJonesConstituent(): Promise> { return fmpStableRequest('/dowjones-constituent'); } // Historical S&P 500 Constituent API export async function getHistoricalSP500Constituent(): Promise> { return fmpStableRequest('/historical-sp500-constituent'); } // Historical Nasdaq Constituent API export async function getHistoricalNasdaqConstituent(): Promise> { return fmpStableRequest('/historical-nasdaq-constituent'); } // Historical Dow Jones Constituent API export async function getHistoricalDowJonesConstituent(): Promise> { return fmpStableRequest('/historical-dowjones-constituent'); } // Exchange Market Hours API export async function getExchangeMarketHours(exchange: string): Promise { return fmpStableRequest('/exchange-market-hours', { exchange }); } // Holidays By Exchange API export async function getHolidaysByExchange(exchange: string): Promise }>> { return fmpStableRequest('/holidays-by-exchange', { exchange }); } // All Exchange Market Hours API export async function getAllExchangeMarketHours(): Promise> { return fmpStableRequest('/all-exchange-market-hours'); } // ========================================== // COMMODITIES APIs // ========================================== // Commodities List API export async function getCommoditiesList(): Promise> { return fmpStableRequest('/commodities-list'); } // ========================================== // DCF VALUATION APIs // ========================================== // DCF Valuation API export async function getDCFValuation(symbol: string): Promise> { return fmpStableRequest('/discounted-cash-flow', { symbol }); } // Levered DCF API export async function getLeveredDCF(symbol: string): Promise> { return fmpStableRequest('/levered-discounted-cash-flow', { symbol }); } // Custom DCF API export async function getCustomDCF(symbol: string, years?: number, growthRate?: number, discountRate?: number): Promise { const params: Record = { symbol }; if (years) params.years = years; if (growthRate) params.growthRate = growthRate; if (discountRate) params.discountRate = discountRate; return fmpStableRequest('/custom-discounted-cash-flow', params); } // Custom Levered DCF API export async function getCustomLeveredDCF(symbol: string, years?: number, growthRate?: number, discountRate?: number): Promise { const params: Record = { symbol }; if (years) params.years = years; if (growthRate) params.growthRate = growthRate; if (discountRate) params.discountRate = discountRate; return fmpStableRequest('/custom-levered-discounted-cash-flow', params); } // ========================================== // FOREX APIs // ========================================== // Forex Currency Pairs API export async function getForexCurrencyPairs(): Promise> { return fmpStableRequest('/forex-list'); } // ========================================== // SENATE & HOUSE TRADING APIs // ========================================== // Latest Senate Disclosures API export async function getLatestSenateDisclosures(page: number = 0, limit: number = 100): Promise { return fmpStableRequest('/senate-latest', { page, limit }); } // Latest House Disclosures API export async function getLatestHouseDisclosures(page: number = 0, limit: number = 100): Promise { return fmpStableRequest('/house-latest', { page, limit }); } // Senate Trades API (by symbol) export async function getSenateTradesSymbol(symbol: string): Promise { return fmpStableRequest('/senate-trades', { symbol }); } // Senate Trades By Name API export async function getSenateTradesByName(name: string): Promise { return fmpStableRequest('/senate-trades-by-name', { name }); } // House Trades API (by symbol) export async function getHouseTradesSymbol(symbol: string): Promise { return fmpStableRequest('/house-trades', { symbol }); } // House Trades By Name API export async function getHouseTradesByName(name: string): Promise { return fmpStableRequest('/house-trades-by-name', { name }); } // ========================================== // ESG APIs // ========================================== // ESG Disclosures API export async function getESGDisclosures(symbol: string): Promise> { return fmpStableRequest('/esg-disclosures', { symbol }); } // ESG Ratings API export async function getESGRatings(symbol: string): Promise { return fmpStableRequest('/esg-ratings', { symbol }); } // ESG Benchmark API export async function getESGBenchmark(year?: number): Promise> { const params: Record = {}; if (year) params.year = year; return fmpStableRequest('/esg-benchmark', params); } // ========================================== // COT (Commitment of Traders) APIs // ========================================== // COT List API export async function getCOTList(): Promise> { return fmpStableRequest('/commitment-of-traders-list'); } // ========================================== // CROWDFUNDING & EQUITY OFFERINGS APIs // ========================================== // Latest Crowdfunding Campaigns API export async function getLatestCrowdfundingCampaigns(page: number = 0, limit: number = 100): Promise> { return fmpStableRequest('/crowdfunding-offerings-latest', { page, limit }); } // Search Crowdfunding Campaigns API export async function searchCrowdfundingCampaigns(name: string): Promise> { return fmpStableRequest('/crowdfunding-offerings-search', { name }); } // Crowdfunding By CIK API export async function getCrowdfundingByCIK(cik: string): Promise> { return fmpStableRequest('/crowdfunding-offerings', { cik }); } // Equity Offering Updates API export async function getEquityOfferingUpdates(page: number = 0, limit: number = 10): Promise> { return fmpStableRequest('/fundraising-latest', { page, limit }); } // Search Equity Offerings API export async function searchEquityOfferings(name: string): Promise> { return fmpStableRequest('/fundraising-search', { name }); } // Company Equity Offerings By CIK API export async function getCompanyEquityOfferingsByCIK(cik: string): Promise> { return fmpStableRequest('/fundraising', { cik }); } // ========================================== // BULK APIs // ========================================== // Profile Bulk API export async function getProfileBulk(part: number = 0): Promise { return fmpStableRequest('/profile-bulk', { part }); } // Rating Bulk API export async function getRatingBulk(): Promise> { return fmpStableRequest('/rating-bulk'); } // DCF Bulk API export async function getDCFBulk(): Promise> { return fmpStableRequest('/dcf-bulk'); } // Scores Bulk API export async function getScoresBulk(): Promise> { return fmpStableRequest('/scores-bulk'); } // Price Target Summary Bulk API export async function getPriceTargetSummaryBulk(): Promise { return fmpStableRequest('/price-target-summary-bulk'); } // ETF Holder Bulk API export async function getETFHolderBulk(part: number = 1): Promise> { return fmpStableRequest('/etf-holder-bulk', { part }); } // Upgrades Downgrades Consensus Bulk API export async function getUpgradesDowngradesConsensusBulk(): Promise> { return fmpStableRequest('/upgrades-downgrades-consensus-bulk'); } // Key Metrics TTM Bulk API export async function getKeyMetricsTTMBulk(): Promise { return fmpStableRequest('/key-metrics-ttm-bulk'); } // Ratios TTM Bulk API export async function getRatiosTTMBulk(): Promise { return fmpStableRequest('/ratios-ttm-bulk'); } // Stock Peers Bulk API export async function getStockPeersBulk(): Promise> { return fmpStableRequest('/peers-bulk'); } // Earnings Surprises Bulk API export async function getEarningsSurprisesBulk(year: number): Promise> { return fmpStableRequest('/earnings-surprises-bulk', { year }); } // Bulk Income Statement API export async function getBulkIncomeStatement(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise { return fmpStableRequest('/income-statement-bulk', { year, period }); } // Bulk Income Statement Growth API export async function getBulkIncomeStatementGrowth(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise> { return fmpStableRequest('/income-statement-growth-bulk', { year, period }); } // Bulk Balance Sheet API export async function getBulkBalanceSheet(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise { return fmpStableRequest('/balance-sheet-statement-bulk', { year, period }); } // Bulk Balance Sheet Growth API export async function getBulkBalanceSheetGrowth(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise> { return fmpStableRequest('/balance-sheet-statement-growth-bulk', { year, period }); } // Bulk Cash Flow Statement API export async function getBulkCashFlowStatement(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise { return fmpStableRequest('/cash-flow-statement-bulk', { year, period }); } // Bulk Cash Flow Statement Growth API export async function getBulkCashFlowStatementGrowth(year: number, period: 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY'): Promise> { return fmpStableRequest('/cash-flow-statement-growth-bulk', { year, period }); } // EOD Bulk API export async function getEODBulk(date: string): Promise> { return fmpStableRequest('/eod-bulk', { date }); }