diff --git a/.changeset/api-compliance-v2.md b/.changeset/api-compliance-v2.md new file mode 100644 index 0000000..40501bf --- /dev/null +++ b/.changeset/api-compliance-v2.md @@ -0,0 +1,102 @@ +--- +"fmp-node-sdk": major +--- + +## Breaking Changes + +### API Migration: v3/v4 → Stable API + +**This is a complete API migration.** The SDK now uses FMP's new stable API instead of the legacy v3/v4 endpoints. + +- Base URL changed from `https://financialmodelingprep.com/api` to `https://financialmodelingprep.com/stable` +- All endpoint paths have been updated to match the stable API specification +- Path parameters converted to query parameters (e.g., `/v3/profile/AAPL` → `/profile?symbol=AAPL`) + +If you were customizing the `baseUrl` in your config, you'll need to update it. + +### Endpoint Changes + +All endpoints have been migrated. Examples of changes: + +| Resource | Old Endpoint | New Endpoint | +|----------|-------------|--------------| +| Company | `v3/profile/{symbol}` | `profile?symbol=` | +| Company | `v3/quote/{symbol}` | `quote?symbol=` | +| Company | `v3/search` | `search-symbol`, `search-name` | +| Analyst | `v3/analyst-estimates` | `analyst-estimates` | +| Analyst | `v4/price-target` | `price-target` | +| Analyst | `v3/grade` | `grades` | +| Bulk | `v4/profile/all` | `profile-bulk` | +| Bulk | `v4/dcf` | `dcf-bulk` | +| Financials | `v3/income-statement/{symbol}` | `income-statement?symbol=` | +| Market | `v3/historical-price-full/{symbol}` | `historical-price-eod/full?symbol=` | + +### Method Signature Changes + +- `CompanyResource.search()` is now deprecated, use `searchSymbol()` or `searchName()` +- `CompanyResource.getDelistedCompanies(limit?)` now takes `(page, limit)` parameters +- `BulkResource.getAllProfiles()` now takes optional `part` parameter for pagination +- `BulkResource.getAllETFHoldings()` now takes optional `part` parameter for pagination +- `CommoditiesResource.getHistoricalPrices()` now returns `HistoricalPrice[]` instead of `{ historical: HistoricalPrice[] }` + +### Type Changes + +#### DCFValuation and LeveredDCF +- Renamed `'Stock Price'` property to `stockPrice` + +#### Quote type - Nullable fields +The following fields are now nullable to accurately reflect the API response: +- `marketCap`: `number` → `number | null` +- `priceAvg50`: `number` → `number | null` +- `priceAvg200`: `number` → `number | null` +- `eps`: `number` → `number | null` +- `pe`: `number` → `number | null` +- `earningsAnnouncement`: `string` → `string | null` +- `sharesOutstanding`: `number` → `number | null` + +#### EarningsSurprise type +- `actualEarningResult`: `number` → `number | null` +- `estimatedEarning`: `number` → `number | null` + +## New Features + +### NewsResource +- `getAvailableTranscriptSymbols()` - Get symbols with available earnings call transcripts +- `searchPressReleases(query, limit)` - Search press releases +- `searchStockNews(query, limit)` - Search stock news +- `searchCryptoNews(query, limit)` - Search crypto news +- `searchForexNews(query, limit)` - Search forex news + +### InsiderResource +- `getHolderPerformanceSummary(cik, date)` - 13F portfolio holdings performance +- `getIndustryPerformanceSummary(cik, date)` - 13F industry portfolio holdings performance + +### AnalystResource +- `getGradesSummary(symbol)` - Analyst grades summary + +### ValuationResource +- `getCustomLeveredDCF(symbol)` - Custom levered DCF valuation + +### CompanyResource +- `searchSymbol(query, limit, exchange)` - Search by symbol +- `searchName(query, limit, exchange)` - Search by company name +- `getBatchAftermarketTrades(symbols)` - Batch aftermarket trades +- `getETFList()` - List of all ETFs +- `getMutualFundList()` - List of all mutual funds + +## New Types +- `PortfolioHoldingsSummary` - 13F portfolio holdings summary +- `IndustryPortfolioHoldingsSummary` - 13F industry portfolio holdings summary +- `FundListItem` - ETF/Mutual fund list item +- `QuoteShort` - Simplified quote data +- `AftermarketTrade` - Aftermarket trade data +- `AftermarketQuote` - Aftermarket quote data +- `PriceChange` - Stock price change data + +## Migration Guide + +1. **Update base URL** (if customizing): Change from `/api` to `/stable` +2. **Update search calls**: Replace `.search()` with `.searchSymbol()` or `.searchName()` +3. **Handle nullable fields**: Add null checks for Quote fields that are now nullable +4. **Update DCF access**: Change `result['Stock Price']` to `result.stockPrice` +5. **Update commodity historical**: Handle direct array return instead of `{ historical: [] }` diff --git a/src/client.ts b/src/client.ts index 4bfd451..5f4a647 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,7 +6,7 @@ import { FMPAPIError } from './errors/index.js'; * Default configuration values */ const DEFAULT_CONFIG = { - baseUrl: 'https://financialmodelingprep.com/api', + baseUrl: 'https://financialmodelingprep.com/stable', timeout: 30000, retries: 3, } as const; diff --git a/src/index.ts b/src/index.ts index d42b060..2094e80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,14 +146,15 @@ export type { StockScreenerParams, StockScreenerResult, ExchangeSymbol, + // Financial statement growth types + IncomeStatementGrowth, + BalanceSheetGrowth, + CashFlowStatementGrowth, } from './types/index.js'; // Export bulk types export type { EarningsSurprise, - IncomeStatementGrowth, - BalanceSheetGrowth, - CashFlowStatementGrowth, EODPrice, } from './resources/bulk.js'; diff --git a/src/resources/analyst.ts b/src/resources/analyst.ts index fc9dd44..8c97fd7 100644 --- a/src/resources/analyst.ts +++ b/src/resources/analyst.ts @@ -28,10 +28,15 @@ export class AnalystResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { symbol: symbol.toUpperCase(), period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get('v3/analyst-estimates', { searchParams: params }); + return this.client.get('analyst-estimates', { + searchParams: params, + }); } /** @@ -39,7 +44,7 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getPriceTargets(symbol: string): Promise { - return this.client.get(`v4/price-target`, { + return this.client.get('price-target', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -49,10 +54,9 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getPriceTargetSummary(symbol: string): Promise { - const result = await this.client.get( - `v4/price-target-summary`, - { searchParams: { symbol: symbol.toUpperCase() } } - ); + const result = await this.client.get('price-target-summary', { + searchParams: { symbol: symbol.toUpperCase() }, + }); return result[0]!; } @@ -61,10 +65,9 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getPriceTargetConsensus(symbol: string): Promise { - const result = await this.client.get( - `v4/price-target-consensus`, - { searchParams: { symbol: symbol.toUpperCase() } } - ); + const result = await this.client.get('price-target-consensus', { + searchParams: { symbol: symbol.toUpperCase() }, + }); return result[0]!; } @@ -73,7 +76,9 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getRecommendations(symbol: string): Promise { - return this.client.get(`v3/analyst-stock-recommendations/${symbol.toUpperCase()}`); + return this.client.get('analyst-stock-recommendations', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -85,7 +90,9 @@ export class AnalystResource { const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get('v3/grade', { searchParams: params }); + return this.client.get('grades', { + searchParams: params, + }); } /** @@ -93,10 +100,9 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getUpgradesDowngradesConsensus(symbol: string): Promise { - const result = await this.client.get( - `v4/upgrades-downgrades-consensus`, - { searchParams: { symbol: symbol.toUpperCase() } } - ); + const result = await this.client.get('grades-consensus', { + searchParams: { symbol: symbol.toUpperCase() }, + }); return result[0]!; } @@ -105,9 +111,9 @@ export class AnalystResource { * @param symbol - Stock symbol */ async getRatingsSnapshot(symbol: string): Promise { - const result = await this.client.get( - `v3/rating/${symbol.toUpperCase()}` - ); + const result = await this.client.get('rating', { + searchParams: { symbol: symbol.toUpperCase() }, + }); return result[0]!; } @@ -117,8 +123,21 @@ export class AnalystResource { * @param limit - Number of results */ async getHistoricalGrades(symbol: string, limit?: number): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get(`v3/historical-rating/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('grades-historical', { + searchParams: params, + }); + } + + /** + * Get stock grades summary + * @param symbol - Stock symbol + */ + async getGradesSummary(symbol: string): Promise { + const result = await this.client.get('grades-summary', { + searchParams: { symbol: symbol.toUpperCase() }, + }); + return result[0]!; } } diff --git a/src/resources/bulk.ts b/src/resources/bulk.ts index 3652f14..d86022e 100644 --- a/src/resources/bulk.ts +++ b/src/resources/bulk.ts @@ -14,6 +14,9 @@ import type { IncomeStatement, BalanceSheet, CashFlowStatement, + IncomeStatementGrowth, + BalanceSheetGrowth, + CashFlowStatementGrowth, } from '../types/index.js'; /** @@ -22,130 +25,8 @@ import type { export interface EarningsSurprise { symbol: string; date: string; - actualEarningResult: number; - estimatedEarning: number; -} - -/** - * Income statement growth - */ -export interface IncomeStatementGrowth { - date: string; - symbol: string; - period: string; - growthRevenue: number; - growthCostOfRevenue: number; - growthGrossProfit: number; - growthGrossProfitRatio: number; - growthResearchAndDevelopmentExpenses: number; - growthGeneralAndAdministrativeExpenses: number; - growthSellingAndMarketingExpenses: number; - growthOtherExpenses: number; - growthOperatingExpenses: number; - growthCostAndExpenses: number; - growthInterestExpense: number; - growthDepreciationAndAmortization: number; - growthEBITDA: number; - growthEBITDARatio: number; - growthOperatingIncome: number; - growthOperatingIncomeRatio: number; - growthTotalOtherIncomeExpensesNet: number; - growthIncomeBeforeTax: number; - growthIncomeBeforeTaxRatio: number; - growthIncomeTaxExpense: number; - growthNetIncome: number; - growthNetIncomeRatio: number; - growthEPS: number; - growthEPSDiluted: number; - growthWeightedAverageShsOut: number; - growthWeightedAverageShsOutDil: number; -} - -/** - * Balance sheet growth - */ -export interface BalanceSheetGrowth { - date: string; - symbol: string; - period: string; - growthCashAndCashEquivalents: number; - growthShortTermInvestments: number; - growthCashAndShortTermInvestments: number; - growthNetReceivables: number; - growthInventory: number; - growthOtherCurrentAssets: number; - growthTotalCurrentAssets: number; - growthPropertyPlantEquipmentNet: number; - growthGoodwill: number; - growthIntangibleAssets: number; - growthGoodwillAndIntangibleAssets: number; - growthLongTermInvestments: number; - growthTaxAssets: number; - growthOtherNonCurrentAssets: number; - growthTotalNonCurrentAssets: number; - growthOtherAssets: number; - growthTotalAssets: number; - growthAccountPayables: number; - growthShortTermDebt: number; - growthTaxPayables: number; - growthDeferredRevenue: number; - growthOtherCurrentLiabilities: number; - growthTotalCurrentLiabilities: number; - growthLongTermDebt: number; - growthDeferredRevenueNonCurrent: number; - growthDeferrredTaxLiabilitiesNonCurrent: number; - growthOtherNonCurrentLiabilities: number; - growthTotalNonCurrentLiabilities: number; - growthOtherLiabilities: number; - growthTotalLiabilities: number; - growthCommonStock: number; - growthRetainedEarnings: number; - growthAccumulatedOtherComprehensiveIncomeLoss: number; - growthOthertotalStockholdersEquity: number; - growthTotalStockholdersEquity: number; - growthTotalLiabilitiesAndStockholdersEquity: number; - growthTotalInvestments: number; - growthTotalDebt: number; - growthNetDebt: number; -} - -/** - * Cash flow statement growth - */ -export interface CashFlowStatementGrowth { - date: string; - symbol: string; - period: string; - growthNetIncome: number; - growthDepreciationAndAmortization: number; - growthDeferredIncomeTax: number; - growthStockBasedCompensation: number; - growthChangeInWorkingCapital: number; - growthAccountsReceivables: number; - growthInventory: number; - growthAccountsPayables: number; - growthOtherWorkingCapital: number; - growthOtherNonCashItems: number; - growthNetCashProvidedByOperatingActivites: number; - growthInvestmentsInPropertyPlantAndEquipment: number; - growthAcquisitionsNet: number; - growthPurchasesOfInvestments: number; - growthSalesMaturitiesOfInvestments: number; - growthOtherInvestingActivites: number; - growthNetCashUsedForInvestingActivites: number; - growthDebtRepayment: number; - growthCommonStockIssued: number; - growthCommonStockRepurchased: number; - growthDividendsPaid: number; - growthOtherFinancingActivites: number; - growthNetCashUsedProvidedByFinancingActivities: number; - growthEffectOfForexChangesOnCash: number; - growthNetChangeInCash: number; - growthCashAtEndOfPeriod: number; - growthCashAtBeginningOfPeriod: number; - growthOperatingCashFlow: number; - growthCapitalExpenditure: number; - growthFreeCashFlow: number; + actualEarningResult: number | null; + estimatedEarning: number | null; } /** @@ -172,9 +53,12 @@ export class BulkResource { /** * Get all company profiles (bulk) * Returns profiles for all available symbols + * @param part - Part number for pagination (default: 0) */ - async getAllProfiles(): Promise { - return this.client.get('v4/profile/all'); + async getAllProfiles(part = 0): Promise { + return this.client.get('profile-bulk', { + searchParams: { part }, + }); } /** @@ -182,7 +66,7 @@ export class BulkResource { * Returns the latest rating for all symbols */ async getAllRatings(): Promise { - return this.client.get('v4/rating'); + return this.client.get('rating-bulk'); } /** @@ -190,7 +74,7 @@ export class BulkResource { * Returns DCF valuations for all symbols */ async getAllDCF(): Promise { - return this.client.get('v4/dcf'); + return this.client.get('dcf-bulk'); } /** @@ -198,7 +82,7 @@ export class BulkResource { * Returns Altman Z-Score and Piotroski Score for all symbols */ async getAllScores(): Promise { - return this.client.get('v4/score'); + return this.client.get('scores-bulk'); } /** @@ -206,15 +90,18 @@ export class BulkResource { * Returns price targets for all symbols */ async getAllPriceTargets(): Promise { - return this.client.get('v4/price-target'); + return this.client.get('price-target-summary-bulk'); } /** * Get all ETF holdings (bulk) * Returns ETF holdings data for all ETF symbols + * @param part - Part number for pagination (default: 1) */ - async getAllETFHoldings(): Promise { - return this.client.get('v4/etf-holder'); + async getAllETFHoldings(part = 1): Promise { + return this.client.get('etf-holder-bulk', { + searchParams: { part }, + }); } /** @@ -222,7 +109,7 @@ export class BulkResource { * Returns analyst upgrades and downgrades for all symbols */ async getAllUpgradesDowngrades(): Promise { - return this.client.get('v4/upgrades-downgrades'); + return this.client.get('upgrades-downgrades-consensus-bulk'); } /** @@ -230,7 +117,7 @@ export class BulkResource { * Returns trailing twelve months key metrics for all symbols */ async getAllKeyMetricsTTM(): Promise { - return this.client.get('v3/key-metrics-ttm'); + return this.client.get('key-metrics-ttm-bulk'); } /** @@ -238,7 +125,7 @@ export class BulkResource { * Returns trailing twelve months financial ratios for all symbols */ async getAllRatiosTTM(): Promise { - return this.client.get('v3/ratios-ttm'); + return this.client.get('ratios-ttm-bulk'); } /** @@ -246,7 +133,7 @@ export class BulkResource { * Returns peer companies for all symbols */ async getAllPeers(): Promise { - return this.client.get('v4/stock_peers'); + return this.client.get('peers-bulk'); } /** @@ -254,7 +141,7 @@ export class BulkResource { * Returns earnings surprises (actual vs estimated) for all symbols */ async getAllEarningsSurprises(): Promise { - return this.client.get('v3/earnings-surprises'); + return this.client.get('earnings-surprises-bulk'); } /** @@ -266,7 +153,7 @@ export class BulkResource { async getAllIncomeStatements(period: Period = Period.Annual, year?: number): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/income-statement', { searchParams: params }); + return this.client.get('income-statement-bulk', { searchParams: params }); } /** @@ -281,7 +168,7 @@ export class BulkResource { ): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/income-statement-growth', { searchParams: params }); + return this.client.get('income-statement-growth-bulk', { searchParams: params }); } /** @@ -293,7 +180,7 @@ export class BulkResource { async getAllBalanceSheets(period: Period = Period.Annual, year?: number): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/balance-sheet-statement', { searchParams: params }); + return this.client.get('balance-sheet-statement-bulk', { searchParams: params }); } /** @@ -308,7 +195,7 @@ export class BulkResource { ): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/balance-sheet-statement-growth', { searchParams: params }); + return this.client.get('balance-sheet-statement-growth-bulk', { searchParams: params }); } /** @@ -320,7 +207,7 @@ export class BulkResource { async getAllCashFlowStatements(period: Period = Period.Annual, year?: number): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/cash-flow-statement', { searchParams: params }); + return this.client.get('cash-flow-statement-bulk', { searchParams: params }); } /** @@ -335,7 +222,7 @@ export class BulkResource { ): Promise { const params: Record = { period }; if (year) params.year = year; - return this.client.get('v3/cash-flow-statement-growth', { searchParams: params }); + return this.client.get('cash-flow-statement-growth-bulk', { searchParams: params }); } /** @@ -344,7 +231,7 @@ export class BulkResource { * @param date - Date in YYYY-MM-DD format */ async getBatchEODPrices(date: string): Promise { - return this.client.get('v4/batch-request-end-of-day-prices', { searchParams: { date } }); + return this.client.get('eod-bulk', { searchParams: { date } }); } /** @@ -354,6 +241,6 @@ export class BulkResource { * @param to - End date in YYYY-MM-DD format */ async getBatchEODPricesRange(from: string, to: string): Promise { - return this.client.get('v4/batch-request-end-of-day-prices', { searchParams: { from, to } }); + return this.client.get('eod-bulk', { searchParams: { from, to } }); } } diff --git a/src/resources/commodities.ts b/src/resources/commodities.ts index 18c15af..624a60b 100644 --- a/src/resources/commodities.ts +++ b/src/resources/commodities.ts @@ -18,7 +18,7 @@ export class CommoditiesResource { * Get commodities list */ async getList(): Promise { - return this.client.get('v3/symbol/available-commodities'); + return this.client.get('commodities-list'); } /** @@ -26,7 +26,9 @@ export class CommoditiesResource { * @param symbol - Commodity symbol (e.g., "GCUSD" for Gold) */ async getQuote(symbol: string): Promise { - return this.client.get(`v3/quote/${symbol.toUpperCase()}`); + return this.client.get('quote', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -34,14 +36,16 @@ export class CommoditiesResource { * @param symbol - Commodity symbol */ async getQuoteShort(symbol: string): Promise[]> { - return this.client.get[]>(`v3/quote-short/${symbol.toUpperCase()}`); + return this.client.get[]>('quote-short', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get all commodity quotes */ async getAllQuotes(): Promise { - return this.client.get('v3/quotes/commodity'); + return this.client.get('batch-commodity-quotes'); } /** @@ -54,15 +58,14 @@ export class CommoditiesResource { symbol: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { - const params: Record = {}; + ): Promise { + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/full', { + searchParams: params, + }); } /** @@ -76,14 +79,13 @@ export class CommoditiesResource { from?: string, to?: string ): Promise<{ date: string; close: number }[]> { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ date: string; close: number }[]>( - `v3/historical-chart/line/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get<{ date: string; close: number }[]>('historical-price-eod/light', { + searchParams: params, + }); } /** @@ -99,13 +101,12 @@ export class CommoditiesResource { from?: string, to?: string ): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/${interval}/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get(`historical-chart/${interval}`, { + searchParams: params, + }); } } diff --git a/src/resources/company.ts b/src/resources/company.ts index 1d1ec51..7200c19 100644 --- a/src/resources/company.ts +++ b/src/resources/company.ts @@ -20,6 +20,11 @@ import type { ExchangeInfo, SectorIndustry, TradableSymbol, + QuoteShort, + AftermarketTrade, + AftermarketQuote, + PriceChange, + FundListItem, } from '../types/index.js'; /** @@ -34,7 +39,9 @@ export class CompanyResource { * @param symbol - Stock symbol (e.g., "AAPL") */ async getProfile(symbol: string): Promise { - return this.client.get(`v3/profile/${symbol.toUpperCase()}`); + return this.client.get('profile', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -42,7 +49,9 @@ export class CompanyResource { * @param symbol - Stock symbol (e.g., "AAPL") */ async getQuote(symbol: string): Promise { - return this.client.get(`v3/quote/${symbol.toUpperCase()}`); + return this.client.get('quote', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -51,14 +60,16 @@ export class CompanyResource { */ async getQuotes(symbols: string[]): Promise { const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); - return this.client.get(`v3/quote/${symbolsParam}`); + return this.client.get('batch-quote', { + searchParams: { symbols: symbolsParam }, + }); } /** * Get all available trading symbols */ async getSymbolsList(): Promise { - return this.client.get('v3/stock/list'); + return this.client.get('stock-list'); } /** @@ -66,16 +77,37 @@ export class CompanyResource { * @param exchange - Exchange name (e.g., "NASDAQ", "NYSE") */ async getExchangeSymbols(exchange: string): Promise { - return this.client.get(`v3/symbol/${exchange.toUpperCase()}`); + return this.client.get('stock-list', { + searchParams: { exchange: exchange.toUpperCase() }, + }); } /** - * Search for companies by query + * Search for companies by symbol query * @param query - Search query * @param limit - Maximum number of results * @param exchange - Filter by exchange (optional) */ - async search(query: string, limit = 10, exchange?: string): Promise { + async searchSymbol(query: string, limit = 10, exchange?: string): Promise { + const params: Record = { + query, + limit, + }; + + if (exchange) { + params.exchange = exchange; + } + + return this.client.get('search-symbol', { searchParams: params }); + } + + /** + * Search for companies by name query + * @param query - Search query + * @param limit - Maximum number of results + * @param exchange - Filter by exchange (optional) + */ + async searchName(query: string, limit = 10, exchange?: string): Promise { const params: Record = { query, limit, @@ -85,7 +117,18 @@ export class CompanyResource { params.exchange = exchange; } - return this.client.get('v3/search', { searchParams: params }); + return this.client.get('search-name', { searchParams: params }); + } + + /** + * Search for companies by query (alias for searchSymbol) + * @param query - Search query + * @param limit - Maximum number of results + * @param exchange - Filter by exchange (optional) + * @deprecated Use searchSymbol or searchName instead + */ + async search(query: string, limit = 10, exchange?: string): Promise { + return this.searchSymbol(query, limit, exchange); } /** @@ -93,7 +136,9 @@ export class CompanyResource { * @param cik - Central Index Key */ async getProfileByCIK(cik: string): Promise { - return this.client.get(`v3/profile/${cik}`); + return this.client.get('profile-cik', { + searchParams: { cik }, + }); } /** @@ -101,7 +146,9 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getCompanyNotes(symbol: string): Promise { - return this.client.get(`v4/company-notes`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('company-notes', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -109,17 +156,20 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getStockPeers(symbol: string): Promise { - return this.client.get(`v4/stock_peers`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('stock-peers', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get delisted companies + * @param page - Page number * @param limit - Maximum number of results */ - async getDelistedCompanies(limit?: number): Promise { - const params: Record = {}; - if (limit) params.limit = limit; - return this.client.get('v3/delisted-companies', { searchParams: params }); + async getDelistedCompanies(page = 0, limit = 100): Promise { + return this.client.get('delisted-companies', { + searchParams: { page, limit }, + }); } /** @@ -127,7 +177,9 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getEmployeeCount(symbol: string): Promise { - return this.client.get(`v4/employee_count`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('employee-count', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -135,10 +187,9 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getHistoricalEmployeeCount(symbol: string): Promise { - return this.client.get( - `v4/historical/employee_count`, - { searchParams: { symbol: symbol.toUpperCase() } } - ); + return this.client.get('historical-employee-count', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -146,7 +197,9 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getMarketCap(symbol: string): Promise { - return this.client.get(`v3/market-capitalization/${symbol.toUpperCase()}`); + return this.client.get('market-capitalization', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -155,7 +208,9 @@ export class CompanyResource { */ async getBatchMarketCap(symbols: string[]): Promise { const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); - return this.client.get(`v3/market-capitalization/${symbolsParam}`); + return this.client.get('market-capitalization-batch', { + searchParams: { symbols: symbolsParam }, + }); } /** @@ -166,7 +221,9 @@ export class CompanyResource { async getHistoricalMarketCap(symbol: string, limit?: number): Promise { const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get(`v3/historical-market-capitalization/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('historical-market-capitalization', { + searchParams: params, + }); } /** @@ -174,21 +231,31 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getSharesFloat(symbol: string): Promise { - return this.client.get(`v4/shares_float`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('shares-float', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get all shares float + * @param page - Page number + * @param limit - Maximum number of results */ - async getAllSharesFloat(): Promise { - return this.client.get('v4/shares_float/all'); + async getAllSharesFloat(page = 0, limit = 1000): Promise { + return this.client.get('shares-float-all', { + searchParams: { page, limit }, + }); } /** * Get latest M&A transactions + * @param page - Page number + * @param limit - Maximum number of results */ - async getMergerAcquisitions(): Promise { - return this.client.get('v4/mergers-acquisitions-rss-feed'); + async getMergerAcquisitions(page = 0, limit = 100): Promise { + return this.client.get('mergers-acquisitions-latest', { + searchParams: { page, limit }, + }); } /** @@ -196,7 +263,9 @@ export class CompanyResource { * @param name - Company name */ async searchMergerAcquisitions(name: string): Promise { - return this.client.get('v4/mergers-acquisitions/search', { searchParams: { name } }); + return this.client.get('mergers-acquisitions-search', { + searchParams: { name }, + }); } /** @@ -204,7 +273,9 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getExecutives(symbol: string): Promise { - return this.client.get(`v3/key-executives/${symbol.toUpperCase()}`); + return this.client.get('key-executives', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -212,173 +283,202 @@ export class CompanyResource { * @param symbol - Stock symbol */ async getExecutiveCompensation(symbol: string): Promise { - return this.client.get(`v4/governance/executive_compensation`, { + return this.client.get('governance-executive-compensation', { searchParams: { symbol: symbol.toUpperCase() }, }); } /** * Get compensation benchmark by industry - * @param year - Year + * @param year - Year (optional) */ - async getCompensationBenchmark(year: number): Promise { - return this.client.get('v4/executive-compensation-benchmark', { searchParams: { year } }); + async getCompensationBenchmark(year?: number): Promise { + const params: Record = {}; + if (year) params.year = year; + return this.client.get('executive-compensation-benchmark', { + searchParams: params, + }); } /** * Get symbols with financial statements */ async getFinancialStatementSymbols(): Promise { - return this.client.get('v3/financial-statement-symbol-lists'); + return this.client.get('financial-statement-symbol-list'); } /** * Get CIK list + * @param page - Page number + * @param limit - Maximum number of results */ - async getCIKList(): Promise { - return this.client.get('v3/cik_list'); + async getCIKList(page = 0, limit = 1000): Promise { + return this.client.get('cik-list', { + searchParams: { page, limit }, + }); } /** * Get symbol changes */ async getSymbolChanges(): Promise { - return this.client.get('v4/symbol_change'); + return this.client.get('symbol-change'); } /** * Get ETF symbols */ async getETFSymbols(): Promise { - return this.client.get('v3/etf/list'); + return this.client.get('etf-list'); } /** * Get actively trading symbols */ async getActivelyTrading(): Promise { - return this.client.get('v3/available-traded/list'); - } - - /** - * Get available earnings transcripts symbols - */ - async getEarningsTranscriptsSymbols(): Promise { - return this.client.get('v4/earning_call_transcript'); + return this.client.get('actively-trading-list'); } /** * Get list of available exchanges */ async getExchanges(): Promise { - return this.client.get('v3/exchanges-list'); + return this.client.get('available-exchanges'); } /** * Get list of available sectors */ async getSectors(): Promise { - return this.client.get('v3/sector-list'); + return this.client.get('available-sectors'); } /** * Get list of available industries */ async getIndustries(): Promise { - return this.client.get('v3/industry-list'); + return this.client.get('available-industries'); } /** * Get list of available countries */ async getCountries(): Promise { - return this.client.get('v3/get-all-countries'); + return this.client.get('available-countries'); } /** * Get short quote (simplified quote data) * @param symbol - Stock symbol */ - async getQuoteShort(symbol: string): Promise[]> { - return this.client.get[]>(`v3/quote-short/${symbol.toUpperCase()}`); + async getQuoteShort(symbol: string): Promise { + return this.client.get('quote-short', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get aftermarket trade price * @param symbol - Stock symbol */ - async getAftermarketTrade(symbol: string): Promise[]> { - return this.client.get[]>(`v4/pre-post-market-trade/${symbol.toUpperCase()}`); + async getAftermarketTrade(symbol: string): Promise { + return this.client.get('aftermarket-trade', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get aftermarket quote * @param symbol - Stock symbol */ - async getAftermarketQuote(symbol: string): Promise[]> { - return this.client.get[]>(`v4/pre-post-market/${symbol.toUpperCase()}`); + async getAftermarketQuote(symbol: string): Promise { + return this.client.get('aftermarket-quote', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get price change * @param symbol - Stock symbol */ - async getPriceChange(symbol: string): Promise[]> { - return this.client.get[]>(`v3/stock-price-change/${symbol.toUpperCase()}`); + async getPriceChange(symbol: string): Promise { + return this.client.get('stock-price-change', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get batch short quotes * @param symbols - Array of stock symbols */ - async getBatchQuotesShort(symbols: string[]): Promise[]> { + async getBatchQuotesShort(symbols: string[]): Promise { const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); - return this.client.get[]>(`v3/quote-short/${symbolsParam}`); - } - - /** - * Get batch aftermarket trades - * @param symbols - Array of stock symbols - */ - async getBatchAftermarketTrades(symbols: string[]): Promise[]> { - const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); - return this.client.get[]>(`v4/pre-post-market-trade/${symbolsParam}`); + return this.client.get('quote-short', { + searchParams: { symbol: symbolsParam }, + }); } /** * Get batch aftermarket quotes * @param symbols - Array of stock symbols */ - async getBatchAftermarketQuotes(symbols: string[]): Promise[]> { + async getBatchAftermarketQuotes(symbols: string[]): Promise { const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); - return this.client.get[]>(`v4/pre-post-market/${symbolsParam}`); + return this.client.get('batch-aftermarket-quote', { + searchParams: { symbols: symbolsParam }, + }); } /** * Get mutual fund quotes */ - async getMutualFundQuotes(): Promise[]> { - return this.client.get[]>('v3/quotes/mutual_fund'); + async getMutualFundQuotes(): Promise { + return this.client.get('batch-mutualfund-quotes'); } /** * Get ETF quotes */ - async getETFQuotes(): Promise[]> { - return this.client.get[]>('v3/quotes/etf'); + async getETFQuotes(): Promise { + return this.client.get('batch-etf-quotes'); } /** * Get commodities quotes */ - async getCommoditiesQuotes(): Promise[]> { - return this.client.get[]>('v3/quotes/commodity'); + async getCommoditiesQuotes(): Promise { + return this.client.get('batch-commodity-quotes'); } /** * Get index quotes */ - async getIndexQuotes(): Promise[]> { - return this.client.get[]>('v3/quotes/index'); + async getIndexQuotes(): Promise { + return this.client.get('batch-index-quotes'); + } + + /** + * Get batch aftermarket trades for multiple symbols + * @param symbols - Array of stock symbols + */ + async getBatchAftermarketTrades(symbols: string[]): Promise { + const symbolsParam = symbols.map(s => s.toUpperCase()).join(','); + return this.client.get('batch-aftermarket-trade', { + searchParams: { symbols: symbolsParam }, + }); + } + + /** + * Get ETF list + */ + async getETFList(): Promise { + return this.client.get('etf-list'); + } + + /** + * Get mutual fund list + */ + async getMutualFundList(): Promise { + return this.client.get('mutual-fund-list'); } } diff --git a/src/resources/cot.ts b/src/resources/cot.ts index 9d01384..00403d7 100644 --- a/src/resources/cot.ts +++ b/src/resources/cot.ts @@ -18,7 +18,7 @@ export class COTResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/commitment_of_traders_report', { searchParams: params }); + return this.client.get('commitment-of-traders-report', { searchParams: params }); } /** @@ -32,13 +32,13 @@ export class COTResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/commitment_of_traders_report_analysis', { searchParams: params }); + return this.client.get('commitment-of-traders-analysis', { searchParams: params }); } /** * Get list of available COT symbols */ async getSymbols(): Promise { - return this.client.get('v4/commitment_of_traders_report/list'); + return this.client.get('commitment-of-traders-list'); } } diff --git a/src/resources/economics.ts b/src/resources/economics.ts index 715b728..123e674 100644 --- a/src/resources/economics.ts +++ b/src/resources/economics.ts @@ -50,7 +50,7 @@ export class EconomicsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/treasury', { searchParams: params }); + return this.client.get('treasury-rates', { searchParams: params }); } /** @@ -68,7 +68,7 @@ export class EconomicsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/economic', { searchParams: params }); + return this.client.get('economic-indicators', { searchParams: params }); } /** @@ -120,6 +120,6 @@ export class EconomicsResource { * Get market risk premium */ async getMarketRiskPremium(): Promise { - return this.client.get('v4/market_risk_premium'); + return this.client.get('market-risk-premium'); } } diff --git a/src/resources/esg.ts b/src/resources/esg.ts index 98aba4d..b127c94 100644 --- a/src/resources/esg.ts +++ b/src/resources/esg.ts @@ -14,10 +14,9 @@ export class ESGResource { * @param symbol - Stock symbol (e.g., "AAPL") */ async getESGData(symbol: string): Promise { - return this.client.get( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: symbol.toUpperCase() } } - ); + return this.client.get('esg-disclosures', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -26,10 +25,9 @@ export class ESGResource { * @param symbol - Stock symbol (e.g., "AAPL") */ async getESGRatings(symbol: string): Promise { - return this.client.get( - 'v4/esg-environmental-social-governance-data-ratings', - { searchParams: { symbol: symbol.toUpperCase() } } - ); + return this.client.get('esg-ratings', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -38,9 +36,8 @@ export class ESGResource { * @param year - Year for benchmark data */ async getESGBenchmark(year: number): Promise { - return this.client.get( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year } } - ); + return this.client.get('esg-benchmark', { + searchParams: { year }, + }); } } diff --git a/src/resources/etf.ts b/src/resources/etf.ts index 7abceb9..f8b8b15 100644 --- a/src/resources/etf.ts +++ b/src/resources/etf.ts @@ -6,6 +6,7 @@ import type { ETFCountryWeighting, ETFStockExposure, MutualFundHolder, + FundListItem, } from '../types/index.js'; /** @@ -20,7 +21,9 @@ export class ETFResource { * @param symbol - ETF symbol */ async getHoldings(symbol: string): Promise { - return this.client.get(`v3/etf-holder/${symbol.toUpperCase()}`); + return this.client.get('etf/holdings', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -28,10 +31,8 @@ export class ETFResource { * @param symbol - ETF symbol */ async getInfo(symbol: string): Promise { - return this.client.get(`v4/etf-info`, { - searchParams: { - symbol: symbol.toUpperCase(), - }, + return this.client.get('etf/info', { + searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -40,9 +41,9 @@ export class ETFResource { * @param symbol - ETF symbol */ async getSectorWeightings(symbol: string): Promise { - return this.client.get( - `v3/etf-sector-weightings/${symbol.toUpperCase()}` - ); + return this.client.get('etf/sector-weightings', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -50,9 +51,9 @@ export class ETFResource { * @param symbol - ETF symbol */ async getCountryWeightings(symbol: string): Promise { - return this.client.get( - `v3/etf-country-weightings/${symbol.toUpperCase()}` - ); + return this.client.get('etf/country-weightings', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -60,9 +61,9 @@ export class ETFResource { * @param symbol - Stock symbol */ async getStockExposure(symbol: string): Promise { - return this.client.get( - `v3/etf-stock-exposure/${symbol.toUpperCase()}` - ); + return this.client.get('etf/asset-exposure', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -70,23 +71,23 @@ export class ETFResource { * @param symbol - Stock symbol */ async getMutualFundHolders(symbol: string): Promise { - return this.client.get( - `v3/mutual-fund-holder/${symbol.toUpperCase()}` - ); + return this.client.get('funds/disclosure-holders-latest', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get ETF list */ - async getETFList(): Promise[]> { - return this.client.get[]>('v3/etf/list'); + async getETFList(): Promise { + return this.client.get('etf-list'); } /** * Get available mutual funds */ - async getAvailableMutualFunds(): Promise[]> { - return this.client.get[]>('v3/symbol/available-mutual-funds'); + async getAvailableMutualFunds(): Promise { + return this.client.get('mutual-fund-list'); } /** @@ -94,6 +95,6 @@ export class ETFResource { * Returns the most recent portfolio dates for all ETFs */ async getLatestDisclosures(): Promise> { - return this.client.get>('v4/etf-holdings/portfolio-date'); + return this.client.get>('funds/disclosure-dates'); } } diff --git a/src/resources/events.ts b/src/resources/events.ts index f4cf5bf..6d47c0e 100644 --- a/src/resources/events.ts +++ b/src/resources/events.ts @@ -24,10 +24,12 @@ export class EventsResource { * @param limit - Number of results */ async getEarnings(symbol: string, limit?: number): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get(`v3/historical/earning_calendar/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('earnings', { + searchParams: params, + }); } /** @@ -40,7 +42,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v3/earning_calendar', { searchParams: params }); + return this.client.get('earnings-calendar', { + searchParams: params, + }); } /** @@ -53,7 +57,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/earning-calendar-confirmed', { searchParams: params }); + return this.client.get('earnings-calendar-confirmed', { + searchParams: params, + }); } /** @@ -61,7 +67,9 @@ export class EventsResource { * @param symbol - Stock symbol */ async getDividends(symbol: string): Promise { - return this.client.get(`v3/historical-price-full/stock_dividend/${symbol.toUpperCase()}`); + return this.client.get('dividends', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -74,7 +82,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v3/stock_dividend_calendar', { searchParams: params }); + return this.client.get('dividends-calendar', { + searchParams: params, + }); } /** @@ -82,7 +92,9 @@ export class EventsResource { * @param symbol - Stock symbol */ async getSplits(symbol: string): Promise { - return this.client.get(`v3/historical-price-full/stock_split/${symbol.toUpperCase()}`); + return this.client.get('splits', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -95,7 +107,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v3/stock_split_calendar', { searchParams: params }); + return this.client.get('splits-calendar', { + searchParams: params, + }); } /** @@ -108,7 +122,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v3/ipo_calendar', { searchParams: params }); + return this.client.get('ipos-calendar', { + searchParams: params, + }); } /** @@ -121,7 +137,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/ipo-calendar-prospectus', { searchParams: params }); + return this.client.get('ipos-prospectus', { + searchParams: params, + }); } /** @@ -134,7 +152,9 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v4/ipo-calendar-confirmed', { searchParams: params }); + return this.client.get('ipos-confirmed', { + searchParams: params, + }); } /** @@ -147,6 +167,8 @@ export class EventsResource { if (from) params.from = from; if (to) params.to = to; - return this.client.get('v3/economic_calendar', { searchParams: params }); + return this.client.get('economic-calendar', { + searchParams: params, + }); } } diff --git a/src/resources/financials.ts b/src/resources/financials.ts index 9b9155e..6f6dccc 100644 --- a/src/resources/financials.ts +++ b/src/resources/financials.ts @@ -12,6 +12,12 @@ import type { ReportDate, LatestFinancialStatement, FinancialReportDownload, + EnterpriseValue, + IncomeStatementGrowth, + BalanceSheetGrowth, + CashFlowStatementGrowth, + RevenueProductSegmentation, + RevenueGeographicSegmentation, } from '../types/index.js'; /** @@ -32,13 +38,15 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get( - `v3/income-statement/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('income-statement', { + searchParams: params, + }); } /** @@ -52,13 +60,15 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get( - `v3/balance-sheet-statement/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('balance-sheet-statement', { + searchParams: params, + }); } /** @@ -72,13 +82,15 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get( - `v3/cash-flow-statement/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('cash-flow-statement', { + searchParams: params, + }); } /** @@ -86,8 +98,8 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getIncomeStatementTTM(symbol: string): Promise { - return this.client.get(`v3/income-statement/${symbol.toUpperCase()}`, { - searchParams: { period: 'ttm' }, + return this.client.get('income-statement-ttm', { + searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -96,8 +108,8 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getBalanceSheetTTM(symbol: string): Promise { - return this.client.get(`v3/balance-sheet-statement/${symbol.toUpperCase()}`, { - searchParams: { period: 'ttm' }, + return this.client.get('balance-sheet-statement-ttm', { + searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -106,10 +118,9 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getCashFlowStatementTTM(symbol: string): Promise { - return this.client.get( - `v3/cash-flow-statement/${symbol.toUpperCase()}`, - { searchParams: { period: 'ttm' } } - ); + return this.client.get('cash-flow-statement-ttm', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -123,10 +134,15 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get(`v3/ratios/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('ratios', { + searchParams: params, + }); } /** @@ -134,7 +150,9 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getRatiosTTM(symbol: string): Promise { - return this.client.get(`v3/ratios-ttm/${symbol.toUpperCase()}`); + return this.client.get('ratios-ttm', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -148,10 +166,15 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get(`v3/key-metrics/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('key-metrics', { + searchParams: params, + }); } /** @@ -159,7 +182,9 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getKeyMetricsTTM(symbol: string): Promise { - return this.client.get(`v3/key-metrics-ttm/${symbol.toUpperCase()}`); + return this.client.get('key-metrics-ttm', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -172,11 +197,16 @@ export class FinancialsResource { symbol: string, period: Period = Period.Annual, limit?: number - ): Promise[]> { - const params: Record = { period }; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>(`v3/enterprise-values/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('enterprise-values', { + searchParams: params, + }); } /** @@ -189,14 +219,16 @@ export class FinancialsResource { symbol: string, period: Period = Period.Annual, limit?: number - ): Promise[]> { - const params: Record = { period }; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>( - `v3/income-statement-growth/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('income-statement-growth', { + searchParams: params, + }); } /** @@ -209,14 +241,16 @@ export class FinancialsResource { symbol: string, period: Period = Period.Annual, limit?: number - ): Promise[]> { - const params: Record = { period }; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>( - `v3/balance-sheet-statement-growth/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('balance-sheet-statement-growth', { + searchParams: params, + }); } /** @@ -229,14 +263,16 @@ export class FinancialsResource { symbol: string, period: Period = Period.Annual, limit?: number - ): Promise[]> { - const params: Record = { period }; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>( - `v3/cash-flow-statement-growth/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('cash-flow-statement-growth', { + searchParams: params, + }); } /** @@ -244,8 +280,11 @@ export class FinancialsResource { * @param symbol - Stock symbol * @param period - Period type */ - async getRevenueByProduct(symbol: string, period: Period = Period.Annual): Promise[]> { - return this.client.get[]>(`v4/revenue-product-segmentation`, { + async getRevenueByProduct( + symbol: string, + period: Period = Period.Annual + ): Promise { + return this.client.get('revenue-product-segmentation', { searchParams: { symbol: symbol.toUpperCase(), period, @@ -259,8 +298,11 @@ export class FinancialsResource { * @param symbol - Stock symbol * @param period - Period type */ - async getRevenueByGeography(symbol: string, period: Period = Period.Annual): Promise[]> { - return this.client.get[]>(`v4/revenue-geographic-segmentation`, { + async getRevenueByGeography( + symbol: string, + period: Period = Period.Annual + ): Promise { + return this.client.get('revenue-geographic-segmentation', { searchParams: { symbol: symbol.toUpperCase(), period, @@ -274,7 +316,9 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getFinancialScores(symbol: string): Promise { - return this.client.get(`v4/score`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('financial-scores', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -285,7 +329,9 @@ export class FinancialsResource { async getOwnerEarnings(symbol: string, limit?: number): Promise { const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get('v4/owner_earnings', { searchParams: params }); + return this.client.get('owner-earnings', { + searchParams: params, + }); } /** @@ -299,12 +345,14 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get( - `v3/financial-growth/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('financial-growth', { + searchParams: params, + }); } /** @@ -312,7 +360,7 @@ export class FinancialsResource { * @param symbol - Stock symbol */ async getReportDates(symbol: string): Promise { - return this.client.get('v4/financial-reports-dates', { + return this.client.get('financial-reports-dates', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -328,9 +376,14 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise[]> { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>(`v3/income-statement-as-reported/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get[]>('income-statement-as-reported', { + searchParams: params, + }); } /** @@ -344,9 +397,14 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise[]> { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>(`v3/balance-sheet-statement-as-reported/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get[]>('balance-sheet-statement-as-reported', { + searchParams: params, + }); } /** @@ -360,24 +418,35 @@ export class FinancialsResource { period: Period = Period.Annual, limit?: number ): Promise[]> { - const params: Record = { period }; + const params: Record = { + symbol: symbol.toUpperCase(), + period, + }; if (limit) params.limit = limit; - return this.client.get[]>(`v3/cash-flow-statement-as-reported/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get[]>('cash-flow-statement-as-reported', { + searchParams: params, + }); } /** - * Get full as-reported financials (v3 endpoint) + * Get full as-reported financials * @param symbol - Stock symbol * @param period - Period type */ - async getAsReportedFull(symbol: string, period: Period = Period.Annual): Promise> { - return this.client.get>(`v3/financial-statement-full-as-reported/${symbol.toUpperCase()}`, { - searchParams: { period }, + async getAsReportedFull( + symbol: string, + period: Period = Period.Annual + ): Promise> { + return this.client.get>('financial-statement-full-as-reported', { + searchParams: { + symbol: symbol.toUpperCase(), + period, + }, }); } /** - * Get latest full as-reported financial statements (v4 endpoint) + * Get latest full as-reported financial statements * Returns the most recent complete financial statement as reported to the SEC * @param symbol - Stock symbol * @param period - Period type (FY for annual, Q1-Q4 for quarterly) @@ -386,10 +455,12 @@ export class FinancialsResource { symbol: string, period: Period = Period.Annual ): Promise { - return this.client.get( - `v4/financial-statement-full-as-reported/${symbol.toUpperCase()}`, - { searchParams: { period } } - ); + return this.client.get('financial-statement-full-as-reported', { + searchParams: { + symbol: symbol.toUpperCase(), + period, + }, + }); } /** @@ -403,7 +474,7 @@ export class FinancialsResource { year: number, period: string ): Promise> { - return this.client.get>('v4/financial-reports-json', { + return this.client.get>('financial-reports-json', { searchParams: { symbol: symbol.toUpperCase(), year, @@ -424,7 +495,7 @@ export class FinancialsResource { year: number, period: string ): Promise { - return this.client.get('v4/financial-reports-xlsx', { + return this.client.get('financial-reports-xlsx', { searchParams: { symbol: symbol.toUpperCase(), year, diff --git a/src/resources/fundraisers.ts b/src/resources/fundraisers.ts index e16747c..c51b65f 100644 --- a/src/resources/fundraisers.ts +++ b/src/resources/fundraisers.ts @@ -17,7 +17,9 @@ export class FundraisersResource { * @param page - Page number (default: 0) */ async getLatestCrowdfunding(page = 0): Promise { - return this.client.get('v4/crowdfunding-rss-feed', { searchParams: { page } }); + return this.client.get('crowdfunding-offerings-latest', { + searchParams: { page }, + }); } /** @@ -31,7 +33,7 @@ export class FundraisersResource { if (name) params.name = name; if (cik) params.cik = cik; - return this.client.get('v4/crowdfunding', { searchParams: params }); + return this.client.get('crowdfunding-offerings-search', { searchParams: params }); } /** @@ -40,7 +42,9 @@ export class FundraisersResource { * @param page - Page number (default: 0) */ async getCrowdfundingByCIK(cik: string, page = 0): Promise { - return this.client.get(`v4/crowdfunding/${cik}`, { searchParams: { page } }); + return this.client.get('crowdfunding-offerings', { + searchParams: { cik, page }, + }); } /** @@ -48,7 +52,9 @@ export class FundraisersResource { * @param page - Page number (default: 0) */ async getLatestEquity(page = 0): Promise { - return this.client.get('v4/fundraising-rss-feed', { searchParams: { page } }); + return this.client.get('fundraising-latest', { + searchParams: { page }, + }); } /** @@ -62,7 +68,7 @@ export class FundraisersResource { if (name) params.name = name; if (cik) params.cik = cik; - return this.client.get('v4/fundraising', { searchParams: params }); + return this.client.get('fundraising-search', { searchParams: params }); } /** @@ -71,6 +77,8 @@ export class FundraisersResource { * @param page - Page number (default: 0) */ async getEquityByCIK(cik: string, page = 0): Promise { - return this.client.get(`v4/fundraising/${cik}`, { searchParams: { page } }); + return this.client.get('fundraising', { + searchParams: { cik, page }, + }); } } diff --git a/src/resources/indexes.ts b/src/resources/indexes.ts index 15a3bfe..5633ac2 100644 --- a/src/resources/indexes.ts +++ b/src/resources/indexes.ts @@ -19,42 +19,42 @@ export class IndexesResource { * Get S&P 500 constituents */ async getSP500Constituents(): Promise { - return this.client.get('v3/sp500_constituent'); + return this.client.get('sp500-constituent'); } /** * Get NASDAQ constituents */ async getNASDAQConstituents(): Promise { - return this.client.get('v3/nasdaq_constituent'); + return this.client.get('nasdaq-constituent'); } /** * Get Dow Jones constituents */ async getDowJonesConstituents(): Promise { - return this.client.get('v3/dowjones_constituent'); + return this.client.get('dowjones-constituent'); } /** * Get historical S&P 500 constituents */ async getHistoricalSP500(): Promise { - return this.client.get('v3/historical/sp500_constituent'); + return this.client.get('historical-sp500-constituent'); } /** * Get historical NASDAQ constituents */ async getHistoricalNASDAQ(): Promise { - return this.client.get('v3/historical/nasdaq_constituent'); + return this.client.get('historical-nasdaq-constituent'); } /** * Get historical Dow Jones constituents */ async getHistoricalDowJones(): Promise { - return this.client.get('v3/historical/dowjones_constituent'); + return this.client.get('historical-dowjones-constituent'); } /** @@ -62,7 +62,9 @@ export class IndexesResource { * @param symbol - Index symbol (e.g., "^GSPC" for S&P 500) */ async getQuote(symbol: string): Promise { - return this.client.get(`v3/quote/${symbol.toUpperCase()}`); + return this.client.get('quote', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -70,21 +72,23 @@ export class IndexesResource { * @param symbol - Index symbol */ async getQuoteShort(symbol: string): Promise[]> { - return this.client.get[]>(`v3/quote-short/${symbol.toUpperCase()}`); + return this.client.get[]>('quote-short', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** * Get all index quotes */ async getAllQuotes(): Promise { - return this.client.get('v3/quotes/index'); + return this.client.get('batch-index-quotes'); } /** * Get index list */ async getList(): Promise[]> { - return this.client.get[]>('v3/symbol/available-indexes'); + return this.client.get[]>('index-list'); } /** @@ -97,15 +101,14 @@ export class IndexesResource { symbol: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { - const params: Record = {}; + ): Promise { + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/full', { + searchParams: params, + }); } /** @@ -119,14 +122,13 @@ export class IndexesResource { from?: string, to?: string ): Promise<{ date: string; close: number }[]> { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ date: string; close: number }[]>( - `v3/historical-chart/line/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get<{ date: string; close: number }[]>('historical-price-eod/light', { + searchParams: params, + }); } /** @@ -142,13 +144,12 @@ export class IndexesResource { from?: string, to?: string ): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/${interval}/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get(`historical-chart/${interval}`, { + searchParams: params, + }); } } diff --git a/src/resources/insider.ts b/src/resources/insider.ts index d41a356..b7d21af 100644 --- a/src/resources/insider.ts +++ b/src/resources/insider.ts @@ -12,6 +12,7 @@ import type { IndustryPortfolioHoldingsSummary, SymbolOwnership, IndustryInstitutionalOwnership, + Form4Ownership, } from '../types/index.js'; /** @@ -29,7 +30,9 @@ export class InsiderResource { const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get('v4/insider-trading', { searchParams: params }); + return this.client.get('insider-trading', { + searchParams: params, + }); } /** @@ -37,7 +40,7 @@ export class InsiderResource { * @param symbol - Stock symbol */ async getInsiderStatistics(symbol: string): Promise { - return this.client.get(`v4/insider-roaster-statistic`, { + return this.client.get('insider-roaster-statistic', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -47,7 +50,7 @@ export class InsiderResource { * @param symbol - Stock symbol */ async getInsiderRoster(symbol: string): Promise { - return this.client.get(`v4/insider-roaster`, { + return this.client.get('insider-roaster', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -57,7 +60,9 @@ export class InsiderResource { * @param symbol - Stock symbol */ async getInstitutionalHolders(symbol: string): Promise { - return this.client.get(`v3/institutional-holder/${symbol.toUpperCase()}`); + return this.client.get('institutional-holder', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -66,10 +71,12 @@ export class InsiderResource { * @param date - Filing date (YYYY-MM-DD) */ async get13F(cik: string, date?: string): Promise { - const params: Record = {}; + const params: Record = { cik }; if (date) params.date = date; - return this.client.get(`v3/form-thirteen/${cik}`, { searchParams: params }); + return this.client.get('form-thirteen', { + searchParams: params, + }); } /** @@ -80,7 +87,9 @@ export class InsiderResource { const params: Record = {}; if (symbol) params.symbol = symbol.toUpperCase(); - return this.client.get('v4/senate-trading', { searchParams: params }); + return this.client.get('senate-trading', { + searchParams: params, + }); } /** @@ -91,21 +100,23 @@ export class InsiderResource { const params: Record = {}; if (symbol) params.symbol = symbol.toUpperCase(); - return this.client.get('v4/senate-disclosure', { searchParams: params }); + return this.client.get('house-disclosure', { + searchParams: params, + }); } /** * Get latest Senate trading disclosures from RSS feed */ async getLatestSenateTrades(): Promise { - return this.client.get('v4/senate-trading-rss-feed'); + return this.client.get('senate-trading-rss-feed'); } /** * Get latest House of Representatives trading disclosures from RSS feed */ async getLatestHouseTrades(): Promise { - return this.client.get('v4/senate-disclosure-rss-feed'); + return this.client.get('house-disclosure-rss-feed'); } /** @@ -113,7 +124,7 @@ export class InsiderResource { * @param name - Senator name */ async getSenateTradingByName(name: string): Promise { - return this.client.get('v4/senate-trading', { + return this.client.get('senate-trading', { searchParams: { name }, }); } @@ -123,7 +134,7 @@ export class InsiderResource { * @param name - Representative name */ async getHouseTradingByName(name: string): Promise { - return this.client.get('v4/senate-disclosure', { + return this.client.get('house-disclosure', { searchParams: { name }, }); } @@ -135,7 +146,9 @@ export class InsiderResource { async getLatestInsiderTrades(limit?: number): Promise { const params: Record = {}; if (limit) params.limit = limit; - return this.client.get('v4/insider-trading', { searchParams: params }); + return this.client.get('insider-trading', { + searchParams: params, + }); } /** @@ -146,14 +159,16 @@ export class InsiderResource { async getInsiderTradesByName(name: string, limit?: number): Promise { const params: Record = { reportingName: name }; if (limit) params.limit = limit; - return this.client.get('v4/insider-trading', { searchParams: params }); + return this.client.get('insider-trading', { + searchParams: params, + }); } /** * Get insider transaction types */ async getInsiderTransactionTypes(): Promise<{ transactionType: string }[]> { - return this.client.get<{ transactionType: string }[]>('v4/insider-trading-transaction-type'); + return this.client.get<{ transactionType: string }[]>('insider-trading-transaction-type'); } /** @@ -161,10 +176,12 @@ export class InsiderResource { * @param symbol - Stock symbol * @param limit - Number of results */ - async getForm4Ownership(symbol: string, limit?: number): Promise[]> { + async getForm4Ownership(symbol: string, limit?: number): Promise { const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get[]>('v4/form-four', { searchParams: params }); + return this.client.get('form-four', { + searchParams: params, + }); } /** @@ -177,7 +194,9 @@ export class InsiderResource { if (cik) params.cik = cik; if (page) params.page = page; - return this.client.get('v4/institutional-ownership/portfolio-date', { searchParams: params }); + return this.client.get('institutional-ownership-portfolio-date', { + searchParams: params, + }); } /** @@ -185,7 +204,7 @@ export class InsiderResource { * @param cik - CIK number */ async get13FFilingDates(cik: string): Promise { - return this.client.get('v4/institutional-ownership/portfolio-date', { + return this.client.get('institutional-ownership-portfolio-date', { searchParams: { cik }, }); } @@ -197,11 +216,13 @@ export class InsiderResource { * @param page - Page number for pagination (optional) */ async get13FWithAnalytics(cik: string, date?: string, page?: number): Promise { - const params: Record = {}; + const params: Record = { cik }; if (date) params.date = date; if (page) params.page = page; - return this.client.get(`v4/form-thirteen/${cik}`, { searchParams: params }); + return this.client.get('form-thirteen', { + searchParams: params, + }); } /** @@ -215,7 +236,9 @@ export class InsiderResource { if (date) params.date = date; if (page) params.page = page; - return this.client.get('v4/institutional-ownership/portfolio-holdings-summary', { searchParams: params }); + return this.client.get('institutional-ownership-portfolio-holdings-summary', { + searchParams: params, + }); } /** @@ -229,7 +252,9 @@ export class InsiderResource { if (date) params.date = date; if (page) params.page = page; - return this.client.get('v4/institutional-ownership/industry/portfolio-holdings-summary', { searchParams: params }); + return this.client.get('institutional-ownership-industry-portfolio-holdings-summary', { + searchParams: params, + }); } /** @@ -243,7 +268,9 @@ export class InsiderResource { if (includeCurrentQuarter !== undefined) params.includeCurrentQuarter = includeCurrentQuarter; if (page) params.page = page; - return this.client.get('v4/institutional-ownership/symbol-ownership', { searchParams: params }); + return this.client.get('institutional-ownership-symbol-ownership', { + searchParams: params, + }); } /** @@ -255,6 +282,36 @@ export class InsiderResource { const params: Record = { symbol: symbol.toUpperCase() }; if (page) params.page = page; - return this.client.get('v4/institutional-ownership/institutional-holders/symbol-ownership-percent', { searchParams: params }); + return this.client.get('institutional-ownership-symbol-ownership-percent', { + searchParams: params, + }); + } + + /** + * Get holder performance summary for an institutional investor + * @param cik - CIK number + * @param date - Filing date (YYYY-MM-DD, optional) + */ + async getHolderPerformanceSummary(cik: string, date?: string): Promise { + const params: Record = { cik }; + if (date) params.date = date; + + return this.client.get('institutional-ownership-portfolio-holdings-summary', { + searchParams: params, + }); + } + + /** + * Get industry performance summary for an institutional investor + * @param cik - CIK number + * @param date - Filing date (YYYY-MM-DD, optional) + */ + async getIndustryPerformanceSummary(cik: string, date?: string): Promise { + const params: Record = { cik }; + if (date) params.date = date; + + return this.client.get('institutional-ownership-industry-portfolio-holdings-summary', { + searchParams: params, + }); } } diff --git a/src/resources/market.ts b/src/resources/market.ts index 333796e..1b15e91 100644 --- a/src/resources/market.ts +++ b/src/resources/market.ts @@ -33,7 +33,7 @@ export class MarketResource { constructor(private readonly client: FMPClient) {} /** - * Get historical daily prices for a symbol + * Get historical daily prices for a symbol (full data with OHLCV) * @param symbol - Stock symbol * @param from - Start date (YYYY-MM-DD) * @param to - End date (YYYY-MM-DD) @@ -42,19 +42,46 @@ export class MarketResource { symbol: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { + ): Promise { validateSymbol(symbol); validateDateRange(from, to); - const params: Record = {}; + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/full', { + searchParams: params, + }); + } + + /** + * Get light historical daily prices (date and close only) + * @param symbol - Stock symbol + * @param from - Start date (YYYY-MM-DD) + * @param to - End date (YYYY-MM-DD) + */ + async getHistoricalPricesLight( + symbol: string, + from?: string, + to?: string + ): Promise { + validateSymbol(symbol); + validateDateRange(from, to); + + const params: Record = { + symbol: symbol.toUpperCase(), + }; + + if (from) params.from = from; + if (to) params.to = to; + + return this.client.get('historical-price-eod/light', { + searchParams: params, + }); } /** @@ -73,67 +100,67 @@ export class MarketResource { validateSymbol(symbol); validateDateRange(from, to); - const params: Record = {}; + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/${interval}/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get(`historical-chart/${interval}`, { + searchParams: params, + }); } /** - * Get forex pair prices + * Get forex pair quote * @param pair - Forex pair (e.g., "EURUSD") */ - async getForexPrice(pair?: string): Promise { - const endpoint = pair ? `v3/fx/${pair.toUpperCase()}` : 'v3/fx'; - return this.client.get(endpoint); + async getForexPrice(pair: string): Promise { + return this.client.get('quote', { + searchParams: { symbol: pair.toUpperCase() }, + }); } /** - * Get all forex pairs + * Get all forex pair quotes */ async getAllForexPrices(): Promise { - return this.getForexPrice(); + return this.client.get('batch-forex-quotes'); } /** - * Get cryptocurrency prices + * Get cryptocurrency quote * @param symbol - Crypto symbol (e.g., "BTCUSD") */ - async getCryptoPrice(symbol?: string): Promise { - const endpoint = symbol - ? `v3/quote/${symbol.toUpperCase()}` - : 'v3/quotes/crypto'; - return this.client.get(endpoint); + async getCryptoPrice(symbol: string): Promise { + return this.client.get('quote', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** - * Get all cryptocurrency prices + * Get all cryptocurrency quotes */ async getAllCryptoPrices(): Promise { - return this.getCryptoPrice(); + return this.client.get('batch-crypto-quotes'); } /** * Get list of available cryptocurrencies */ async getCryptoList(): Promise { - return this.client.get('v3/symbol/available-cryptocurrencies'); + return this.client.get('cryptocurrency-list'); } /** - * Get cryptocurrency quotes in short format (symbol, price, volume) + * Get cryptocurrency quote (short format) * @param symbol - Crypto symbol (e.g., "BTCUSD") */ - async getCryptoQuoteShort(symbol?: string): Promise { - const endpoint = symbol - ? `v3/quote/${symbol.toUpperCase()}` - : 'v3/quotes/crypto'; - return this.client.get(endpoint); + async getCryptoQuoteShort(symbol: string): Promise { + return this.client.get('quote-short', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -147,14 +174,15 @@ export class MarketResource { from?: string, to?: string ): Promise { - const params: Record = {}; + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/line/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/light', { + searchParams: params, + }); } /** @@ -167,78 +195,40 @@ export class MarketResource { symbol: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { - const params: Record = {}; - if (from) params.from = from; - if (to) params.to = to; - - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${symbol.toUpperCase()}`, - { searchParams: params } - ); - } - - /** - * Get intraday chart data for cryptocurrency (1-minute intervals) - * @param symbol - Crypto symbol (e.g., "BTCUSD") - * @param from - Start date (YYYY-MM-DD) - * @param to - End date (YYYY-MM-DD) - */ - async getCryptoIntraday1Min( - symbol: string, - from?: string, - to?: string - ): Promise { - const params: Record = {}; - if (from) params.from = from; - if (to) params.to = to; - - return this.client.get( - `v3/historical-chart/1min/${symbol.toUpperCase()}`, - { searchParams: params } - ); - } - - /** - * Get intraday chart data for cryptocurrency (5-minute intervals) - * @param symbol - Crypto symbol (e.g., "BTCUSD") - * @param from - Start date (YYYY-MM-DD) - * @param to - End date (YYYY-MM-DD) - */ - async getCryptoIntraday5Min( - symbol: string, - from?: string, - to?: string - ): Promise { - const params: Record = {}; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/5min/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/full', { + searchParams: params, + }); } /** - * Get intraday chart data for cryptocurrency (1-hour intervals) + * Get intraday chart data for cryptocurrency * @param symbol - Crypto symbol (e.g., "BTCUSD") + * @param interval - Time interval * @param from - Start date (YYYY-MM-DD) * @param to - End date (YYYY-MM-DD) */ - async getCryptoIntraday1Hour( + async getCryptoIntraday( symbol: string, + interval: IntradayInterval = IntradayInterval.OneHour, from?: string, to?: string ): Promise { - const params: Record = {}; + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/1hour/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get(`historical-chart/${interval}`, { + searchParams: params, + }); } /** @@ -251,32 +241,34 @@ export class MarketResource { pair: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { - const params: Record = {}; + ): Promise { + const params: Record = { + symbol: pair.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${pair.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/full', { + searchParams: params, + }); } /** * Get list of available forex currency pairs */ async getForexCurrencyPairs(): Promise { - return this.client.get('v3/symbol/available-forex-currency-pairs'); + return this.client.get('forex-list'); } /** * Get forex quote in short format (symbol, price, volume) * @param pair - Forex pair (e.g., "EURUSD") */ - async getForexQuoteShort(pair?: string): Promise { - const endpoint = pair ? `v3/forex/${pair.toUpperCase()}` : 'v3/forex'; - return this.client.get(endpoint); + async getForexQuoteShort(pair: string): Promise { + return this.client.get('quote-short', { + searchParams: { symbol: pair.toUpperCase() }, + }); } /** @@ -290,128 +282,70 @@ export class MarketResource { from?: string, to?: string ): Promise { - const params: Record = {}; - if (from) params.from = from; - if (to) params.to = to; - - return this.client.get( - `v3/historical-chart/line/${pair.toUpperCase()}`, - { searchParams: params } - ); - } - - /** - * Get intraday chart data for forex pairs (1-minute intervals) - * @param pair - Forex pair (e.g., "EURUSD") - * @param from - Start date (YYYY-MM-DD) - * @param to - End date (YYYY-MM-DD) - */ - async getForexIntraday1Min( - pair: string, - from?: string, - to?: string - ): Promise { - const params: Record = {}; - if (from) params.from = from; - if (to) params.to = to; - - return this.client.get( - `v3/historical-chart/1min/${pair.toUpperCase()}`, - { searchParams: params } - ); - } - - /** - * Get intraday chart data for forex pairs (5-minute intervals) - * @param pair - Forex pair (e.g., "EURUSD") - * @param from - Start date (YYYY-MM-DD) - * @param to - End date (YYYY-MM-DD) - */ - async getForexIntraday5Min( - pair: string, - from?: string, - to?: string - ): Promise { - const params: Record = {}; + const params: Record = { + symbol: pair.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/5min/${pair.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-price-eod/light', { + searchParams: params, + }); } /** - * Get intraday chart data for forex pairs (1-hour intervals) + * Get intraday chart data for forex pairs * @param pair - Forex pair (e.g., "EURUSD") + * @param interval - Time interval * @param from - Start date (YYYY-MM-DD) * @param to - End date (YYYY-MM-DD) */ - async getForexIntraday1Hour( + async getForexIntraday( pair: string, + interval: IntradayInterval = IntradayInterval.OneHour, from?: string, to?: string ): Promise { - const params: Record = {}; + const params: Record = { + symbol: pair.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-chart/1hour/${pair.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get(`historical-chart/${interval}`, { + searchParams: params, + }); } /** * Get market hours for a specific exchange * @param exchange - Exchange name (e.g., "NYSE", "NASDAQ") */ - async getMarketHours(exchange?: string): Promise { - const params: Record = {}; - if (exchange) params.exchange = exchange; - return this.client.get('v3/is-the-market-open', { searchParams: params }); + async getMarketHours(exchange: string): Promise { + return this.client.get('exchange-market-hours', { + searchParams: { exchange }, + }); } /** - * Get market holidays + * Get market holidays for a specific exchange + * @param exchange - Exchange name (e.g., "NYSE", "NASDAQ") */ - async getMarketHolidays(): Promise { - return this.client.get('v3/market-holidays'); + async getMarketHolidays(exchange: string): Promise { + return this.client.get('holidays-by-exchange', { + searchParams: { exchange }, + }); } /** * Get hours for all exchanges */ async getAllMarketHours(): Promise { - return this.client.get('v3/market-hours'); + return this.client.get('all-exchange-market-hours'); } /** - * Get light historical chart data (lightweight price data with intervals) - * @param interval - Time interval (e.g., '1min', '5min', '15min', '30min', '1hour', '4hour') - * @param symbol - Stock symbol - * @param from - Start date (YYYY-MM-DD) - * @param to - End date (YYYY-MM-DD) - */ - async getLightChart( - interval: string, - symbol: string, - from?: string, - to?: string - ): Promise { - const params: Record = {}; - if (from) params.from = from; - if (to) params.to = to; - - return this.client.get( - `v3/historical-chart/${interval}/${symbol.toUpperCase()}`, - { searchParams: params } - ); - } - - /** - * Get unadjusted historical prices (not adjusted for splits or dividends) + * Get unadjusted historical prices (not adjusted for splits) * @param symbol - Stock symbol * @param from - Start date (YYYY-MM-DD) * @param to - End date (YYYY-MM-DD) @@ -420,19 +354,21 @@ export class MarketResource { symbol: string, from?: string, to?: string - ): Promise { - const params: Record = {}; + ): Promise { + const params: Record = { + symbol: symbol.toUpperCase(), + }; if (from) params.from = from; if (to) params.to = to; - return this.client.get( - `v3/historical-price-full/${symbol.toUpperCase()}/line`, + return this.client.get( + 'historical-price-eod/non-split-adjusted', { searchParams: params } ); } /** - * Get dividend-adjusted historical prices (adjusted for dividends only) + * Get dividend-adjusted historical prices * @param symbol - Stock symbol * @param from - Start date (YYYY-MM-DD) * @param to - End date (YYYY-MM-DD) @@ -441,15 +377,15 @@ export class MarketResource { symbol: string, from?: string, to?: string - ): Promise<{ historical: HistoricalPrice[] }> { + ): Promise { const params: Record = { - serietype: 'line' + symbol: symbol.toUpperCase(), }; if (from) params.from = from; if (to) params.to = to; - return this.client.get<{ historical: HistoricalPrice[] }>( - `v3/historical-price-full/${symbol.toUpperCase()}`, + return this.client.get( + 'historical-price-eod/dividend-adjusted', { searchParams: params } ); } diff --git a/src/resources/news.ts b/src/resources/news.ts index d13128f..30cfa9f 100644 --- a/src/resources/news.ts +++ b/src/resources/news.ts @@ -18,7 +18,9 @@ export class NewsResource { * @param limit - Results per page */ async getFMPArticles(page = 0, limit = 50): Promise { - return this.client.get('v3/fmp/articles', { searchParams: { page, size: limit } }); + return this.client.get('fmp-articles', { + searchParams: { page, size: limit }, + }); } /** @@ -26,7 +28,9 @@ export class NewsResource { * @param page - Page number */ async getGeneralNews(page = 0): Promise { - return this.client.get('v4/general_news', { searchParams: { page } }); + return this.client.get('general-news', { + searchParams: { page }, + }); } /** @@ -38,7 +42,9 @@ export class NewsResource { const params: Record = { limit }; if (tickers) params.tickers = tickers; - return this.client.get('v3/stock_news', { searchParams: params }); + return this.client.get('stock-news', { + searchParams: params, + }); } /** @@ -47,7 +53,9 @@ export class NewsResource { * @param limit - Results per page */ async getCryptoNews(page = 0, limit = 50): Promise { - return this.client.get('v4/crypto_news', { searchParams: { page, limit } }); + return this.client.get('crypto-news', { + searchParams: { page, limit }, + }); } /** @@ -56,16 +64,20 @@ export class NewsResource { * @param limit - Results per page */ async getForexNews(page = 0, limit = 50): Promise { - return this.client.get('v4/forex_news', { searchParams: { page, limit } }); + return this.client.get('forex-news', { + searchParams: { page, limit }, + }); } /** - * Get press releases (search endpoint) + * Get press releases * @param symbol - Stock symbol * @param page - Page number */ async getPressReleases(symbol: string, page = 0): Promise { - return this.client.get(`v3/press-releases/${symbol.toUpperCase()}`, { searchParams: { page } }); + return this.client.get('press-releases', { + searchParams: { symbol: symbol.toUpperCase(), page }, + }); } /** @@ -74,7 +86,9 @@ export class NewsResource { * @param limit - Number of results (default: 50) */ async getLatestPressReleases(symbol: string, limit = 50): Promise { - return this.client.get(`v3/press-releases/${symbol.toUpperCase()}`, { searchParams: { limit } }); + return this.client.get('press-releases', { + searchParams: { symbol: symbol.toUpperCase(), limit }, + }); } /** @@ -88,8 +102,12 @@ export class NewsResource { year: number, quarter: number ): Promise { - return this.client.get(`v3/earning_call_transcript/${symbol.toUpperCase()}`, { - searchParams: { year, quarter }, + return this.client.get('earning-call-transcript', { + searchParams: { + symbol: symbol.toUpperCase(), + year, + quarter, + }, }); } @@ -99,8 +117,9 @@ export class NewsResource { */ async getEarningsTranscriptDates(symbol: string): Promise> { return this.client.get>( - `v4/earning_call_transcript`, - { searchParams: { symbol: symbol.toUpperCase() } } + 'earning-call-transcript-dates', { + searchParams: { symbol: symbol.toUpperCase() }, + } ); } @@ -109,8 +128,59 @@ export class NewsResource { * @param symbol - Stock symbol */ async getBatchEarningsTranscripts(symbol: string): Promise { - return this.client.get( - `v4/batch_earning_call_transcript/${symbol.toUpperCase()}` - ); + return this.client.get('batch-earning-call-transcript', { + searchParams: { symbol: symbol.toUpperCase() }, + }); + } + + /** + * Get list of symbols with available earnings transcripts + */ + async getAvailableTranscriptSymbols(): Promise> { + return this.client.get>('earning-call-transcript-available-symbols'); + } + + /** + * Search press releases + * @param query - Search query + * @param limit - Number of results + */ + async searchPressReleases(query: string, limit = 50): Promise { + return this.client.get('press-releases-search', { + searchParams: { query, limit }, + }); + } + + /** + * Search stock news + * @param query - Search query + * @param limit - Number of results + */ + async searchStockNews(query: string, limit = 50): Promise { + return this.client.get('stock-news-search', { + searchParams: { query, limit }, + }); + } + + /** + * Search crypto news + * @param query - Search query + * @param limit - Number of results + */ + async searchCryptoNews(query: string, limit = 50): Promise { + return this.client.get('crypto-news-search', { + searchParams: { query, limit }, + }); + } + + /** + * Search forex news + * @param query - Search query + * @param limit - Number of results + */ + async searchForexNews(query: string, limit = 50): Promise { + return this.client.get('forex-news-search', { + searchParams: { query, limit }, + }); } } diff --git a/src/resources/performance.ts b/src/resources/performance.ts index 143b9f2..c4fa6d9 100644 --- a/src/resources/performance.ts +++ b/src/resources/performance.ts @@ -17,21 +17,21 @@ export class PerformanceResource { * Get biggest gainers */ async getGainers(): Promise { - return this.client.get('v3/stock_market/gainers'); + return this.client.get('stock-market-gainers'); } /** * Get biggest losers */ async getLosers(): Promise { - return this.client.get('v3/stock_market/losers'); + return this.client.get('stock-market-losers'); } /** * Get most active stocks */ async getMostActive(): Promise { - return this.client.get('v3/stock_market/actives'); + return this.client.get('stock-market-actives'); } /** @@ -42,7 +42,9 @@ export class PerformanceResource { const params: Record = {}; if (limit) params.limit = limit; - return this.client.get('v3/sector-performance', { searchParams: params }); + return this.client.get('sector-performance', { + searchParams: params, + }); } /** @@ -57,10 +59,9 @@ export class PerformanceResource { const params: Record = { sector }; if (limit) params.limit = limit; - return this.client.get( - 'v3/historical-sector-performance', - { searchParams: params } - ); + return this.client.get('historical-sector-performance', { + searchParams: params, + }); } /** @@ -72,7 +73,9 @@ export class PerformanceResource { const params: Record = { date }; if (exchange) params.exchange = exchange; - return this.client.get('v4/sector_price_earning_ratio', { searchParams: params }); + return this.client.get('sector-price-earning-ratio', { + searchParams: params, + }); } /** @@ -84,7 +87,9 @@ export class PerformanceResource { const params: Record = { date }; if (exchange) params.exchange = exchange; - return this.client.get[]>('v4/industry_price_earning_ratio', { searchParams: params }); + return this.client.get[]>('industry-price-earning-ratio', { + searchParams: params, + }); } /** @@ -92,7 +97,9 @@ export class PerformanceResource { * @param sector - Sector name */ async getHistoricalSectorPE(sector: string): Promise { - return this.client.get('v4/historical-sector-pe', { searchParams: { sector } }); + return this.client.get('historical-sector-pe', { + searchParams: { sector }, + }); } /** @@ -100,6 +107,8 @@ export class PerformanceResource { * @param industry - Industry name */ async getHistoricalIndustryPE(industry: string): Promise[]> { - return this.client.get[]>('v4/historical-industry-pe', { searchParams: { industry } }); + return this.client.get[]>('historical-industry-pe', { + searchParams: { industry }, + }); } } diff --git a/src/resources/search.ts b/src/resources/search.ts index 15b8f98..5aaacdf 100644 --- a/src/resources/search.ts +++ b/src/resources/search.ts @@ -47,7 +47,7 @@ export class SearchResource { params.exchange = exchange.toUpperCase(); } - return this.client.get('v3/search-ticker', { searchParams: params }); + return this.client.get('search-symbol', { searchParams: params }); } /** @@ -80,7 +80,7 @@ export class SearchResource { params.exchange = exchange.toUpperCase(); } - return this.client.get('v3/search-name', { searchParams: params }); + return this.client.get('search-name', { searchParams: params }); } /** @@ -95,7 +95,9 @@ export class SearchResource { * ``` */ async searchByCIK(cik: string): Promise { - return this.client.get(`v3/cik/${cik}`); + return this.client.get('search-cik', { + searchParams: { cik }, + }); } /** @@ -110,7 +112,9 @@ export class SearchResource { * ``` */ async searchByCUSIP(cusip: string): Promise { - return this.client.get(`v3/cusip/${cusip}`); + return this.client.get('search-cusip', { + searchParams: { cusip }, + }); } /** @@ -125,7 +129,7 @@ export class SearchResource { * ``` */ async searchByISIN(isin: string): Promise { - return this.client.get('v3/search-isin', { searchParams: { isin } }); + return this.client.get('search-isin', { searchParams: { isin } }); } /** @@ -221,7 +225,7 @@ export class SearchResource { queryParams.limit = params.limit; } - return this.client.get('v3/stock-screener', { searchParams: queryParams }); + return this.client.get('company-screener', { searchParams: queryParams }); } /** @@ -242,6 +246,8 @@ export class SearchResource { * ``` */ async getExchangeSymbols(exchange: string): Promise { - return this.client.get(`v3/symbol/${exchange.toUpperCase()}`); + return this.client.get('exchange-symbols', { + searchParams: { exchange: exchange.toUpperCase() }, + }); } } diff --git a/src/resources/sec.ts b/src/resources/sec.ts index 0dc4b58..ea2fd46 100644 --- a/src/resources/sec.ts +++ b/src/resources/sec.ts @@ -20,11 +20,13 @@ export class SECResource { * @param limit - Number of results */ async getFilings(symbol: string, type?: string, limit?: number): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (type) params.type = type; if (limit) params.limit = limit; - return this.client.get(`v3/sec_filings/${symbol.toUpperCase()}`, { searchParams: params }); + return this.client.get('sec-filings', { + searchParams: params, + }); } /** @@ -41,7 +43,9 @@ export class SECResource { if (to) params.to = to; if (limit) params.limit = limit; - return this.client.get('v4/rss_feed', { searchParams: params }); + return this.client.get('rss-feed', { + searchParams: params, + }); } /** @@ -62,7 +66,9 @@ export class SECResource { if (to) params.to = to; if (limit) params.limit = limit; - return this.client.get('v4/rss_feed', { searchParams: params }); + return this.client.get('rss-feed', { + searchParams: params, + }); } /** @@ -82,10 +88,12 @@ export class SECResource { * @param limit - Number of results */ async getFilingsByCIK(cik: string, type?: string, limit?: number): Promise { - const params: Record = {}; + const params: Record = { cik }; if (type) params.type = type; if (limit) params.limit = limit; - return this.client.get(`v3/sec_filings/${cik}`, { searchParams: params }); + return this.client.get('sec-filings', { + searchParams: params, + }); } /** @@ -98,7 +106,9 @@ export class SECResource { const params: Record = { name }; if (type) params.type = type; if (limit) params.limit = limit; - return this.client.get('v3/sec_filings', { searchParams: params }); + return this.client.get('sec-filings', { + searchParams: params, + }); } /** @@ -106,7 +116,9 @@ export class SECResource { * @param symbol - Stock symbol */ async searchCompanyBySymbol(symbol: string): Promise { - return this.client.get(`v3/cik-search/${symbol.toUpperCase()}`); + return this.client.get('cik-search', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -114,7 +126,9 @@ export class SECResource { * @param cik - Central Index Key */ async searchCompanyByCIK(cik: string): Promise { - return this.client.get(`v3/cik/${cik}`); + return this.client.get('cik', { + searchParams: { cik }, + }); } /** @@ -124,14 +138,16 @@ export class SECResource { async getLatestFilings(limit?: number): Promise { const params: Record = {}; if (limit) params.limit = limit; - return this.client.get('v4/rss_feed_8k', { searchParams: params }); + return this.client.get('rss-feed-8k', { + searchParams: params, + }); } /** * Get list of all SIC codes */ async getAllSICCodes(): Promise { - return this.client.get('v4/standard_industrial_classification/all'); + return this.client.get('standard-industrial-classification-all'); } /** @@ -139,7 +155,9 @@ export class SECResource { * @param sicCode - SIC code */ async getSICByCode(sicCode: string): Promise { - return this.client.get(`v4/standard_industrial_classification`, { searchParams: { sicCode } }); + return this.client.get('standard-industrial-classification', { + searchParams: { sicCode }, + }); } /** @@ -147,7 +165,9 @@ export class SECResource { * @param industry - Industry name */ async searchSIC(industry: string): Promise { - return this.client.get('v4/standard_industrial_classification', { searchParams: { industry } }); + return this.client.get('standard-industrial-classification', { + searchParams: { industry }, + }); } /** @@ -156,6 +176,8 @@ export class SECResource { * @param symbol - Stock symbol */ async getFullProfile(symbol: string): Promise { - return this.client.get(`v4/company-outlook`, { searchParams: { symbol: symbol.toUpperCase() } }); + return this.client.get('company-outlook', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } } diff --git a/src/resources/technical.ts b/src/resources/technical.ts index f3e7625..693bde4 100644 --- a/src/resources/technical.ts +++ b/src/resources/technical.ts @@ -31,8 +31,12 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'sma', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'sma', + period, + }, }); } @@ -47,8 +51,12 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'ema', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'ema', + period, + }, }); } @@ -63,8 +71,12 @@ export class TechnicalResource { period = 14, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'rsi', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'rsi', + period, + }, }); } @@ -79,8 +91,12 @@ export class TechnicalResource { period = 14, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'adx', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'adx', + period, + }, }); } @@ -95,8 +111,12 @@ export class TechnicalResource { period = 14, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'williams', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'williams', + period, + }, }); } @@ -111,12 +131,13 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get( - `v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, - { - searchParams: { type: 'standardDeviation', period }, - } - ); + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'standardDeviation', + period, + }, + }); } /** @@ -130,8 +151,12 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'wma', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'wma', + period, + }, }); } @@ -146,8 +171,12 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'dema', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'dema', + period, + }, }); } @@ -162,8 +191,12 @@ export class TechnicalResource { period = 10, timeframe: TechnicalTimeframe = TechnicalTimeframe.Daily ): Promise { - return this.client.get(`v3/technical_indicator/${timeframe}/${symbol.toUpperCase()}`, { - searchParams: { type: 'tema', period }, + return this.client.get(`technical-indicator/${timeframe}`, { + searchParams: { + symbol: symbol.toUpperCase(), + type: 'tema', + period, + }, }); } } diff --git a/src/resources/valuation.ts b/src/resources/valuation.ts index a74abb4..e318ada 100644 --- a/src/resources/valuation.ts +++ b/src/resources/valuation.ts @@ -13,7 +13,9 @@ export class ValuationResource { * @param symbol - Stock symbol */ async getDCF(symbol: string): Promise { - return this.client.get(`v3/discounted-cash-flow/${symbol.toUpperCase()}`); + return this.client.get('discounted-cash-flow', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } /** @@ -21,7 +23,7 @@ export class ValuationResource { * @param symbol - Stock symbol */ async getLeveredDCF(symbol: string): Promise { - return this.client.get(`v4/advanced_levered_discounted_cash_flow`, { + return this.client.get('levered-discounted-cash-flow', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -31,7 +33,7 @@ export class ValuationResource { * @param symbol - Stock symbol */ async getAdvancedDCF(symbol: string): Promise { - return this.client.get(`v4/advanced_discounted_cash_flow`, { + return this.client.get('custom-discounted-cash-flow', { searchParams: { symbol: symbol.toUpperCase() }, }); } @@ -42,12 +44,11 @@ export class ValuationResource { * @param limit - Maximum number of results */ async getHistoricalDailyDCF(symbol: string, limit?: number): Promise { - const params: Record = {}; + const params: Record = { symbol: symbol.toUpperCase() }; if (limit) params.limit = limit; - return this.client.get( - `v3/historical-daily-discounted-cash-flow/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-daily-discounted-cash-flow', { + searchParams: params, + }); } /** @@ -61,11 +62,20 @@ export class ValuationResource { period: 'annual' | 'quarter' = 'annual', limit?: number ): Promise { - const params: Record = { period }; + const params: Record = { symbol: symbol.toUpperCase(), period }; if (limit) params.limit = limit; - return this.client.get( - `v3/historical-discounted-cash-flow-statement/${symbol.toUpperCase()}`, - { searchParams: params } - ); + return this.client.get('historical-discounted-cash-flow-statement', { + searchParams: params, + }); + } + + /** + * Get custom levered DCF valuation + * @param symbol - Stock symbol + */ + async getCustomLeveredDCF(symbol: string): Promise { + return this.client.get('custom-levered-discounted-cash-flow', { + searchParams: { symbol: symbol.toUpperCase() }, + }); } } diff --git a/src/types/common.ts b/src/types/common.ts index 6bdb084..ca0e7f8 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -39,7 +39,7 @@ export interface FMPConfig { /** * Base URL for the FMP API - * @default "https://financialmodelingprep.com/api" + * @default "https://financialmodelingprep.com/stable" */ baseUrl?: string; diff --git a/src/types/company.ts b/src/types/company.ts index f71d2d5..7f1a347 100644 --- a/src/types/company.ts +++ b/src/types/company.ts @@ -57,18 +57,18 @@ export interface Quote { dayHigh: number; yearHigh: number; yearLow: number; - marketCap: number; - priceAvg50: number; - priceAvg200: number; + marketCap: number | null; + priceAvg50: number | null; + priceAvg200: number | null; exchange: string; volume: number; avgVolume: number; open: number; previousClose: number; - eps: number; - pe: number; - earningsAnnouncement: string; - sharesOutstanding: number; + eps: number | null; + pe: number | null; + earningsAnnouncement: string | null; + sharesOutstanding: number | null; timestamp: number; } @@ -279,3 +279,77 @@ export interface TradableSymbol { price: number; exchange: string; } + +/** + * Short quote (simplified quote data) + */ +export interface QuoteShort { + symbol: string; + price: number; + volume: number; +} + +/** + * Aftermarket trade data + */ +export interface AftermarketTrade { + symbol: string; + price: number; + size: number; + timestamp: number; +} + +/** + * Aftermarket quote data + */ +export interface AftermarketQuote { + symbol: string; + ask: number; + bid: number; + asize: number; + bsize: number; + timestamp: number; +} + +/** + * Stock price change data + */ +export interface PriceChange { + symbol: string; + '1D': number | null; + '5D': number | null; + '1M': number | null; + '3M': number | null; + '6M': number | null; + ytd: number | null; + '1Y': number | null; + '3Y': number | null; + '5Y': number | null; + '10Y': number | null; + max: number | null; +} + +/** + * Enterprise value data + */ +export interface EnterpriseValue { + symbol: string; + date: string; + stockPrice: number | null; + numberOfShares: number | null; + marketCapitalization: number | null; + minusCashAndCashEquivalents: number | null; + addTotalDebt: number | null; + enterpriseValue: number | null; +} + +/** + * ETF/Fund list item + */ +export interface FundListItem { + symbol: string; + name: string; + price: number | null; + exchange: string; + exchangeShortName: string; +} diff --git a/src/types/financials.ts b/src/types/financials.ts index 3429585..1cbd8a4 100644 --- a/src/types/financials.ts +++ b/src/types/financials.ts @@ -9,41 +9,41 @@ export interface IncomeStatement { date: string; symbol: string; reportedCurrency: string; - cik: string; + cik: string | null; 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; + revenue: number | null; + costOfRevenue: number | null; + grossProfit: number | null; + grossProfitRatio: number | null; + researchAndDevelopmentExpenses: number | null; + generalAndAdministrativeExpenses: number | null; + sellingAndMarketingExpenses: number | null; + sellingGeneralAndAdministrativeExpenses: number | null; + otherExpenses: number | null; + operatingExpenses: number | null; + costAndExpenses: number | null; + interestIncome: number | null; + interestExpense: number | null; + depreciationAndAmortization: number | null; + ebitda: number | null; + ebitdaratio: number | null; + operatingIncome: number | null; + operatingIncomeRatio: number | null; + totalOtherIncomeExpensesNet: number | null; + incomeBeforeTax: number | null; + incomeBeforeTaxRatio: number | null; + incomeTaxExpense: number | null; + netIncome: number | null; + netIncomeRatio: number | null; + eps: number | null; + epsdiluted: number | null; + weightedAverageShsOut: number | null; + weightedAverageShsOutDil: number | null; + link: string | null; + finalLink: string | null; } /** @@ -53,57 +53,57 @@ export interface BalanceSheet { date: string; symbol: string; reportedCurrency: string; - cik: string; + cik: string | null; 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; + cashAndCashEquivalents: number | null; + shortTermInvestments: number | null; + cashAndShortTermInvestments: number | null; + netReceivables: number | null; + inventory: number | null; + otherCurrentAssets: number | null; + totalCurrentAssets: number | null; + propertyPlantEquipmentNet: number | null; + goodwill: number | null; + intangibleAssets: number | null; + goodwillAndIntangibleAssets: number | null; + longTermInvestments: number | null; + taxAssets: number | null; + otherNonCurrentAssets: number | null; + totalNonCurrentAssets: number | null; + otherAssets: number | null; + totalAssets: number | null; + accountPayables: number | null; + shortTermDebt: number | null; + taxPayables: number | null; + deferredRevenue: number | null; + otherCurrentLiabilities: number | null; + totalCurrentLiabilities: number | null; + longTermDebt: number | null; + deferredRevenueNonCurrent: number | null; + deferredTaxLiabilitiesNonCurrent: number | null; + otherNonCurrentLiabilities: number | null; + totalNonCurrentLiabilities: number | null; + otherLiabilities: number | null; + capitalLeaseObligations: number | null; + totalLiabilities: number | null; + preferredStock: number | null; + commonStock: number | null; + retainedEarnings: number | null; + accumulatedOtherComprehensiveIncomeLoss: number | null; + othertotalStockholdersEquity: number | null; + totalStockholdersEquity: number | null; + totalEquity: number | null; + totalLiabilitiesAndStockholdersEquity: number | null; + minorityInterest: number | null; + totalLiabilitiesAndTotalEquity: number | null; + totalInvestments: number | null; + totalDebt: number | null; + netDebt: number | null; + link: string | null; + finalLink: string | null; } /** @@ -113,43 +113,43 @@ export interface CashFlowStatement { date: string; symbol: string; reportedCurrency: string; - cik: string; + cik: string | null; 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; + netIncome: number | null; + depreciationAndAmortization: number | null; + deferredIncomeTax: number | null; + stockBasedCompensation: number | null; + changeInWorkingCapital: number | null; + accountsReceivables: number | null; + inventory: number | null; + accountsPayables: number | null; + otherWorkingCapital: number | null; + otherNonCashItems: number | null; + netCashProvidedByOperatingActivities: number | null; + investmentsInPropertyPlantAndEquipment: number | null; + acquisitionsNet: number | null; + purchasesOfInvestments: number | null; + salesMaturitiesOfInvestments: number | null; + otherInvestingActivites: number | null; + netCashUsedForInvestingActivites: number | null; + debtRepayment: number | null; + commonStockIssued: number | null; + commonStockRepurchased: number | null; + dividendsPaid: number | null; + otherFinancingActivites: number | null; + netCashUsedProvidedByFinancingActivities: number | null; + effectOfForexChangesOnCash: number | null; + netChangeInCash: number | null; + cashAtEndOfPeriod: number | null; + cashAtBeginningOfPeriod: number | null; + operatingCashFlow: number | null; + capitalExpenditure: number | null; + freeCashFlow: number | null; + link: string | null; + finalLink: string | null; } /** @@ -160,59 +160,59 @@ export interface FinancialRatios { 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; - priceBookValueRatio: number; - priceToBookRatio: number; - priceToSalesRatio: number; - priceEarningsRatio: number; - priceToFreeCashFlowsRatio: number; - priceToOperatingCashFlowsRatio: number; - priceCashFlowRatio: number; - priceEarningsToGrowthRatio: number; - priceSalesRatio: number; - dividendYield: number; - enterpriseValueMultiple: number; - priceFairValue: number; + currentRatio: number | null; + quickRatio: number | null; + cashRatio: number | null; + daysOfSalesOutstanding: number | null; + daysOfInventoryOutstanding: number | null; + operatingCycle: number | null; + daysOfPayablesOutstanding: number | null; + cashConversionCycle: number | null; + grossProfitMargin: number | null; + operatingProfitMargin: number | null; + pretaxProfitMargin: number | null; + netProfitMargin: number | null; + effectiveTaxRate: number | null; + returnOnAssets: number | null; + returnOnEquity: number | null; + returnOnCapitalEmployed: number | null; + netIncomePerEBT: number | null; + ebtPerEbit: number | null; + ebitPerRevenue: number | null; + debtRatio: number | null; + debtEquityRatio: number | null; + longTermDebtToCapitalization: number | null; + totalDebtToCapitalization: number | null; + interestCoverage: number | null; + cashFlowToDebtRatio: number | null; + companyEquityMultiplier: number | null; + receivablesTurnover: number | null; + payablesTurnover: number | null; + inventoryTurnover: number | null; + fixedAssetTurnover: number | null; + assetTurnover: number | null; + operatingCashFlowPerShare: number | null; + freeCashFlowPerShare: number | null; + cashPerShare: number | null; + payoutRatio: number | null; + operatingCashFlowSalesRatio: number | null; + freeCashFlowOperatingCashFlowRatio: number | null; + cashFlowCoverageRatios: number | null; + shortTermCoverageRatios: number | null; + capitalExpenditureCoverageRatio: number | null; + dividendPaidAndCapexCoverageRatio: number | null; + priceBookValueRatio: number | null; + priceToBookRatio: number | null; + priceToSalesRatio: number | null; + priceEarningsRatio: number | null; + priceToFreeCashFlowsRatio: number | null; + priceToOperatingCashFlowsRatio: number | null; + priceCashFlowRatio: number | null; + priceEarningsToGrowthRatio: number | null; + priceSalesRatio: number | null; + dividendYield: number | null; + enterpriseValueMultiple: number | null; + priceFairValue: number | null; } /** @@ -223,63 +223,63 @@ export interface KeyMetrics { 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; + revenuePerShare: number | null; + netIncomePerShare: number | null; + operatingCashFlowPerShare: number | null; + freeCashFlowPerShare: number | null; + cashPerShare: number | null; + bookValuePerShare: number | null; + tangibleBookValuePerShare: number | null; + shareholdersEquityPerShare: number | null; + interestDebtPerShare: number | null; + marketCap: number | null; + enterpriseValue: number | null; + peRatio: number | null; + priceToSalesRatio: number | null; + pocfratio: number | null; + pfcfRatio: number | null; + pbRatio: number | null; + ptbRatio: number | null; + evToSales: number | null; + enterpriseValueOverEBITDA: number | null; + evToOperatingCashFlow: number | null; + evToFreeCashFlow: number | null; + earningsYield: number | null; + freeCashFlowYield: number | null; + debtToEquity: number | null; + debtToAssets: number | null; + netDebtToEBITDA: number | null; + currentRatio: number | null; + interestCoverage: number | null; + incomeQuality: number | null; + dividendYield: number | null; + payoutRatio: number | null; + salesGeneralAndAdministrativeToRevenue: number | null; + researchAndDdevelopementToRevenue: number | null; + intangiblesToTotalAssets: number | null; + capexToOperatingCashFlow: number | null; + capexToRevenue: number | null; + capexToDepreciation: number | null; + stockBasedCompensationToRevenue: number | null; + grahamNumber: number | null; + roic: number | null; + returnOnTangibleAssets: number | null; + grahamNetNet: number | null; + workingCapital: number | null; + tangibleAssetValue: number | null; + netCurrentAssetValue: number | null; + investedCapital: number | null; + averageReceivables: number | null; + averagePayables: number | null; + averageInventory: number | null; + daysSalesOutstanding: number | null; + daysPayablesOutstanding: number | null; + daysOfInventoryOnHand: number | null; + receivablesTurnover: number | null; + payablesTurnover: number | null; + inventoryTurnover: number | null; + roe: number | null; + capexPerShare: number | null; } /** @@ -287,15 +287,15 @@ export interface KeyMetrics { */ export interface FinancialScores { symbol: string; - altmanZScore: number; - piotroskiScore: number; - workingCapital: number; - totalAssets: number; - retainedEarnings: number; - ebit: number; - marketCap: number; - totalLiabilities: number; - revenue: number; + altmanZScore: number | null; + piotroskiScore: number | null; + workingCapital: number | null; + totalAssets: number | null; + retainedEarnings: number | null; + ebit: number | null; + marketCap: number | null; + totalLiabilities: number | null; + revenue: number | null; } /** @@ -304,11 +304,11 @@ export interface FinancialScores { export interface OwnerEarnings { symbol: string; date: string; - averagePPE: number; - maintenanceCapex: number; - ownersEarnings: number; - growthCapex: number; - ownersEarningsPerShare: number; + averagePPE: number | null; + maintenanceCapex: number | null; + ownersEarnings: number | null; + growthCapex: number | null; + ownersEarningsPerShare: number | null; } /** @@ -319,40 +319,40 @@ export interface FinancialGrowth { 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; + revenueGrowth: number | null; + grossProfitGrowth: number | null; + ebitgrowth: number | null; + operatingIncomeGrowth: number | null; + netIncomeGrowth: number | null; + epsgrowth: number | null; + epsdilutedGrowth: number | null; + weightedAverageSharesGrowth: number | null; + weightedAverageSharesDilutedGrowth: number | null; + dividendsperShareGrowth: number | null; + operatingCashFlowGrowth: number | null; + freeCashFlowGrowth: number | null; + tenYRevenueGrowthPerShare: number | null; + fiveYRevenueGrowthPerShare: number | null; + threeYRevenueGrowthPerShare: number | null; + tenYOperatingCFGrowthPerShare: number | null; + fiveYOperatingCFGrowthPerShare: number | null; + threeYOperatingCFGrowthPerShare: number | null; + tenYNetIncomeGrowthPerShare: number | null; + fiveYNetIncomeGrowthPerShare: number | null; + threeYNetIncomeGrowthPerShare: number | null; + tenYShareholdersEquityGrowthPerShare: number | null; + fiveYShareholdersEquityGrowthPerShare: number | null; + threeYShareholdersEquityGrowthPerShare: number | null; + tenYDividendperShareGrowthPerShare: number | null; + fiveYDividendperShareGrowthPerShare: number | null; + threeYDividendperShareGrowthPerShare: number | null; + receivablesGrowth: number | null; + inventoryGrowth: number | null; + assetGrowth: number | null; + bookValueperShareGrowth: number | null; + debtGrowth: number | null; + rdexpenseGrowth: number | null; + sgaexpensesGrowth: number | null; } /** @@ -388,3 +388,146 @@ export interface LatestFinancialStatement { export interface FinancialReportDownload { url: string; } + +/** + * Income statement growth data + */ +export interface IncomeStatementGrowth { + date: string; + symbol: string; + period: string; + calendarYear: string; + growthRevenue: number | null; + growthCostOfRevenue: number | null; + growthGrossProfit: number | null; + growthGrossProfitRatio: number | null; + growthResearchAndDevelopmentExpenses: number | null; + growthGeneralAndAdministrativeExpenses: number | null; + growthSellingAndMarketingExpenses: number | null; + growthOtherExpenses: number | null; + growthOperatingExpenses: number | null; + growthCostAndExpenses: number | null; + growthInterestExpense: number | null; + growthDepreciationAndAmortization: number | null; + growthEBITDA: number | null; + growthEBITDARatio: number | null; + growthOperatingIncome: number | null; + growthOperatingIncomeRatio: number | null; + growthTotalOtherIncomeExpensesNet: number | null; + growthIncomeBeforeTax: number | null; + growthIncomeBeforeTaxRatio: number | null; + growthIncomeTaxExpense: number | null; + growthNetIncome: number | null; + growthNetIncomeRatio: number | null; + growthEPS: number | null; + growthEPSDiluted: number | null; + growthWeightedAverageShsOut: number | null; + growthWeightedAverageShsOutDil: number | null; +} + +/** + * Balance sheet growth data + */ +export interface BalanceSheetGrowth { + date: string; + symbol: string; + period: string; + calendarYear: string; + growthCashAndCashEquivalents: number | null; + growthShortTermInvestments: number | null; + growthCashAndShortTermInvestments: number | null; + growthNetReceivables: number | null; + growthInventory: number | null; + growthOtherCurrentAssets: number | null; + growthTotalCurrentAssets: number | null; + growthPropertyPlantEquipmentNet: number | null; + growthGoodwill: number | null; + growthIntangibleAssets: number | null; + growthGoodwillAndIntangibleAssets: number | null; + growthLongTermInvestments: number | null; + growthTaxAssets: number | null; + growthOtherNonCurrentAssets: number | null; + growthTotalNonCurrentAssets: number | null; + growthOtherAssets: number | null; + growthTotalAssets: number | null; + growthAccountPayables: number | null; + growthShortTermDebt: number | null; + growthTaxPayables: number | null; + growthDeferredRevenue: number | null; + growthOtherCurrentLiabilities: number | null; + growthTotalCurrentLiabilities: number | null; + growthLongTermDebt: number | null; + growthDeferredRevenueNonCurrent: number | null; + growthDeferrredTaxLiabilitiesNonCurrent: number | null; + growthOtherNonCurrentLiabilities: number | null; + growthTotalNonCurrentLiabilities: number | null; + growthOtherLiabilities: number | null; + growthTotalLiabilities: number | null; + growthCommonStock: number | null; + growthRetainedEarnings: number | null; + growthAccumulatedOtherComprehensiveIncomeLoss: number | null; + growthOthertotalStockholdersEquity: number | null; + growthTotalStockholdersEquity: number | null; + growthTotalLiabilitiesAndStockholdersEquity: number | null; + growthTotalInvestments: number | null; + growthTotalDebt: number | null; + growthNetDebt: number | null; +} + +/** + * Cash flow statement growth data + */ +export interface CashFlowStatementGrowth { + date: string; + symbol: string; + period: string; + calendarYear: string; + growthNetIncome: number | null; + growthDepreciationAndAmortization: number | null; + growthDeferredIncomeTax: number | null; + growthStockBasedCompensation: number | null; + growthChangeInWorkingCapital: number | null; + growthAccountsReceivables: number | null; + growthInventory: number | null; + growthAccountsPayables: number | null; + growthOtherWorkingCapital: number | null; + growthOtherNonCashItems: number | null; + growthNetCashProvidedByOperatingActivites: number | null; + growthInvestmentsInPropertyPlantAndEquipment: number | null; + growthAcquisitionsNet: number | null; + growthPurchasesOfInvestments: number | null; + growthSalesMaturitiesOfInvestments: number | null; + growthOtherInvestingActivites: number | null; + growthNetCashUsedForInvestingActivites: number | null; + growthDebtRepayment: number | null; + growthCommonStockIssued: number | null; + growthCommonStockRepurchased: number | null; + growthDividendsPaid: number | null; + growthOtherFinancingActivites: number | null; + growthNetCashUsedProvidedByFinancingActivities: number | null; + growthEffectOfForexChangesOnCash: number | null; + growthNetChangeInCash: number | null; + growthCashAtEndOfPeriod: number | null; + growthCashAtBeginningOfPeriod: number | null; + growthOperatingCashFlow: number | null; + growthCapitalExpenditure: number | null; + growthFreeCashFlow: number | null; +} + +/** + * Revenue by product segment + */ +export interface RevenueProductSegmentation { + date: string; + symbol: string; + [segmentName: string]: string | number | null; +} + +/** + * Revenue by geographic segment + */ +export interface RevenueGeographicSegmentation { + date: string; + symbol: string; + [regionName: string]: string | number | null; +} diff --git a/src/types/insider.ts b/src/types/insider.ts index e40207d..a32419d 100644 --- a/src/types/insider.ts +++ b/src/types/insider.ts @@ -178,3 +178,24 @@ export interface IndustryInstitutionalOwnership { percentageOwned: number; date: string; } + +/** + * Form 4 ownership filing data + */ +export interface Form4Ownership { + symbol: string; + filingDate: string; + transactionDate: string; + reportingCik: string; + reportingName: string; + typeOfOwner: string; + acquistionOrDisposition: string; + formType: string; + securitiesOwned: number | null; + securitiesTransacted: number | null; + transactionType: string; + price: number | null; + securityName: string; + companyCik: string; + link: string; +} diff --git a/src/types/valuation.ts b/src/types/valuation.ts index 56b288d..e6c858d 100644 --- a/src/types/valuation.ts +++ b/src/types/valuation.ts @@ -9,7 +9,7 @@ export interface DCFValuation { symbol: string; date: string; dcf: number; - 'Stock Price': number; + stockPrice: number | null; } /** @@ -19,7 +19,7 @@ export interface LeveredDCF { symbol: string; date: string; dcf: number; - 'Stock Price': number; + stockPrice: number | null; } /** diff --git a/tests/analyst.test.ts b/tests/analyst.test.ts index 6af6005..c4db7c2 100644 --- a/tests/analyst.test.ts +++ b/tests/analyst.test.ts @@ -60,13 +60,12 @@ describe('AnalystResource', () => { const result = await analyst.getEstimates('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'annual', - }, - } -); + period: 'annual', + }, + }); expect(result).toEqual(mockEstimates); }); @@ -75,13 +74,12 @@ describe('AnalystResource', () => { const result = await analyst.getEstimates('AAPL', 'quarter'); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'quarter', - }, - } -); + period: 'quarter', + }, + }); expect(result).toEqual(mockEstimates); }); @@ -90,14 +88,13 @@ describe('AnalystResource', () => { const result = await analyst.getEstimates('AAPL', 'annual', 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'annual', - limit: 10, - }, - } -); + period: 'annual', + limit: 10, + }, + }); expect(result).toEqual(mockEstimates); }); @@ -106,13 +103,12 @@ describe('AnalystResource', () => { await analyst.getEstimates('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'annual', - }, - } -); + period: 'annual', + }, + }); }); it('should not include limit parameter when not provided', async () => { @@ -120,13 +116,12 @@ describe('AnalystResource', () => { await analyst.getEstimates('AAPL', 'annual'); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'annual', - }, - } -); + period: 'annual', + }, + }); }); it('should handle API errors', async () => { @@ -159,12 +154,11 @@ describe('AnalystResource', () => { const result = await analyst.getPriceTargets('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target', { + expect(mockClient.get).toHaveBeenCalledWith('price-target', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockPriceTargets); }); @@ -173,12 +167,11 @@ describe('AnalystResource', () => { await analyst.getPriceTargets('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target', { + expect(mockClient.get).toHaveBeenCalledWith('price-target', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); }); it('should handle authentication errors', async () => { @@ -212,12 +205,11 @@ describe('AnalystResource', () => { const result = await analyst.getPriceTargetSummary('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target-summary', { + expect(mockClient.get).toHaveBeenCalledWith('price-target-summary', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockSummary[0]); }); @@ -235,12 +227,11 @@ describe('AnalystResource', () => { await analyst.getPriceTargetSummary('tsla'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target-summary', { + expect(mockClient.get).toHaveBeenCalledWith('price-target-summary', { searchParams: { symbol: 'TSLA', - }, - } -); + }, + }); }); }); @@ -260,12 +251,11 @@ describe('AnalystResource', () => { const result = await analyst.getPriceTargetConsensus('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target-consensus', { + expect(mockClient.get).toHaveBeenCalledWith('price-target-consensus', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockConsensus[0]); }); @@ -283,12 +273,11 @@ describe('AnalystResource', () => { await analyst.getPriceTargetConsensus('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target-consensus', { + expect(mockClient.get).toHaveBeenCalledWith('price-target-consensus', { searchParams: { symbol: 'MSFT', - }, - } -); + }, + }); }); it('should handle rate limit errors', async () => { @@ -319,20 +308,20 @@ describe('AnalystResource', () => { const result = await analyst.getRecommendations('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-stock-recommendations/AAPL' - ); + expect(mockClient.get).toHaveBeenCalledWith('analyst-stock-recommendations', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockRecommendations); }); - it('should normalize symbol to uppercase in URL', async () => { + it('should normalize symbol to uppercase', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockRecommendations); await analyst.getRecommendations('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-stock-recommendations/AAPL' - ); + expect(mockClient.get).toHaveBeenCalledWith('analyst-stock-recommendations', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle mixed case symbols', async () => { @@ -340,9 +329,9 @@ describe('AnalystResource', () => { await analyst.getRecommendations('AaPl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-stock-recommendations/AAPL' - ); + expect(mockClient.get).toHaveBeenCalledWith('analyst-stock-recommendations', { + searchParams: { symbol: 'AAPL' }, + }); }); }); @@ -369,12 +358,11 @@ describe('AnalystResource', () => { const result = await analyst.getGrades('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/grade', { + expect(mockClient.get).toHaveBeenCalledWith('grades', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockGrades); }); @@ -383,13 +371,12 @@ describe('AnalystResource', () => { const result = await analyst.getGrades('AAPL', 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/grade', { + expect(mockClient.get).toHaveBeenCalledWith('grades', { searchParams: { symbol: 'AAPL', - limit: 5, - }, - } -); + limit: 5, + }, + }); expect(result).toEqual(mockGrades); }); @@ -398,13 +385,12 @@ describe('AnalystResource', () => { await analyst.getGrades('googl', 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/grade', { + expect(mockClient.get).toHaveBeenCalledWith('grades', { searchParams: { symbol: 'GOOGL', - limit: 10, - }, - } -); + limit: 10, + }, + }); }); it('should not include limit parameter when not provided', async () => { @@ -421,12 +407,11 @@ describe('AnalystResource', () => { await analyst.getGrades('AAPL', 0); - expect(mockClient.get).toHaveBeenCalledWith('v3/grade', { + expect(mockClient.get).toHaveBeenCalledWith('grades', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); }); }); @@ -448,15 +433,11 @@ describe('AnalystResource', () => { const result = await analyst.getUpgradesDowngradesConsensus('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/upgrades-downgrades-consensus', - { - searchParams: { - symbol: 'AAPL', + expect(mockClient.get).toHaveBeenCalledWith('grades-consensus', { + searchParams: { + symbol: 'AAPL', }, - } - - ); + }); expect(result).toEqual(mockConsensus[0]); }); @@ -474,15 +455,11 @@ describe('AnalystResource', () => { await analyst.getUpgradesDowngradesConsensus('nvda'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/upgrades-downgrades-consensus', - { - searchParams: { - symbol: 'NVDA', + expect(mockClient.get).toHaveBeenCalledWith('grades-consensus', { + searchParams: { + symbol: 'NVDA', }, - } - - ); + }); }); }); @@ -504,7 +481,9 @@ describe('AnalystResource', () => { const result = await analyst.getRatingsSnapshot('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/rating/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('rating', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockRatings[0]); }); @@ -517,12 +496,14 @@ describe('AnalystResource', () => { expect(Array.isArray(result)).toBe(false); }); - it('should normalize symbol to uppercase in URL', async () => { + it('should normalize symbol to uppercase', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockRatings); await analyst.getRatingsSnapshot('meta'); - expect(mockClient.get).toHaveBeenCalledWith('v3/rating/META'); + expect(mockClient.get).toHaveBeenCalledWith('rating', { + searchParams: { symbol: 'META' }, + }); }); }); @@ -556,10 +537,9 @@ describe('AnalystResource', () => { const result = await analyst.getHistoricalGrades('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-rating/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockHistoricalGrades); }); @@ -568,26 +548,26 @@ describe('AnalystResource', () => { const result = await analyst.getHistoricalGrades('AAPL', 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-rating/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { searchParams: { + symbol: 'AAPL', limit: 10, - }, - } -); + }, + }); expect(result).toEqual(mockHistoricalGrades); }); - it('should normalize symbol to uppercase in URL', async () => { + it('should normalize symbol to uppercase', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockHistoricalGrades); await analyst.getHistoricalGrades('amzn', 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-rating/AMZN', { + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { searchParams: { + symbol: 'AMZN', limit: 20, - }, - } -); + }, + }); }); it('should not include limit parameter when not provided', async () => { @@ -595,8 +575,9 @@ describe('AnalystResource', () => { await analyst.getHistoricalGrades('AAPL'); - const call = vi.mocked(mockClient.get).mock.calls[0]; - expect(call[1]).toEqual({ searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle limit of 0', async () => { @@ -604,10 +585,9 @@ describe('AnalystResource', () => { await analyst.getHistoricalGrades('AAPL', 0); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-rating/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle large limit values', async () => { @@ -615,12 +595,12 @@ describe('AnalystResource', () => { await analyst.getHistoricalGrades('AAPL', 1000); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-rating/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('grades-historical', { searchParams: { + symbol: 'AAPL', limit: 1000, - }, - } -); + }, + }); }); }); @@ -668,7 +648,7 @@ describe('AnalystResource', () => { it('should handle already uppercase symbols', async () => { await analyst.getEstimates('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ symbol: 'AAPL' }) }) @@ -678,7 +658,7 @@ describe('AnalystResource', () => { it('should handle lowercase symbols', async () => { await analyst.getEstimates('aapl'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ symbol: 'AAPL' }) }) @@ -688,7 +668,7 @@ describe('AnalystResource', () => { it('should handle mixed case symbols', async () => { await analyst.getEstimates('AaPl'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ symbol: 'AAPL' }) }) @@ -698,7 +678,7 @@ describe('AnalystResource', () => { it('should handle symbols with special characters', async () => { await analyst.getEstimates('BRK.B'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ symbol: 'BRK.B' }) }) @@ -708,7 +688,7 @@ describe('AnalystResource', () => { it('should handle symbols with hyphens', async () => { await analyst.getEstimates('some-etf'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ symbol: 'SOME-ETF' }) }) @@ -724,7 +704,7 @@ describe('AnalystResource', () => { it('should default to annual period', async () => { await analyst.getEstimates('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ period: 'annual' }) }) @@ -734,7 +714,7 @@ describe('AnalystResource', () => { it('should accept annual period explicitly', async () => { await analyst.getEstimates('AAPL', 'annual'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ period: 'annual' }) }) @@ -744,7 +724,7 @@ describe('AnalystResource', () => { it('should accept quarter period', async () => { await analyst.getEstimates('AAPL', 'quarter'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/analyst-estimates', + 'analyst-estimates', expect.objectContaining({ searchParams: expect.objectContaining({ period: 'quarter' }) }) @@ -753,14 +733,13 @@ describe('AnalystResource', () => { it('should combine period with limit', async () => { await analyst.getEstimates('AAPL', 'quarter', 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/analyst-estimates', { + expect(mockClient.get).toHaveBeenCalledWith('analyst-estimates', { searchParams: { symbol: 'AAPL', - period: 'quarter', - limit: 5, - }, - } -); + period: 'quarter', + limit: 5, + }, + }); }); }); @@ -784,7 +763,7 @@ describe('AnalystResource', () => { it('should include limit when positive number', async () => { await analyst.getGrades('AAPL', 10); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/grade', + 'grades', expect.objectContaining({ searchParams: expect.objectContaining({ limit: 10, symbol: 'AAPL' }) }) @@ -794,7 +773,7 @@ describe('AnalystResource', () => { it('should handle limit value of 1', async () => { await analyst.getHistoricalGrades('AAPL', 1); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-rating/AAPL', + 'grades-historical', expect.objectContaining({ searchParams: expect.objectContaining({ limit: 1 }) }) diff --git a/tests/bulk.test.ts b/tests/bulk.test.ts index f90af93..e4c4c77 100644 --- a/tests/bulk.test.ts +++ b/tests/bulk.test.ts @@ -120,7 +120,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllProfiles(); - expect(mockClient.get).toHaveBeenCalledWith('v4/profile/all'); + expect(mockClient.get).toHaveBeenCalledWith('profile-bulk', { searchParams: { part: 0 } }); expect(result).toEqual(mockProfiles); expect(result).toHaveLength(2); }); @@ -162,7 +162,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllRatings(); - expect(mockClient.get).toHaveBeenCalledWith('v4/rating'); + expect(mockClient.get).toHaveBeenCalledWith('rating-bulk'); expect(result).toEqual(mockRatings); expect(result).toHaveLength(2); }); @@ -189,7 +189,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllDCF(); - expect(mockClient.get).toHaveBeenCalledWith('v4/dcf'); + expect(mockClient.get).toHaveBeenCalledWith('dcf-bulk'); expect(result).toEqual(mockDCF); }); }); @@ -215,7 +215,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllScores(); - expect(mockClient.get).toHaveBeenCalledWith('v4/score'); + expect(mockClient.get).toHaveBeenCalledWith('scores-bulk'); expect(result).toEqual(mockScores); }); }); @@ -242,7 +242,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllPriceTargets(); - expect(mockClient.get).toHaveBeenCalledWith('v4/price-target'); + expect(mockClient.get).toHaveBeenCalledWith('price-target-summary-bulk'); expect(result).toEqual(mockTargets); }); }); @@ -270,7 +270,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllETFHoldings(); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-holder'); + expect(mockClient.get).toHaveBeenCalledWith('etf-holder-bulk', { searchParams: { part: 1 } }); expect(result).toEqual(mockHoldings); }); }); @@ -298,7 +298,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllUpgradesDowngrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/upgrades-downgrades'); + expect(mockClient.get).toHaveBeenCalledWith('upgrades-downgrades-consensus-bulk'); expect(result).toEqual(mockGrades); }); }); @@ -375,7 +375,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllKeyMetricsTTM(); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics-ttm'); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics-ttm-bulk'); expect(result).toEqual(mockMetrics); }); }); @@ -448,7 +448,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllRatiosTTM(); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios-ttm'); + expect(mockClient.get).toHaveBeenCalledWith('ratios-ttm-bulk'); expect(result).toEqual(mockRatios); }); }); @@ -470,7 +470,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllPeers(); - expect(mockClient.get).toHaveBeenCalledWith('v4/stock_peers'); + expect(mockClient.get).toHaveBeenCalledWith('peers-bulk'); expect(result).toEqual(mockPeers); }); }); @@ -496,7 +496,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllEarningsSurprises(); - expect(mockClient.get).toHaveBeenCalledWith('v3/earnings-surprises'); + expect(mockClient.get).toHaveBeenCalledWith('earnings-surprises-bulk'); expect(result).toEqual(mockSurprises); }); }); @@ -550,7 +550,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatements(); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement', { searchParams: { period: 'annual' }, } + expect(mockClient.get).toHaveBeenCalledWith('income-statement-bulk', { searchParams: { period: 'annual' }, } ); expect(result).toEqual(mockStatements); }); @@ -562,7 +562,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatements('quarter'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement', { searchParams: { period: 'quarter' }, } + expect(mockClient.get).toHaveBeenCalledWith('income-statement-bulk', { searchParams: { period: 'quarter' }, } ); expect(result).toEqual(mockStatements); }); @@ -574,7 +574,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatements('annual', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement', { + expect(mockClient.get).toHaveBeenCalledWith('income-statement-bulk', { searchParams: { period: 'annual', year: 2023, @@ -591,7 +591,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatements('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement', { + expect(mockClient.get).toHaveBeenCalledWith('income-statement-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -642,7 +642,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatementGrowth(); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('income-statement-growth-bulk', { searchParams: { period: 'annual', }, @@ -658,7 +658,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllIncomeStatementGrowth('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('income-statement-growth-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -734,7 +734,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllBalanceSheets(); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement', { + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-bulk', { searchParams: { period: 'annual', }, @@ -750,7 +750,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllBalanceSheets('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement', { + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -814,7 +814,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllBalanceSheetGrowth(); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-growth-bulk', { searchParams: { period: 'annual', }, @@ -830,7 +830,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllBalanceSheetGrowth('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-growth-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -892,7 +892,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllCashFlowStatements(); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement', { + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-bulk', { searchParams: { period: 'annual', }, @@ -908,7 +908,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllCashFlowStatements('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement', { + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -963,7 +963,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllCashFlowStatementGrowth(); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-growth-bulk', { searchParams: { period: 'annual', }, @@ -979,7 +979,7 @@ describe('BulkResource', () => { const result = await bulkResource.getAllCashFlowStatementGrowth('quarter', 2023); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-growth', { + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-growth-bulk', { searchParams: { period: 'quarter', year: 2023, @@ -1019,7 +1019,7 @@ describe('BulkResource', () => { const result = await bulkResource.getBatchEODPrices('2024-01-15'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch-request-end-of-day-prices', { + expect(mockClient.get).toHaveBeenCalledWith('eod-bulk', { searchParams: { date: '2024-01-15', }, @@ -1036,7 +1036,7 @@ describe('BulkResource', () => { await bulkResource.getBatchEODPrices('2023-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch-request-end-of-day-prices', { + expect(mockClient.get).toHaveBeenCalledWith('eod-bulk', { searchParams: { date: '2023-12-31', }, @@ -1094,7 +1094,7 @@ describe('BulkResource', () => { const result = await bulkResource.getBatchEODPricesRange('2024-01-15', '2024-01-16'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch-request-end-of-day-prices', { + expect(mockClient.get).toHaveBeenCalledWith('eod-bulk', { searchParams: { from: '2024-01-15', to: '2024-01-16', @@ -1112,7 +1112,7 @@ describe('BulkResource', () => { await bulkResource.getBatchEODPricesRange('2024-01-15', '2024-01-15'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch-request-end-of-day-prices', { + expect(mockClient.get).toHaveBeenCalledWith('eod-bulk', { searchParams: { from: '2024-01-15', to: '2024-01-15', @@ -1128,7 +1128,7 @@ describe('BulkResource', () => { await bulkResource.getBatchEODPricesRange('2024-01-01', '2024-03-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch-request-end-of-day-prices', { + expect(mockClient.get).toHaveBeenCalledWith('eod-bulk', { searchParams: { from: '2024-01-01', to: '2024-03-31', diff --git a/tests/commodities.test.ts b/tests/commodities.test.ts index 1cf12fa..d8b166d 100644 --- a/tests/commodities.test.ts +++ b/tests/commodities.test.ts @@ -51,7 +51,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getList(); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/available-commodities'); + expect(mockClient.get).toHaveBeenCalledWith('commodities-list'); expect(result).toEqual(mockData); expect(result).toHaveLength(3); }); @@ -99,7 +99,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuote('GCUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/GCUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'GCUSD' } }); expect(result).toEqual(mockQuote); }); @@ -108,7 +108,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuote('gcusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/GCUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'GCUSD' } }); expect(result).toEqual(mockQuote); }); @@ -117,7 +117,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuote('GcUsD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/GCUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'GCUSD' } }); expect(result).toEqual(mockQuote); }); @@ -153,7 +153,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuote('SIUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/SIUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'SIUSD' } }); expect(result).toEqual(silverQuote); expect(result[0].symbol).toBe('SIUSD'); }); @@ -163,7 +163,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuote('INVALID'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/INVALID'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'INVALID' } }); expect(result).toEqual([]); }); }); @@ -182,7 +182,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getQuoteShort('GCUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/GCUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { searchParams: { symbol: 'GCUSD' } }); expect(result).toEqual(mockShortQuote); }); @@ -191,7 +191,7 @@ describe('CommoditiesResource', () => { await commodities.getQuoteShort('clusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/CLUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { searchParams: { symbol: 'CLUSD' } }); }); it('should handle empty response', async () => { @@ -260,7 +260,7 @@ describe('CommoditiesResource', () => { const result = await commodities.getAllQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/commodity'); + expect(mockClient.get).toHaveBeenCalledWith('batch-commodity-quotes'); expect(result).toEqual(mockAllQuotes); expect(result).toHaveLength(2); }); @@ -316,8 +316,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getHistoricalPrices('GCUSD'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: {} } + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockHistoricalData); expect(result.historical).toHaveLength(2); @@ -329,9 +329,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getHistoricalPrices('GCUSD', '2024-01-01'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { from: '2024-01-01' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01' } } ); expect(result).toEqual(mockHistoricalData); }); @@ -342,9 +341,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getHistoricalPrices('GCUSD', undefined, '2024-01-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { to: '2024-01-31' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', to: '2024-01-31' } } ); expect(result).toEqual(mockHistoricalData); }); @@ -359,9 +357,8 @@ describe('CommoditiesResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01', to: '2024-01-31' } } ); expect(result).toEqual(mockHistoricalData); }); @@ -372,9 +369,8 @@ describe('CommoditiesResource', () => { await commodities.getHistoricalPrices('siusd', '2024-01-01', '2024-01-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/SIUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'SIUSD', from: '2024-01-01', to: '2024-01-31' } } ); }); @@ -384,9 +380,8 @@ describe('CommoditiesResource', () => { await commodities.getHistoricalPrices('GCUSD', '2024-12-01', '2024-12-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { from: '2024-12-01', to: '2024-12-31' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', from: '2024-12-01', to: '2024-12-31' } } ); }); @@ -428,8 +423,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getLightChart('GCUSD'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GCUSD', - { searchParams: {} } + 'historical-price-eod/light', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockLightChartData); expect(result).toHaveLength(3); @@ -443,9 +438,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getLightChart('GCUSD', '2024-01-01'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GCUSD', - { searchParams: { from: '2024-01-01' }, } - + 'historical-price-eod/light', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01' } } ); expect(result).toEqual(mockLightChartData); }); @@ -456,9 +450,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getLightChart('GCUSD', undefined, '2024-01-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GCUSD', - { searchParams: { to: '2024-01-31' }, } - + 'historical-price-eod/light', + { searchParams: { symbol: 'GCUSD', to: '2024-01-31' } } ); expect(result).toEqual(mockLightChartData); }); @@ -473,9 +466,8 @@ describe('CommoditiesResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-price-eod/light', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01', to: '2024-01-31' } } ); expect(result).toEqual(mockLightChartData); }); @@ -486,9 +478,8 @@ describe('CommoditiesResource', () => { await commodities.getLightChart('clusd', '2024-01-01', '2024-01-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/CLUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-price-eod/light', + { searchParams: { symbol: 'CLUSD', from: '2024-01-01', to: '2024-01-31' } } ); }); @@ -527,8 +518,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/GCUSD', - { searchParams: {} } + 'historical-chart/1hour', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -539,8 +530,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD', '1min'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/GCUSD', - { searchParams: {} } + 'historical-chart/1min', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -551,8 +542,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD', '5min'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/GCUSD', - { searchParams: {} } + 'historical-chart/5min', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -563,8 +554,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD', '15min'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/15min/GCUSD', - { searchParams: {} } + 'historical-chart/15min', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -575,8 +566,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD', '30min'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/30min/GCUSD', - { searchParams: {} } + 'historical-chart/30min', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -587,8 +578,8 @@ describe('CommoditiesResource', () => { const result = await commodities.getIntradayChart('GCUSD', '4hour'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/4hour/GCUSD', - { searchParams: {} } + 'historical-chart/4hour', + { searchParams: { symbol: 'GCUSD' } } ); expect(result).toEqual(mockIntradayData); }); @@ -603,9 +594,8 @@ describe('CommoditiesResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/GCUSD', - { searchParams: { from: '2024-01-01' }, } - + 'historical-chart/1hour', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01' } } ); expect(result).toEqual(mockIntradayData); }); @@ -621,9 +611,8 @@ describe('CommoditiesResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/GCUSD', - { searchParams: { to: '2024-01-31' }, } - + 'historical-chart/1hour', + { searchParams: { symbol: 'GCUSD', to: '2024-01-31' } } ); expect(result).toEqual(mockIntradayData); }); @@ -639,9 +628,8 @@ describe('CommoditiesResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/GCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-chart/1hour', + { searchParams: { symbol: 'GCUSD', from: '2024-01-01', to: '2024-01-31' } } ); expect(result).toEqual(mockIntradayData); }); @@ -652,9 +640,8 @@ describe('CommoditiesResource', () => { await commodities.getIntradayChart('siusd', '15min', '2024-01-01', '2024-01-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/15min/SIUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - + 'historical-chart/15min', + { searchParams: { symbol: 'SIUSD', from: '2024-01-01', to: '2024-01-31' } } ); }); @@ -716,7 +703,7 @@ describe('CommoditiesResource', () => { await commodities.getQuote('GC=F'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/GC=F'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'GC=F' } }); }); it('should handle empty string symbol', async () => { @@ -724,7 +711,7 @@ describe('CommoditiesResource', () => { await commodities.getQuote(''); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '' } }); }); it('should handle symbols with whitespace', async () => { @@ -732,7 +719,7 @@ describe('CommoditiesResource', () => { await commodities.getQuote(' GCUSD '); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/ GCUSD '); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: ' GCUSD ' } }); }); }); @@ -744,9 +731,8 @@ describe('CommoditiesResource', () => { await commodities.getHistoricalPrices('GCUSD', '2024-12-31', '2024-01-01'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { from: '2024-12-31', to: '2024-01-01' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', from: '2024-12-31', to: '2024-01-01' } } ); }); @@ -756,9 +742,8 @@ describe('CommoditiesResource', () => { await commodities.getHistoricalPrices('GCUSD', '2024-01-15', '2024-01-15'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GCUSD', - { searchParams: { from: '2024-01-15', to: '2024-01-15' }, } - + 'historical-price-eod/full', + { searchParams: { symbol: 'GCUSD', from: '2024-01-15', to: '2024-01-15' } } ); }); @@ -768,8 +753,8 @@ describe('CommoditiesResource', () => { await commodities.getLightChart('GCUSD', undefined, undefined); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GCUSD', - { searchParams: {} } + 'historical-price-eod/light', + { searchParams: { symbol: 'GCUSD' } } ); }); }); diff --git a/tests/company.test.ts b/tests/company.test.ts index a24658a..7cbb6e6 100644 --- a/tests/company.test.ts +++ b/tests/company.test.ts @@ -24,7 +24,7 @@ import type { CompensationBenchmark, CIKMapping, SymbolChange, - Exchange, + ExchangeInfo, SectorIndustry, TradableSymbol, } from '../src/types/index.js'; @@ -87,7 +87,9 @@ describe('CompanyResource', () => { const result = await companyResource.getProfile('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/profile/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('profile', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockProfile); }); @@ -96,7 +98,9 @@ describe('CompanyResource', () => { await companyResource.getProfile('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/profile/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('profile', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -159,7 +163,9 @@ describe('CompanyResource', () => { const result = await companyResource.getQuote('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockQuote); }); @@ -168,7 +174,9 @@ describe('CompanyResource', () => { await companyResource.getQuote('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -213,7 +221,9 @@ describe('CompanyResource', () => { const result = await companyResource.getQuotes(['AAPL', 'MSFT']); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/AAPL,MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('batch-quote', { + searchParams: { symbols: 'AAPL,MSFT' }, + }); expect(result).toEqual(mockQuotes); }); @@ -222,7 +232,9 @@ describe('CompanyResource', () => { await companyResource.getQuotes(['aapl', 'msft', 'goog']); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/AAPL,MSFT,GOOG'); + expect(mockClient.get).toHaveBeenCalledWith('batch-quote', { + searchParams: { symbols: 'AAPL,MSFT,GOOG' }, + }); }); it('should handle empty array', async () => { @@ -230,7 +242,9 @@ describe('CompanyResource', () => { await companyResource.getQuotes([]); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/'); + expect(mockClient.get).toHaveBeenCalledWith('batch-quote', { + searchParams: { symbols: '' }, + }); }); it('should handle API errors', async () => { @@ -261,7 +275,7 @@ describe('CompanyResource', () => { const result = await companyResource.getSymbolsList(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock/list'); + expect(mockClient.get).toHaveBeenCalledWith('stock-list'); expect(result).toEqual(mockSymbols); }); @@ -291,7 +305,9 @@ describe('CompanyResource', () => { const result = await companyResource.getExchangeSymbols('NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/NASDAQ'); + expect(mockClient.get).toHaveBeenCalledWith('stock-list', { + searchParams: { exchange: 'NASDAQ' }, + }); expect(result).toEqual(mockSymbols); }); @@ -300,7 +316,9 @@ describe('CompanyResource', () => { await companyResource.getExchangeSymbols('nasdaq'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/NASDAQ'); + expect(mockClient.get).toHaveBeenCalledWith('stock-list', { + searchParams: { exchange: 'NASDAQ' }, + }); }); it('should handle API errors', async () => { @@ -331,7 +349,7 @@ describe('CompanyResource', () => { const result = await companyResource.search('Apple'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'Apple', limit: 10, @@ -345,7 +363,7 @@ describe('CompanyResource', () => { await companyResource.search('Apple', 25); - expect(mockClient.get).toHaveBeenCalledWith('v3/search', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'Apple', limit: 25, @@ -358,7 +376,7 @@ describe('CompanyResource', () => { await companyResource.search('Apple', 10, 'NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'Apple', limit: 10, @@ -423,7 +441,9 @@ describe('CompanyResource', () => { const result = await companyResource.getProfileByCIK('0000320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/profile/0000320193'); + expect(mockClient.get).toHaveBeenCalledWith('profile-cik', { + searchParams: { cik: '0000320193' }, + }); expect(result).toEqual(mockProfile); }); @@ -453,7 +473,7 @@ describe('CompanyResource', () => { const result = await companyResource.getCompanyNotes('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-notes', { + expect(mockClient.get).toHaveBeenCalledWith('company-notes', { searchParams: { symbol: 'AAPL', }, @@ -466,7 +486,7 @@ describe('CompanyResource', () => { await companyResource.getCompanyNotes('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-notes', { + expect(mockClient.get).toHaveBeenCalledWith('company-notes', { searchParams: { symbol: 'AAPL', }, @@ -497,7 +517,7 @@ describe('CompanyResource', () => { const result = await companyResource.getStockPeers('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/stock_peers', { + expect(mockClient.get).toHaveBeenCalledWith('stock-peers', { searchParams: { symbol: 'AAPL', }, @@ -510,7 +530,7 @@ describe('CompanyResource', () => { await companyResource.getStockPeers('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/stock_peers', { + expect(mockClient.get).toHaveBeenCalledWith('stock-peers', { searchParams: { symbol: 'AAPL', }, @@ -527,7 +547,7 @@ describe('CompanyResource', () => { }); describe('getDelistedCompanies', () => { - it('should get delisted companies without limit', async () => { + it('should get delisted companies with default pagination', async () => { const mockDelisted: DelistedCompany[] = [ { symbol: 'XYZ', @@ -542,17 +562,20 @@ describe('CompanyResource', () => { const result = await companyResource.getDelistedCompanies(); - expect(mockClient.get).toHaveBeenCalledWith('v3/delisted-companies', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('delisted-companies', { + searchParams: { page: 0, limit: 100 }, + }); expect(result).toEqual(mockDelisted); }); - it('should get delisted companies with limit', async () => { + it('should get delisted companies with custom pagination', async () => { vi.mocked(mockClient.get).mockResolvedValue([]); - await companyResource.getDelistedCompanies(50); + await companyResource.getDelistedCompanies(2, 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/delisted-companies', { + expect(mockClient.get).toHaveBeenCalledWith('delisted-companies', { searchParams: { + page: 2, limit: 50, }, }); @@ -587,7 +610,7 @@ describe('CompanyResource', () => { const result = await companyResource.getEmployeeCount('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/employee_count', { + expect(mockClient.get).toHaveBeenCalledWith('employee-count', { searchParams: { symbol: 'AAPL', }, @@ -600,7 +623,7 @@ describe('CompanyResource', () => { await companyResource.getEmployeeCount('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/employee_count', { + expect(mockClient.get).toHaveBeenCalledWith('employee-count', { searchParams: { symbol: 'AAPL', }, @@ -638,7 +661,7 @@ describe('CompanyResource', () => { const result = await companyResource.getHistoricalEmployeeCount('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical/employee_count', { + expect(mockClient.get).toHaveBeenCalledWith('historical-employee-count', { searchParams: { symbol: 'AAPL', }, @@ -651,7 +674,7 @@ describe('CompanyResource', () => { await companyResource.getHistoricalEmployeeCount('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical/employee_count', { + expect(mockClient.get).toHaveBeenCalledWith('historical-employee-count', { searchParams: { symbol: 'AAPL', }, @@ -683,7 +706,9 @@ describe('CompanyResource', () => { const result = await companyResource.getMarketCap('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/market-capitalization/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('market-capitalization', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockMarketCap); }); @@ -692,7 +717,9 @@ describe('CompanyResource', () => { await companyResource.getMarketCap('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/market-capitalization/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('market-capitalization', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -725,7 +752,9 @@ describe('CompanyResource', () => { const result = await companyResource.getBatchMarketCap(['AAPL', 'MSFT']); - expect(mockClient.get).toHaveBeenCalledWith('v3/market-capitalization/AAPL,MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('market-capitalization-batch', { + searchParams: { symbols: 'AAPL,MSFT' }, + }); expect(result).toEqual(mockMarketCaps); }); @@ -734,9 +763,9 @@ describe('CompanyResource', () => { await companyResource.getBatchMarketCap(['aapl', 'msft', 'goog']); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/market-capitalization/AAPL,MSFT,GOOG' - ); + expect(mockClient.get).toHaveBeenCalledWith('market-capitalization-batch', { + searchParams: { symbols: 'AAPL,MSFT,GOOG' }, + }); }); it('should handle API errors', async () => { @@ -764,14 +793,11 @@ describe('CompanyResource', () => { const result = await companyResource.getHistoricalMarketCap('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-market-capitalization/AAPL', - { - searchParams: { - symbol: 'AAPL', - }, - } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-market-capitalization', { + searchParams: { + symbol: 'AAPL', + }, + }); expect(result).toEqual(mockHistorical); }); @@ -780,15 +806,12 @@ describe('CompanyResource', () => { await companyResource.getHistoricalMarketCap('AAPL', 100); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-market-capitalization/AAPL', - { - searchParams: { - symbol: 'AAPL', - limit: 100, - }, - } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-market-capitalization', { + searchParams: { + symbol: 'AAPL', + limit: 100, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -796,14 +819,11 @@ describe('CompanyResource', () => { await companyResource.getHistoricalMarketCap('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-market-capitalization/AAPL', - { - searchParams: { - symbol: 'AAPL', - }, - } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-market-capitalization', { + searchParams: { + symbol: 'AAPL', + }, + }); }); it('should handle API errors', async () => { @@ -834,7 +854,7 @@ describe('CompanyResource', () => { const result = await companyResource.getSharesFloat('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/shares_float', { + expect(mockClient.get).toHaveBeenCalledWith('shares-float', { searchParams: { symbol: 'AAPL', }, @@ -847,7 +867,7 @@ describe('CompanyResource', () => { await companyResource.getSharesFloat('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/shares_float', { + expect(mockClient.get).toHaveBeenCalledWith('shares-float', { searchParams: { symbol: 'AAPL', }, @@ -882,7 +902,9 @@ describe('CompanyResource', () => { const result = await companyResource.getAllSharesFloat(); - expect(mockClient.get).toHaveBeenCalledWith('v4/shares_float/all'); + expect(mockClient.get).toHaveBeenCalledWith('shares-float-all', { + searchParams: { page: 0, limit: 1000 }, + }); expect(result).toEqual(mockAllShares); }); @@ -913,7 +935,9 @@ describe('CompanyResource', () => { const result = await companyResource.getMergerAcquisitions(); - expect(mockClient.get).toHaveBeenCalledWith('v4/mergers-acquisitions-rss-feed'); + expect(mockClient.get).toHaveBeenCalledWith('mergers-acquisitions-latest', { + searchParams: { page: 0, limit: 100 }, + }); expect(result).toEqual(mockMA); }); @@ -946,7 +970,7 @@ describe('CompanyResource', () => { const result = await companyResource.searchMergerAcquisitions('Apple'); - expect(mockClient.get).toHaveBeenCalledWith('v4/mergers-acquisitions/search', { + expect(mockClient.get).toHaveBeenCalledWith('mergers-acquisitions-search', { searchParams: { name: 'Apple', }, @@ -983,7 +1007,9 @@ describe('CompanyResource', () => { const result = await companyResource.getExecutives('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-executives/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('key-executives', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockExecutives); }); @@ -992,7 +1018,9 @@ describe('CompanyResource', () => { await companyResource.getExecutives('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-executives/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('key-executives', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -1032,7 +1060,7 @@ describe('CompanyResource', () => { const result = await companyResource.getExecutiveCompensation('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/governance/executive_compensation', { + expect(mockClient.get).toHaveBeenCalledWith('governance-executive-compensation', { searchParams: { symbol: 'AAPL', }, @@ -1045,7 +1073,7 @@ describe('CompanyResource', () => { await companyResource.getExecutiveCompensation('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/governance/executive_compensation', { + expect(mockClient.get).toHaveBeenCalledWith('governance-executive-compensation', { searchParams: { symbol: 'AAPL', }, @@ -1082,7 +1110,7 @@ describe('CompanyResource', () => { const result = await companyResource.getCompensationBenchmark(2023); - expect(mockClient.get).toHaveBeenCalledWith('v4/executive-compensation-benchmark', { + expect(mockClient.get).toHaveBeenCalledWith('executive-compensation-benchmark', { searchParams: { year: 2023, }, @@ -1118,7 +1146,7 @@ describe('CompanyResource', () => { const result = await companyResource.getFinancialStatementSymbols(); - expect(mockClient.get).toHaveBeenCalledWith('v3/financial-statement-symbol-lists'); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-symbol-list'); expect(result).toEqual(mockSymbols); }); @@ -1146,7 +1174,9 @@ describe('CompanyResource', () => { const result = await companyResource.getCIKList(); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik_list'); + expect(mockClient.get).toHaveBeenCalledWith('cik-list', { + searchParams: { page: 0, limit: 1000 }, + }); expect(result).toEqual(mockCIK); }); @@ -1174,7 +1204,7 @@ describe('CompanyResource', () => { const result = await companyResource.getSymbolChanges(); - expect(mockClient.get).toHaveBeenCalledWith('v4/symbol_change'); + expect(mockClient.get).toHaveBeenCalledWith('symbol-change'); expect(result).toEqual(mockChanges); }); @@ -1204,7 +1234,7 @@ describe('CompanyResource', () => { const result = await companyResource.getETFSymbols(); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf/list'); + expect(mockClient.get).toHaveBeenCalledWith('etf-list'); expect(result).toEqual(mockETFs); }); @@ -1232,7 +1262,7 @@ describe('CompanyResource', () => { const result = await companyResource.getActivelyTrading(); - expect(mockClient.get).toHaveBeenCalledWith('v3/available-traded/list'); + expect(mockClient.get).toHaveBeenCalledWith('actively-trading-list'); expect(result).toEqual(mockTrading); }); @@ -1245,41 +1275,9 @@ describe('CompanyResource', () => { }); }); - describe('getEarningsTranscriptsSymbols', () => { - it('should get earnings transcripts symbols successfully', async () => { - const mockSymbols: SymbolsList[] = [ - { - symbol: 'AAPL', - name: 'Apple Inc.', - price: 150.0, - exchange: 'NASDAQ Global Select', - exchangeShortName: 'NASDAQ', - type: 'stock', - }, - ]; - - vi.mocked(mockClient.get).mockResolvedValue(mockSymbols); - - const result = await companyResource.getEarningsTranscriptsSymbols(); - - expect(mockClient.get).toHaveBeenCalledWith('v4/earning_call_transcript'); - expect(result).toEqual(mockSymbols); - }); - - it('should handle API errors', async () => { - vi.mocked(mockClient.get).mockRejectedValue( - new FMPAPIError('Server error', 500, 'Internal Server Error') - ); - - await expect(companyResource.getEarningsTranscriptsSymbols()).rejects.toThrow( - FMPAPIError - ); - }); - }); - describe('getExchanges', () => { it('should get exchanges successfully', async () => { - const mockExchanges: Exchange[] = [ + const mockExchanges: ExchangeInfo[] = [ { name: 'NASDAQ', code: 'NASDAQ', @@ -1292,7 +1290,7 @@ describe('CompanyResource', () => { const result = await companyResource.getExchanges(); - expect(mockClient.get).toHaveBeenCalledWith('v3/exchanges-list'); + expect(mockClient.get).toHaveBeenCalledWith('available-exchanges'); expect(result).toEqual(mockExchanges); }); @@ -1317,7 +1315,7 @@ describe('CompanyResource', () => { const result = await companyResource.getSectors(); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-list'); + expect(mockClient.get).toHaveBeenCalledWith('available-sectors'); expect(result).toEqual(mockSectors); }); @@ -1342,7 +1340,7 @@ describe('CompanyResource', () => { const result = await companyResource.getIndustries(); - expect(mockClient.get).toHaveBeenCalledWith('v3/industry-list'); + expect(mockClient.get).toHaveBeenCalledWith('available-industries'); expect(result).toEqual(mockIndustries); }); @@ -1363,7 +1361,7 @@ describe('CompanyResource', () => { const result = await companyResource.getCountries(); - expect(mockClient.get).toHaveBeenCalledWith('v3/get-all-countries'); + expect(mockClient.get).toHaveBeenCalledWith('available-countries'); expect(result).toEqual(mockCountries); }); @@ -1384,7 +1382,9 @@ describe('CompanyResource', () => { const result = await companyResource.getQuoteShort('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockQuote); }); @@ -1393,7 +1393,9 @@ describe('CompanyResource', () => { await companyResource.getQuoteShort('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -1415,7 +1417,9 @@ describe('CompanyResource', () => { const result = await companyResource.getAftermarketTrade('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market-trade/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('aftermarket-trade', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockTrade); }); @@ -1424,7 +1428,9 @@ describe('CompanyResource', () => { await companyResource.getAftermarketTrade('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market-trade/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('aftermarket-trade', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -1446,7 +1452,9 @@ describe('CompanyResource', () => { const result = await companyResource.getAftermarketQuote('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('aftermarket-quote', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockQuote); }); @@ -1455,7 +1463,9 @@ describe('CompanyResource', () => { await companyResource.getAftermarketQuote('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('aftermarket-quote', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -1479,7 +1489,9 @@ describe('CompanyResource', () => { const result = await companyResource.getPriceChange('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-price-change/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('stock-price-change', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockChange); }); @@ -1488,7 +1500,9 @@ describe('CompanyResource', () => { await companyResource.getPriceChange('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-price-change/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('stock-price-change', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -1513,7 +1527,9 @@ describe('CompanyResource', () => { const result = await companyResource.getBatchQuotesShort(['AAPL', 'MSFT']); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/AAPL,MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'AAPL,MSFT' }, + }); expect(result).toEqual(mockQuotes); }); @@ -1522,7 +1538,9 @@ describe('CompanyResource', () => { await companyResource.getBatchQuotesShort(['aapl', 'msft', 'goog']); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/AAPL,MSFT,GOOG'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'AAPL,MSFT,GOOG' }, + }); }); it('should handle API errors', async () => { @@ -1536,42 +1554,6 @@ describe('CompanyResource', () => { }); }); - describe('getBatchAftermarketTrades', () => { - it('should get batch aftermarket trades successfully', async () => { - const mockTrades = [ - { symbol: 'AAPL', price: 150.5, volume: 100000 }, - { symbol: 'MSFT', price: 350.5, volume: 75000 }, - ]; - - vi.mocked(mockClient.get).mockResolvedValue(mockTrades); - - const result = await companyResource.getBatchAftermarketTrades(['AAPL', 'MSFT']); - - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market-trade/AAPL,MSFT'); - expect(result).toEqual(mockTrades); - }); - - it('should normalize symbols to uppercase', async () => { - vi.mocked(mockClient.get).mockResolvedValue([]); - - await companyResource.getBatchAftermarketTrades(['aapl', 'msft', 'goog']); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/pre-post-market-trade/AAPL,MSFT,GOOG' - ); - }); - - it('should handle API errors', async () => { - vi.mocked(mockClient.get).mockRejectedValue( - new FMPAPIError('Server error', 500, 'Internal Server Error') - ); - - await expect( - companyResource.getBatchAftermarketTrades(['AAPL', 'MSFT']) - ).rejects.toThrow(FMPAPIError); - }); - }); - describe('getBatchAftermarketQuotes', () => { it('should get batch aftermarket quotes successfully', async () => { const mockQuotes = [ @@ -1583,7 +1565,9 @@ describe('CompanyResource', () => { const result = await companyResource.getBatchAftermarketQuotes(['AAPL', 'MSFT']); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market/AAPL,MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('batch-aftermarket-quote', { + searchParams: { symbols: 'AAPL,MSFT' }, + }); expect(result).toEqual(mockQuotes); }); @@ -1592,7 +1576,9 @@ describe('CompanyResource', () => { await companyResource.getBatchAftermarketQuotes(['aapl', 'msft', 'goog']); - expect(mockClient.get).toHaveBeenCalledWith('v4/pre-post-market/AAPL,MSFT,GOOG'); + expect(mockClient.get).toHaveBeenCalledWith('batch-aftermarket-quote', { + searchParams: { symbols: 'AAPL,MSFT,GOOG' }, + }); }); it('should handle API errors', async () => { @@ -1617,7 +1603,7 @@ describe('CompanyResource', () => { const result = await companyResource.getMutualFundQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/mutual_fund'); + expect(mockClient.get).toHaveBeenCalledWith('batch-mutualfund-quotes'); expect(result).toEqual(mockQuotes); }); @@ -1641,7 +1627,7 @@ describe('CompanyResource', () => { const result = await companyResource.getETFQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/etf'); + expect(mockClient.get).toHaveBeenCalledWith('batch-etf-quotes'); expect(result).toEqual(mockQuotes); }); @@ -1665,7 +1651,7 @@ describe('CompanyResource', () => { const result = await companyResource.getCommoditiesQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/commodity'); + expect(mockClient.get).toHaveBeenCalledWith('batch-commodity-quotes'); expect(result).toEqual(mockQuotes); }); @@ -1689,7 +1675,7 @@ describe('CompanyResource', () => { const result = await companyResource.getIndexQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/index'); + expect(mockClient.get).toHaveBeenCalledWith('batch-index-quotes'); expect(result).toEqual(mockQuotes); }); diff --git a/tests/cot.test.ts b/tests/cot.test.ts index 228aa87..330e45e 100644 --- a/tests/cot.test.ts +++ b/tests/cot.test.ts @@ -51,12 +51,9 @@ describe('COTResource', () => { const result = await cotResource.getReport('GC'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC' } + }); expect(result).toEqual(mockReportData); }); @@ -65,12 +62,9 @@ describe('COTResource', () => { await cotResource.getReport('gc'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC' } + }); }); it('should fetch COT report with from date', async () => { @@ -78,13 +72,9 @@ describe('COTResource', () => { const result = await cotResource.getReport('GC', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - from: '2024-01-01', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC', from: '2024-01-01' } + }); expect(result).toEqual(mockReportData); }); @@ -93,13 +83,9 @@ describe('COTResource', () => { const result = await cotResource.getReport('GC', undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC', to: '2024-12-31' } + }); expect(result).toEqual(mockReportData); }); @@ -108,14 +94,9 @@ describe('COTResource', () => { const result = await cotResource.getReport('GC', '2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - from: '2024-01-01', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC', from: '2024-01-01', to: '2024-12-31' } + }); expect(result).toEqual(mockReportData); }); @@ -191,12 +172,9 @@ describe('COTResource', () => { const result = await cotResource.getAnalysis('CL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL' } + }); expect(result).toEqual(mockAnalysisData); }); @@ -205,12 +183,9 @@ describe('COTResource', () => { await cotResource.getAnalysis('cl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL' } + }); }); it('should fetch COT analysis with from date', async () => { @@ -218,13 +193,9 @@ describe('COTResource', () => { const result = await cotResource.getAnalysis('CL', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - from: '2024-01-01', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL', from: '2024-01-01' } + }); expect(result).toEqual(mockAnalysisData); }); @@ -233,13 +204,9 @@ describe('COTResource', () => { const result = await cotResource.getAnalysis('CL', undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL', to: '2024-12-31' } + }); expect(result).toEqual(mockAnalysisData); }); @@ -248,14 +215,9 @@ describe('COTResource', () => { const result = await cotResource.getAnalysis('CL', '2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - from: '2024-01-01', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL', from: '2024-01-01', to: '2024-12-31' } + }); expect(result).toEqual(mockAnalysisData); }); @@ -335,7 +297,7 @@ describe('COTResource', () => { const result = await cotResource.getSymbols(); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report/list'); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-list'); expect(result).toEqual(mockSymbolsData); }); @@ -345,7 +307,7 @@ describe('COTResource', () => { const result = await cotResource.getSymbols(); expect(mockClient.get).toHaveBeenCalledTimes(1); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report/list'); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-list'); expect(result).toHaveLength(4); }); @@ -421,12 +383,9 @@ describe('COTResource', () => { await cotResource.getReport('ES_F'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'ES_F', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'ES_F' } + }); }); it('should handle mixed case symbols correctly', async () => { @@ -435,12 +394,9 @@ describe('COTResource', () => { await cotResource.getReport('GcEuR'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GCEUR', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GCEUR' } + }); }); it('should not modify date format when passed', async () => { @@ -449,14 +405,9 @@ describe('COTResource', () => { await cotResource.getReport('GC', '2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report', { - searchParams: { - symbol: 'GC', - from: '2024-01-01', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-report', { + searchParams: { symbol: 'GC', from: '2024-01-01', to: '2024-12-31' } + }); }); it('should handle only from date without to date', async () => { @@ -465,13 +416,9 @@ describe('COTResource', () => { await cotResource.getAnalysis('CL', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - from: '2024-01-01', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL', from: '2024-01-01' } + }); expect(mockClient.get).toHaveBeenCalledTimes(1); }); @@ -481,13 +428,9 @@ describe('COTResource', () => { await cotResource.getAnalysis('CL', undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/commitment_of_traders_report_analysis', { - searchParams: { - symbol: 'CL', - to: '2024-12-31', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('commitment-of-traders-analysis', { + searchParams: { symbol: 'CL', to: '2024-12-31' } + }); expect(mockClient.get).toHaveBeenCalledTimes(1); }); }); @@ -515,7 +458,7 @@ describe('COTResource', () => { await cotResource.getReport('GC'); const [[endpoint]] = vi.mocked(mockClient.get).mock.calls; - expect(endpoint).toBe('v4/commitment_of_traders_report'); + expect(endpoint).toBe('commitment-of-traders-report'); }); it('should call correct endpoint for getAnalysis', async () => { @@ -524,7 +467,7 @@ describe('COTResource', () => { await cotResource.getAnalysis('CL'); const [[endpoint]] = vi.mocked(mockClient.get).mock.calls; - expect(endpoint).toBe('v4/commitment_of_traders_report_analysis'); + expect(endpoint).toBe('commitment-of-traders-analysis'); }); it('should call correct endpoint for getSymbols', async () => { @@ -533,7 +476,7 @@ describe('COTResource', () => { await cotResource.getSymbols(); const [[endpoint]] = vi.mocked(mockClient.get).mock.calls; - expect(endpoint).toBe('v4/commitment_of_traders_report/list'); + expect(endpoint).toBe('commitment-of-traders-list'); }); }); }); diff --git a/tests/economics.test.ts b/tests/economics.test.ts index bfbf3d8..b66f917 100644 --- a/tests/economics.test.ts +++ b/tests/economics.test.ts @@ -82,7 +82,7 @@ describe('EconomicsResource', () => { const result = await economics.getTreasuryRates(); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: {} }); expect(result).toEqual(mockTreasuryRates); expect(result).toHaveLength(2); expect(result[0]).toHaveProperty('date'); @@ -94,12 +94,11 @@ describe('EconomicsResource', () => { const result = await economics.getTreasuryRates('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); expect(result).toEqual(mockTreasuryRates); }); @@ -108,12 +107,11 @@ describe('EconomicsResource', () => { const result = await economics.getTreasuryRates(undefined, '2024-01-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { to: '2024-01-31', - }, - } -); + }, + }); expect(result).toEqual(mockTreasuryRates); }); @@ -122,13 +120,12 @@ describe('EconomicsResource', () => { const result = await economics.getTreasuryRates('2024-01-01', '2024-01-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '2024-01-01', - to: '2024-01-31', - }, - } -); + to: '2024-01-31', + }, + }); expect(result).toEqual(mockTreasuryRates); }); @@ -153,13 +150,12 @@ describe('EconomicsResource', () => { // Test with various date formats - API should handle validation await economics.getTreasuryRates('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); }); @@ -169,12 +165,11 @@ describe('EconomicsResource', () => { const result = await economics.getIndicator('GDP'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'GDP', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -183,13 +178,12 @@ describe('EconomicsResource', () => { const result = await economics.getIndicator('realGDP', '2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'realGDP', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -198,13 +192,12 @@ describe('EconomicsResource', () => { const result = await economics.getIndicator('CPI', undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'CPI', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -213,14 +206,13 @@ describe('EconomicsResource', () => { const result = await economics.getIndicator('inflationRate', '2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'inflationRate', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -256,12 +248,11 @@ describe('EconomicsResource', () => { for (const indicator of indicators) { vi.mocked(mockClient.get).mockClear(); await economics.getIndicator(indicator); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: indicator, - }, - } -); + }, + }); } }); @@ -288,12 +279,11 @@ describe('EconomicsResource', () => { const result = await economics.getGDP(); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'GDP', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -302,13 +292,12 @@ describe('EconomicsResource', () => { const result = await economics.getGDP('2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'GDP', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -317,14 +306,13 @@ describe('EconomicsResource', () => { const result = await economics.getGDP('2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'GDP', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); }); @@ -335,12 +323,11 @@ describe('EconomicsResource', () => { const result = await economics.getCPI(); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'CPI', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -349,13 +336,12 @@ describe('EconomicsResource', () => { const result = await economics.getCPI('2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'CPI', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -364,14 +350,13 @@ describe('EconomicsResource', () => { const result = await economics.getCPI('2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'CPI', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); }); @@ -382,12 +367,11 @@ describe('EconomicsResource', () => { const result = await economics.getInflationRate(); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'inflationRate', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -396,13 +380,12 @@ describe('EconomicsResource', () => { const result = await economics.getInflationRate('2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'inflationRate', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -411,14 +394,13 @@ describe('EconomicsResource', () => { const result = await economics.getInflationRate('2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'inflationRate', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); }); @@ -429,12 +411,11 @@ describe('EconomicsResource', () => { const result = await economics.getUnemploymentRate(); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'unemploymentRate', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -443,13 +424,12 @@ describe('EconomicsResource', () => { const result = await economics.getUnemploymentRate('2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'unemploymentRate', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -458,14 +438,13 @@ describe('EconomicsResource', () => { const result = await economics.getUnemploymentRate('2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'unemploymentRate', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); }); @@ -476,12 +455,11 @@ describe('EconomicsResource', () => { const result = await economics.getFederalFundsRate(); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'federalFunds', - }, - } -); + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -490,13 +468,12 @@ describe('EconomicsResource', () => { const result = await economics.getFederalFundsRate('2023-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'federalFunds', - from: '2023-01-01', - }, - } -); + from: '2023-01-01', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); @@ -505,14 +482,13 @@ describe('EconomicsResource', () => { const result = await economics.getFederalFundsRate('2023-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/economic', { + expect(mockClient.get).toHaveBeenCalledWith('economic-indicators', { searchParams: { name: 'federalFunds', - from: '2023-01-01', - to: '2024-12-31', - }, - } -); + from: '2023-01-01', + to: '2024-12-31', + }, + }); expect(result).toEqual(mockEconomicIndicators); }); }); @@ -523,7 +499,7 @@ describe('EconomicsResource', () => { const result = await economics.getMarketRiskPremium(); - expect(mockClient.get).toHaveBeenCalledWith('v4/market_risk_premium'); + expect(mockClient.get).toHaveBeenCalledWith('market-risk-premium'); expect(result).toEqual(mockMarketRiskPremiums); expect(result).toHaveLength(2); expect(result[0]).toHaveProperty('country'); @@ -605,13 +581,12 @@ describe('EconomicsResource', () => { // Invalid dates should be passed to API for validation await economics.getTreasuryRates('invalid-date', 'also-invalid'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: 'invalid-date', - to: 'also-invalid', - }, - } -); + to: 'also-invalid', + }, + }); }); }); @@ -735,13 +710,12 @@ describe('EconomicsResource', () => { await economics.getTreasuryRates('1990-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '1990-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); it('should handle same from and to dates', async () => { @@ -749,13 +723,12 @@ describe('EconomicsResource', () => { await economics.getTreasuryRates('2024-01-15', '2024-01-15'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '2024-01-15', - to: '2024-01-15', - }, - } -); + to: '2024-01-15', + }, + }); }); it('should handle reversed date ranges', async () => { @@ -764,13 +737,12 @@ describe('EconomicsResource', () => { // API should handle validation of reversed dates await economics.getTreasuryRates('2024-12-31', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/treasury', { + expect(mockClient.get).toHaveBeenCalledWith('treasury-rates', { searchParams: { from: '2024-12-31', - to: '2024-01-01', - }, - } -); + to: '2024-01-01', + }, + }); }); }); }); diff --git a/tests/esg.test.ts b/tests/esg.test.ts index 6ef6a01..04b7896 100644 --- a/tests/esg.test.ts +++ b/tests/esg.test.ts @@ -45,9 +45,8 @@ describe('ESGResource', () => { const result = await esgResource.getESGData('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: 'AAPL' }, } - + 'esg-disclosures', + { searchParams: { symbol: 'AAPL' } } ); expect(result).toEqual(mockResponse); }); @@ -75,9 +74,8 @@ describe('ESGResource', () => { await esgResource.getESGData('tsla'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: 'TSLA' }, } - + 'esg-disclosures', + { searchParams: { symbol: 'TSLA' } } ); }); @@ -87,9 +85,8 @@ describe('ESGResource', () => { await esgResource.getESGData('MsFt'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: 'MSFT' }, } - + 'esg-disclosures', + { searchParams: { symbol: 'MSFT' } } ); }); @@ -190,9 +187,8 @@ describe('ESGResource', () => { const result = await esgResource.getESGRatings('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data-ratings', - { searchParams: { symbol: 'AAPL' }, } - + 'esg-ratings', + { searchParams: { symbol: 'AAPL' } } ); expect(result).toEqual(mockResponse); }); @@ -218,9 +214,8 @@ describe('ESGResource', () => { await esgResource.getESGRatings('msft'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data-ratings', - { searchParams: { symbol: 'MSFT' }, } - + 'esg-ratings', + { searchParams: { symbol: 'MSFT' } } ); }); @@ -230,9 +225,8 @@ describe('ESGResource', () => { await esgResource.getESGRatings('GoOgL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data-ratings', - { searchParams: { symbol: 'GOOGL' }, } - + 'esg-ratings', + { searchParams: { symbol: 'GOOGL' } } ); }); @@ -335,9 +329,8 @@ describe('ESGResource', () => { const result = await esgResource.getESGBenchmark(2024); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2024 }, } - + 'esg-benchmark', + { searchParams: { year: 2024 } } ); expect(result).toEqual(mockResponse); }); @@ -369,8 +362,8 @@ describe('ESGResource', () => { const result2023 = await esgResource.getESGBenchmark(2023); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2023 }, } + 'esg-benchmark', + { searchParams: { year: 2023 } } ); expect(result2023).toEqual(mockResponse2023); @@ -379,8 +372,8 @@ describe('ESGResource', () => { const result2022 = await esgResource.getESGBenchmark(2022); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2022 }, } + 'esg-benchmark', + { searchParams: { year: 2022 } } ); expect(result2022).toEqual(mockResponse2022); @@ -392,8 +385,8 @@ describe('ESGResource', () => { await esgResource.getESGBenchmark(2021); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2021 }, } + 'esg-benchmark', + { searchParams: { year: 2021 } } ); expect(mockClient.get).toHaveBeenCalledTimes(1); @@ -497,9 +490,8 @@ describe('ESGResource', () => { const result = await esgResource.getESGBenchmark(2030); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2030 }, } - + 'esg-benchmark', + { searchParams: { year: 2030 } } ); expect(result).toEqual(mockResponse); }); @@ -521,9 +513,8 @@ describe('ESGResource', () => { const result = await esgResource.getESGBenchmark(2015); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-sector-benchmark', - { searchParams: { year: 2015 }, } - + 'esg-benchmark', + { searchParams: { year: 2015 } } ); expect(result).toEqual(mockResponse); }); @@ -563,9 +554,8 @@ describe('ESGResource', () => { await esgResource.getESGData('BRK.B'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: 'BRK.B' }, } - + 'esg-disclosures', + { searchParams: { symbol: 'BRK.B' } } ); }); @@ -575,9 +565,8 @@ describe('ESGResource', () => { await esgResource.getESGRatings('BRK-B'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data-ratings', - { searchParams: { symbol: 'BRK-B' }, } - + 'esg-ratings', + { searchParams: { symbol: 'BRK-B' } } ); }); @@ -587,9 +576,8 @@ describe('ESGResource', () => { await esgResource.getESGData(' aapl '); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: ' AAPL ' }, } - + 'esg-disclosures', + { searchParams: { symbol: ' AAPL ' } } ); }); @@ -599,9 +587,8 @@ describe('ESGResource', () => { await esgResource.getESGData(''); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/esg-environmental-social-governance-data', - { searchParams: { symbol: '' }, } - + 'esg-disclosures', + { searchParams: { symbol: '' } } ); }); }); @@ -636,17 +623,17 @@ describe('ESGResource', () => { await esgResource.getESGData('AAPL'); expect(vi.mocked(mockClient.get).mock.calls[0][0]).toBe( - 'v4/esg-environmental-social-governance-data' + 'esg-disclosures' ); await esgResource.getESGRatings('AAPL'); expect(vi.mocked(mockClient.get).mock.calls[1][0]).toBe( - 'v4/esg-environmental-social-governance-data-ratings' + 'esg-ratings' ); await esgResource.getESGBenchmark(2024); expect(vi.mocked(mockClient.get).mock.calls[2][0]).toBe( - 'v4/esg-environmental-social-governance-sector-benchmark' + 'esg-benchmark' ); }); }); diff --git a/tests/etf.test.ts b/tests/etf.test.ts index 75b3a28..e67e37a 100644 --- a/tests/etf.test.ts +++ b/tests/etf.test.ts @@ -51,7 +51,7 @@ describe('ETFResource', () => { const result = await etfResource.getHoldings('SPY'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-holder/SPY'); + expect(mockClient.get).toHaveBeenCalledWith('etf/holdings', { searchParams: { symbol: 'SPY' } }); expect(result).toEqual(mockHoldings); }); @@ -60,7 +60,7 @@ describe('ETFResource', () => { await etfResource.getHoldings('spy'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-holder/SPY'); + expect(mockClient.get).toHaveBeenCalledWith('etf/holdings', { searchParams: { symbol: 'SPY' } }); }); it('should handle lowercase ETF symbols', async () => { @@ -68,7 +68,7 @@ describe('ETFResource', () => { await etfResource.getHoldings('voo'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-holder/VOO'); + expect(mockClient.get).toHaveBeenCalledWith('etf/holdings', { searchParams: { symbol: 'VOO' } }); }); it('should handle mixed case symbols', async () => { @@ -76,7 +76,7 @@ describe('ETFResource', () => { await etfResource.getHoldings('QqQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-holder/QQQ'); + expect(mockClient.get).toHaveBeenCalledWith('etf/holdings', { searchParams: { symbol: 'QQQ' } }); }); it('should handle empty response', async () => { @@ -138,7 +138,7 @@ describe('ETFResource', () => { const result = await etfResource.getInfo('SPY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-info', { + expect(mockClient.get).toHaveBeenCalledWith('etf/info', { searchParams: { symbol: 'SPY', }, @@ -152,7 +152,7 @@ describe('ETFResource', () => { await etfResource.getInfo('spy'); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-info', { + expect(mockClient.get).toHaveBeenCalledWith('etf/info', { searchParams: { symbol: 'SPY', }, @@ -165,7 +165,7 @@ describe('ETFResource', () => { await etfResource.getInfo('VOO'); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-info', { + expect(mockClient.get).toHaveBeenCalledWith('etf/info', { searchParams: { symbol: 'VOO', }, @@ -210,7 +210,7 @@ describe('ETFResource', () => { const result = await etfResource.getSectorWeightings('SPY'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-sector-weightings/SPY'); + expect(mockClient.get).toHaveBeenCalledWith('etf/sector-weightings', { searchParams: { symbol: 'SPY' } }); expect(result).toEqual(mockSectorWeightings); }); @@ -219,7 +219,7 @@ describe('ETFResource', () => { await etfResource.getSectorWeightings('vti'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-sector-weightings/VTI'); + expect(mockClient.get).toHaveBeenCalledWith('etf/sector-weightings', { searchParams: { symbol: 'VTI' } }); }); it('should handle sector-specific ETFs', async () => { @@ -275,7 +275,7 @@ describe('ETFResource', () => { const result = await etfResource.getCountryWeightings('VT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-country-weightings/VT'); + expect(mockClient.get).toHaveBeenCalledWith('etf/country-weightings', { searchParams: { symbol: 'VT' } }); expect(result).toEqual(mockCountryWeightings); }); @@ -284,7 +284,7 @@ describe('ETFResource', () => { await etfResource.getCountryWeightings('vt'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-country-weightings/VT'); + expect(mockClient.get).toHaveBeenCalledWith('etf/country-weightings', { searchParams: { symbol: 'VT' } }); }); it('should handle international ETFs', async () => { @@ -360,7 +360,7 @@ describe('ETFResource', () => { const result = await etfResource.getStockExposure('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-stock-exposure/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('etf/asset-exposure', { searchParams: { symbol: 'AAPL' } }); expect(result).toEqual(mockStockExposure); }); @@ -369,7 +369,7 @@ describe('ETFResource', () => { await etfResource.getStockExposure('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-stock-exposure/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('etf/asset-exposure', { searchParams: { symbol: 'AAPL' } }); }); it('should handle stocks with limited ETF exposure', async () => { @@ -402,7 +402,7 @@ describe('ETFResource', () => { await etfResource.getStockExposure('TsLa'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-stock-exposure/TSLA'); + expect(mockClient.get).toHaveBeenCalledWith('etf/asset-exposure', { searchParams: { symbol: 'TSLA' } }); }); it('should throw error on API failure', async () => { @@ -447,7 +447,7 @@ describe('ETFResource', () => { const result = await etfResource.getMutualFundHolders('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/mutual-fund-holder/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('funds/disclosure-holders-latest', { searchParams: { symbol: 'AAPL' } }); expect(result).toEqual(mockMutualFundHolders); }); @@ -456,7 +456,7 @@ describe('ETFResource', () => { await etfResource.getMutualFundHolders('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v3/mutual-fund-holder/MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('funds/disclosure-holders-latest', { searchParams: { symbol: 'MSFT' } }); }); it('should handle stocks with no mutual fund holders', async () => { @@ -513,7 +513,7 @@ describe('ETFResource', () => { const result = await etfResource.getETFList(); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf/list'); + expect(mockClient.get).toHaveBeenCalledWith('etf-list'); expect(result).toEqual(mockETFList); }); @@ -544,7 +544,7 @@ describe('ETFResource', () => { const result = await etfResource.getAvailableMutualFunds(); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/available-mutual-funds'); + expect(mockClient.get).toHaveBeenCalledWith('mutual-fund-list'); expect(result).toEqual(mockMutualFunds); }); @@ -578,7 +578,7 @@ describe('ETFResource', () => { const result = await etfResource.getLatestDisclosures(); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-holdings/portfolio-date'); + expect(mockClient.get).toHaveBeenCalledWith('funds/disclosure-dates'); expect(result).toEqual(mockDisclosures); }); @@ -629,10 +629,10 @@ describe('ETFResource', () => { await etfResource.getHoldings('Spy'); await etfResource.getHoldings('SpY'); - expect(mockClient.get).toHaveBeenNthCalledWith(1, 'v3/etf-holder/SPY'); - expect(mockClient.get).toHaveBeenNthCalledWith(2, 'v3/etf-holder/SPY'); - expect(mockClient.get).toHaveBeenNthCalledWith(3, 'v3/etf-holder/SPY'); - expect(mockClient.get).toHaveBeenNthCalledWith(4, 'v3/etf-holder/SPY'); + expect(mockClient.get).toHaveBeenNthCalledWith(1, 'etf/holdings', { searchParams: { symbol: 'SPY' } }); + expect(mockClient.get).toHaveBeenNthCalledWith(2, 'etf/holdings', { searchParams: { symbol: 'SPY' } }); + expect(mockClient.get).toHaveBeenNthCalledWith(3, 'etf/holdings', { searchParams: { symbol: 'SPY' } }); + expect(mockClient.get).toHaveBeenNthCalledWith(4, 'etf/holdings', { searchParams: { symbol: 'SPY' } }); }); it('should normalize symbols with numbers', async () => { @@ -641,9 +641,8 @@ describe('ETFResource', () => { await etfResource.getStockExposure('tsla'); await etfResource.getInfo('voo'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-stock-exposure/TSLA'); - expect(mockClient.get).toHaveBeenCalledWith('v4/etf-info', { searchParams: { symbol: 'VOO' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('etf/asset-exposure', { searchParams: { symbol: 'TSLA' } }); + expect(mockClient.get).toHaveBeenCalledWith('etf/info', { searchParams: { symbol: 'VOO' } }); }); it('should handle symbols with special characters', async () => { @@ -653,7 +652,7 @@ describe('ETFResource', () => { // the normalization should still work await etfResource.getHoldings('brk.b'); - expect(mockClient.get).toHaveBeenCalledWith('v3/etf-holder/BRK.B'); + expect(mockClient.get).toHaveBeenCalledWith('etf/holdings', { searchParams: { symbol: 'BRK.B' } }); }); }); diff --git a/tests/events.test.ts b/tests/events.test.ts index 4ef10e2..802655e 100644 --- a/tests/events.test.ts +++ b/tests/events.test.ts @@ -44,10 +44,9 @@ describe('EventsResource', () => { const result = await eventsResource.getEarnings('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockEarnings); }); @@ -57,10 +56,9 @@ describe('EventsResource', () => { await eventsResource.getEarnings('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should include limit parameter when provided', async () => { @@ -69,11 +67,9 @@ describe('EventsResource', () => { await eventsResource.getEarnings('AAPL', 10); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/AAPL', - { searchParams: { limit: 10 }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'AAPL', limit: 10 }, + }); }); it('should handle mixed case symbols', async () => { @@ -82,10 +78,9 @@ describe('EventsResource', () => { await eventsResource.getEarnings('TsLa'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/TSLA', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'TSLA' }, + }); }); it('should handle API errors', async () => { @@ -116,7 +111,9 @@ describe('EventsResource', () => { const result = await eventsResource.getEarningsCalendar(); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { + searchParams: {}, + }); expect(result).toEqual(mockCalendar); }); @@ -126,12 +123,11 @@ describe('EventsResource', () => { await eventsResource.getEarningsCalendar('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch earnings calendar with to date only', async () => { @@ -140,12 +136,11 @@ describe('EventsResource', () => { await eventsResource.getEarningsCalendar(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch earnings calendar with both from and to dates', async () => { @@ -154,13 +149,12 @@ describe('EventsResource', () => { await eventsResource.getEarningsCalendar('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); it('should handle null/undefined earnings data', async () => { @@ -206,9 +200,9 @@ describe('EventsResource', () => { const result = await eventsResource.getDividends('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/stock_dividend/AAPL' - ); + expect(mockClient.get).toHaveBeenCalledWith('dividends', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockDividends); }); @@ -218,9 +212,9 @@ describe('EventsResource', () => { await eventsResource.getDividends('msft'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/stock_dividend/MSFT' - ); + expect(mockClient.get).toHaveBeenCalledWith('dividends', { + searchParams: { symbol: 'MSFT' }, + }); }); it('should handle empty dividend history', async () => { @@ -251,7 +245,9 @@ describe('EventsResource', () => { const result = await eventsResource.getDividendCalendar(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_dividend_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('dividends-calendar', { + searchParams: {}, + }); expect(result).toEqual(mockCalendar); }); @@ -261,12 +257,11 @@ describe('EventsResource', () => { await eventsResource.getDividendCalendar('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_dividend_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('dividends-calendar', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch dividend calendar with to date', async () => { @@ -275,12 +270,11 @@ describe('EventsResource', () => { await eventsResource.getDividendCalendar(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_dividend_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('dividends-calendar', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch dividend calendar with date range', async () => { @@ -289,13 +283,12 @@ describe('EventsResource', () => { await eventsResource.getDividendCalendar('2024-01-01', '2024-03-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_dividend_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('dividends-calendar', { searchParams: { from: '2024-01-01', - to: '2024-03-31', - }, - } -); + to: '2024-03-31', + }, + }); }); }); @@ -315,9 +308,9 @@ describe('EventsResource', () => { const result = await eventsResource.getSplits('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/stock_split/AAPL' - ); + expect(mockClient.get).toHaveBeenCalledWith('splits', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockSplits); }); @@ -327,9 +320,9 @@ describe('EventsResource', () => { await eventsResource.getSplits('googl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/stock_split/GOOGL' - ); + expect(mockClient.get).toHaveBeenCalledWith('splits', { + searchParams: { symbol: 'GOOGL' }, + }); }); it('should handle companies with no split history', async () => { @@ -357,7 +350,9 @@ describe('EventsResource', () => { const result = await eventsResource.getSplitsCalendar(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_split_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('splits-calendar', { + searchParams: {}, + }); expect(result).toEqual(mockCalendar); }); @@ -367,12 +362,11 @@ describe('EventsResource', () => { await eventsResource.getSplitsCalendar('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_split_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('splits-calendar', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch stock splits calendar with to date', async () => { @@ -381,12 +375,11 @@ describe('EventsResource', () => { await eventsResource.getSplitsCalendar(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_split_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('splits-calendar', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch stock splits calendar with date range', async () => { @@ -395,13 +388,12 @@ describe('EventsResource', () => { await eventsResource.getSplitsCalendar('2024-01-01', '2024-06-30'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_split_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('splits-calendar', { searchParams: { from: '2024-01-01', - to: '2024-06-30', - }, - } -); + to: '2024-06-30', + }, + }); }); }); @@ -424,7 +416,9 @@ describe('EventsResource', () => { const result = await eventsResource.getIPOCalendar(); - expect(mockClient.get).toHaveBeenCalledWith('v3/ipo_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('ipos-calendar', { + searchParams: {}, + }); expect(result).toEqual(mockIPOs); }); @@ -434,12 +428,11 @@ describe('EventsResource', () => { await eventsResource.getIPOCalendar('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ipo_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-calendar', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch IPO calendar with to date', async () => { @@ -448,12 +441,11 @@ describe('EventsResource', () => { await eventsResource.getIPOCalendar(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ipo_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-calendar', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch IPO calendar with date range', async () => { @@ -462,13 +454,12 @@ describe('EventsResource', () => { await eventsResource.getIPOCalendar('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ipo_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-calendar', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); it('should handle empty IPO calendar', async () => { @@ -499,7 +490,9 @@ describe('EventsResource', () => { const result = await eventsResource.getIPOProspectus(); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-prospectus', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('ipos-prospectus', { + searchParams: {}, + }); expect(result).toEqual(mockProspectus); }); @@ -509,12 +502,11 @@ describe('EventsResource', () => { await eventsResource.getIPOProspectus('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-prospectus', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-prospectus', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch IPO prospectus with to date', async () => { @@ -523,12 +515,11 @@ describe('EventsResource', () => { await eventsResource.getIPOProspectus(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-prospectus', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-prospectus', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch IPO prospectus with date range', async () => { @@ -537,13 +528,12 @@ describe('EventsResource', () => { await eventsResource.getIPOProspectus('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-prospectus', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-prospectus', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); }); @@ -566,7 +556,9 @@ describe('EventsResource', () => { const result = await eventsResource.getIPOConfirmed(); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-confirmed', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('ipos-confirmed', { + searchParams: {}, + }); expect(result).toEqual(mockConfirmed); }); @@ -576,12 +568,11 @@ describe('EventsResource', () => { await eventsResource.getIPOConfirmed('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-confirmed', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch confirmed IPOs with to date', async () => { @@ -590,12 +581,11 @@ describe('EventsResource', () => { await eventsResource.getIPOConfirmed(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-confirmed', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch confirmed IPOs with date range', async () => { @@ -604,13 +594,12 @@ describe('EventsResource', () => { await eventsResource.getIPOConfirmed('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/ipo-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('ipos-confirmed', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); }); @@ -634,7 +623,9 @@ describe('EventsResource', () => { const result = await eventsResource.getEconomicCalendar(); - expect(mockClient.get).toHaveBeenCalledWith('v3/economic_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('economic-calendar', { + searchParams: {}, + }); expect(result).toEqual(mockEconomic); }); @@ -644,12 +635,11 @@ describe('EventsResource', () => { await eventsResource.getEconomicCalendar('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/economic_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('economic-calendar', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch economic calendar with to date', async () => { @@ -658,12 +648,11 @@ describe('EventsResource', () => { await eventsResource.getEconomicCalendar(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/economic_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('economic-calendar', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch economic calendar with date range', async () => { @@ -672,13 +661,12 @@ describe('EventsResource', () => { await eventsResource.getEconomicCalendar('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/economic_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('economic-calendar', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); it('should handle multiple economic events', async () => { @@ -737,7 +725,9 @@ describe('EventsResource', () => { const result = await eventsResource.getConfirmedEarnings(); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning-calendar-confirmed', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar-confirmed', { + searchParams: {}, + }); expect(result).toEqual(mockConfirmed); }); @@ -747,12 +737,11 @@ describe('EventsResource', () => { await eventsResource.getConfirmedEarnings('2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar-confirmed', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should fetch confirmed earnings with to date', async () => { @@ -761,12 +750,11 @@ describe('EventsResource', () => { await eventsResource.getConfirmedEarnings(undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar-confirmed', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); it('should fetch confirmed earnings with date range', async () => { @@ -775,13 +763,12 @@ describe('EventsResource', () => { await eventsResource.getConfirmedEarnings('2024-01-01', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning-calendar-confirmed', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar-confirmed', { searchParams: { from: '2024-01-01', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); }); @@ -843,9 +830,9 @@ describe('EventsResource', () => { await eventsResource.getDividends('BRK.B'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/stock_dividend/BRK.B' - ); + expect(mockClient.get).toHaveBeenCalledWith('dividends', { + searchParams: { symbol: 'BRK.B' }, + }); }); it('should handle empty string dates gracefully', async () => { @@ -855,7 +842,9 @@ describe('EventsResource', () => { await eventsResource.getEarningsCalendar('', ''); // Empty strings are falsy, so they won't be included in params - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { + searchParams: {}, + }); }); it('should handle limit of 0 in getEarnings', async () => { @@ -865,10 +854,9 @@ describe('EventsResource', () => { await eventsResource.getEarnings('AAPL', 0); // 0 is falsy, so it won't be included - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should include limit when it is a positive number', async () => { @@ -877,11 +865,9 @@ describe('EventsResource', () => { await eventsResource.getEarnings('AAPL', 100); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical/earning_calendar/AAPL', - { searchParams: { limit: 100 }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('earnings', { + searchParams: { symbol: 'AAPL', limit: 100 }, + }); }); it('should handle very long date ranges in calendar methods', async () => { @@ -890,13 +876,12 @@ describe('EventsResource', () => { await eventsResource.getEarningsCalendar('2000-01-01', '2030-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_calendar', { + expect(mockClient.get).toHaveBeenCalledWith('earnings-calendar', { searchParams: { from: '2000-01-01', - to: '2030-12-31', - }, - } -); + to: '2030-12-31', + }, + }); }); }); diff --git a/tests/financials.test.ts b/tests/financials.test.ts index 38b51dc..11db4a8 100644 --- a/tests/financials.test.ts +++ b/tests/financials.test.ts @@ -1,5 +1,6 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { FinancialsResource } from '../src/resources/financials.js'; +import { Period } from '../src/types/index.js'; import type { FMPClient } from '../src/client.js'; import type { IncomeStatement, @@ -67,7 +68,8 @@ describe('FinancialsResource', () => { weightedAverageShsOut: 15744231000, weightedAverageShsOutDil: 15812547000, link: 'https://www.sec.gov/cgi-bin/viewer?action=view&cik=320193&accession_number=0000320193-24-000081&xbrl_type=v', - finalLink: 'https://www.sec.gov/cgi-bin/viewer?action=view&cik=320193&accession_number=0000320193-24-000081&xbrl_type=v', + finalLink: + 'https://www.sec.gov/cgi-bin/viewer?action=view&cik=320193&accession_number=0000320193-24-000081&xbrl_type=v', }, ]; @@ -75,8 +77,9 @@ describe('FinancialsResource', () => { const result = await financials.getIncomeStatement('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); expect(result).toEqual(mockData); }); @@ -84,25 +87,22 @@ describe('FinancialsResource', () => { const mockData: IncomeStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getIncomeStatement('AAPL', 'quarter'); + await financials.getIncomeStatement('AAPL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'quarter' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'quarter' }, + }); }); it('should fetch income statement with limit', async () => { const mockData: IncomeStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getIncomeStatement('AAPL', 'annual', 5); + await financials.getIncomeStatement('AAPL', Period.Annual, 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { - searchParams: { - period: 'annual', - limit: 5, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'annual', limit: 5 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -111,8 +111,9 @@ describe('FinancialsResource', () => { await financials.getIncomeStatement('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); it('should handle API errors', async () => { @@ -130,41 +131,31 @@ describe('FinancialsResource', () => { await financials.getBalanceSheet('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); it('should fetch balance sheet with quarterly period', async () => { const mockData: BalanceSheet[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getBalanceSheet('MSFT', 'quarter'); + await financials.getBalanceSheet('MSFT', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'quarter', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement', { + searchParams: { symbol: 'MSFT', period: 'quarter' }, + }); }); it('should fetch balance sheet with limit', async () => { const mockData: BalanceSheet[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getBalanceSheet('MSFT', 'annual', 10); + await financials.getBalanceSheet('MSFT', Period.Annual, 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'annual', - limit: 10, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement', { + searchParams: { symbol: 'MSFT', period: 'annual', limit: 10 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -173,12 +164,9 @@ describe('FinancialsResource', () => { await financials.getBalanceSheet('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); }); @@ -189,41 +177,31 @@ describe('FinancialsResource', () => { await financials.getCashFlowStatement('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement', { + searchParams: { symbol: 'GOOGL', period: 'annual' }, + }); }); it('should fetch cash flow statement with quarterly period', async () => { const mockData: CashFlowStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getCashFlowStatement('GOOGL', 'quarter'); + await financials.getCashFlowStatement('GOOGL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'quarter', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement', { + searchParams: { symbol: 'GOOGL', period: 'quarter' }, + }); }); it('should fetch cash flow statement with limit', async () => { const mockData: CashFlowStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getCashFlowStatement('GOOGL', 'annual', 3); + await financials.getCashFlowStatement('GOOGL', Period.Annual, 3); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'annual', - limit: 3, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement', { + searchParams: { symbol: 'GOOGL', period: 'annual', limit: 3 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -232,12 +210,9 @@ describe('FinancialsResource', () => { await financials.getCashFlowStatement('googl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement', { + searchParams: { symbol: 'GOOGL', period: 'annual' }, + }); }); }); @@ -249,8 +224,9 @@ describe('FinancialsResource', () => { await financials.getIncomeStatementTTM('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'ttm' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-ttm', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -259,8 +235,9 @@ describe('FinancialsResource', () => { await financials.getIncomeStatementTTM('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'ttm' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-ttm', { + searchParams: { symbol: 'AAPL' }, + }); }); }); @@ -271,12 +248,9 @@ describe('FinancialsResource', () => { await financials.getBalanceSheetTTM('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'ttm', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-ttm', { + searchParams: { symbol: 'MSFT' }, + }); }); }); @@ -287,12 +261,9 @@ describe('FinancialsResource', () => { await financials.getCashFlowStatementTTM('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'ttm', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-ttm', { + searchParams: { symbol: 'GOOGL' }, + }); }); }); }); @@ -304,28 +275,31 @@ describe('FinancialsResource', () => { await financials.getRatios('TSLA'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios/TSLA', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('ratios', { + searchParams: { symbol: 'TSLA', period: 'annual' }, + }); }); it('should fetch financial ratios with quarterly period', async () => { const mockData: FinancialRatios[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getRatios('TSLA', 'quarter'); + await financials.getRatios('TSLA', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios/TSLA', { searchParams: { period: 'quarter' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('ratios', { + searchParams: { symbol: 'TSLA', period: 'quarter' }, + }); }); it('should fetch financial ratios with limit', async () => { const mockData: FinancialRatios[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getRatios('TSLA', 'annual', 7); + await financials.getRatios('TSLA', Period.Annual, 7); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios/TSLA', { searchParams: { period: 'annual', limit: 7 }, } -); + expect(mockClient.get).toHaveBeenCalledWith('ratios', { + searchParams: { symbol: 'TSLA', period: 'annual', limit: 7 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -334,8 +308,9 @@ describe('FinancialsResource', () => { await financials.getRatios('tsla'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios/TSLA', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('ratios', { + searchParams: { symbol: 'TSLA', period: 'annual' }, + }); }); }); @@ -346,7 +321,9 @@ describe('FinancialsResource', () => { await financials.getRatiosTTM('NVDA'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios-ttm/NVDA'); + expect(mockClient.get).toHaveBeenCalledWith('ratios-ttm', { + searchParams: { symbol: 'NVDA' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -355,7 +332,9 @@ describe('FinancialsResource', () => { await financials.getRatiosTTM('nvda'); - expect(mockClient.get).toHaveBeenCalledWith('v3/ratios-ttm/NVDA'); + expect(mockClient.get).toHaveBeenCalledWith('ratios-ttm', { + searchParams: { symbol: 'NVDA' }, + }); }); }); @@ -366,33 +345,31 @@ describe('FinancialsResource', () => { await financials.getKeyMetrics('AMZN'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics/AMZN', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics', { + searchParams: { symbol: 'AMZN', period: 'annual' }, + }); }); it('should fetch key metrics with quarterly period', async () => { const mockData: KeyMetrics[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getKeyMetrics('AMZN', 'quarter'); + await financials.getKeyMetrics('AMZN', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics/AMZN', { searchParams: { period: 'quarter' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics', { + searchParams: { symbol: 'AMZN', period: 'quarter' }, + }); }); it('should fetch key metrics with limit', async () => { const mockData: KeyMetrics[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getKeyMetrics('AMZN', 'annual', 4); + await financials.getKeyMetrics('AMZN', Period.Annual, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics/AMZN', { - searchParams: { - period: 'annual', - limit: 4, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics', { + searchParams: { symbol: 'AMZN', period: 'annual', limit: 4 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -401,8 +378,9 @@ describe('FinancialsResource', () => { await financials.getKeyMetrics('amzn'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics/AMZN', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics', { + searchParams: { symbol: 'AMZN', period: 'annual' }, + }); }); }); @@ -413,7 +391,9 @@ describe('FinancialsResource', () => { await financials.getKeyMetricsTTM('META'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics-ttm/META'); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics-ttm', { + searchParams: { symbol: 'META' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -422,7 +402,9 @@ describe('FinancialsResource', () => { await financials.getKeyMetricsTTM('meta'); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics-ttm/META'); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics-ttm', { + searchParams: { symbol: 'META' }, + }); }); }); @@ -433,37 +415,31 @@ describe('FinancialsResource', () => { await financials.getEnterpriseValues('NFLX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/enterprise-values/NFLX', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('enterprise-values', { + searchParams: { symbol: 'NFLX', period: 'annual' }, + }); }); it('should fetch enterprise values with quarterly period', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getEnterpriseValues('NFLX', 'quarter'); + await financials.getEnterpriseValues('NFLX', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/enterprise-values/NFLX', { - searchParams: { - period: 'quarter', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('enterprise-values', { + searchParams: { symbol: 'NFLX', period: 'quarter' }, + }); }); it('should fetch enterprise values with limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getEnterpriseValues('NFLX', 'annual', 6); + await financials.getEnterpriseValues('NFLX', Period.Annual, 6); - expect(mockClient.get).toHaveBeenCalledWith('v3/enterprise-values/NFLX', { - searchParams: { - period: 'annual', - limit: 6, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('enterprise-values', { + searchParams: { symbol: 'NFLX', period: 'annual', limit: 6 }, + }); }); }); @@ -475,27 +451,20 @@ describe('FinancialsResource', () => { await financials.getIncomeStatementGrowth('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-growth/AAPL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-growth', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); it('should fetch income statement growth with quarterly period and limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getIncomeStatementGrowth('AAPL', 'quarter', 8); + await financials.getIncomeStatementGrowth('AAPL', Period.Quarter, 8); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-growth/AAPL', { - searchParams: { - period: 'quarter', - limit: 8, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-growth', { + searchParams: { symbol: 'AAPL', period: 'quarter', limit: 8 }, + }); }); }); @@ -506,27 +475,20 @@ describe('FinancialsResource', () => { await financials.getBalanceSheetGrowth('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-growth/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-growth', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); it('should fetch balance sheet growth with quarterly period and limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getBalanceSheetGrowth('MSFT', 'quarter', 12); + await financials.getBalanceSheetGrowth('MSFT', Period.Quarter, 12); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-growth/MSFT', { - searchParams: { - period: 'quarter', - limit: 12, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-growth', { + searchParams: { symbol: 'MSFT', period: 'quarter', limit: 12 }, + }); }); }); @@ -537,27 +499,20 @@ describe('FinancialsResource', () => { await financials.getCashFlowStatementGrowth('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-growth/GOOGL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-growth', { + searchParams: { symbol: 'GOOGL', period: 'annual' }, + }); }); it('should fetch cash flow statement growth with quarterly period and limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getCashFlowStatementGrowth('GOOGL', 'quarter', 5); + await financials.getCashFlowStatementGrowth('GOOGL', Period.Quarter, 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-growth/GOOGL', { - searchParams: { - period: 'quarter', - limit: 5, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-growth', { + searchParams: { symbol: 'GOOGL', period: 'quarter', limit: 5 }, + }); }); }); }); @@ -570,30 +525,20 @@ describe('FinancialsResource', () => { await financials.getRevenueByProduct('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-product-segmentation', { - searchParams: { - symbol: 'AAPL', - period: 'annual', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-product-segmentation', { + searchParams: { symbol: 'AAPL', period: 'annual', structure: 'flat' }, + }); }); it('should fetch revenue by product with quarterly period', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getRevenueByProduct('AAPL', 'quarter'); + await financials.getRevenueByProduct('AAPL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-product-segmentation', { - searchParams: { - symbol: 'AAPL', - period: 'quarter', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-product-segmentation', { + searchParams: { symbol: 'AAPL', period: 'quarter', structure: 'flat' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -602,14 +547,9 @@ describe('FinancialsResource', () => { await financials.getRevenueByProduct('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-product-segmentation', { - searchParams: { - symbol: 'AAPL', - period: 'annual', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-product-segmentation', { + searchParams: { symbol: 'AAPL', period: 'annual', structure: 'flat' }, + }); }); }); @@ -620,30 +560,20 @@ describe('FinancialsResource', () => { await financials.getRevenueByGeography('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-geographic-segmentation', { - searchParams: { - symbol: 'MSFT', - period: 'annual', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-geographic-segmentation', { + searchParams: { symbol: 'MSFT', period: 'annual', structure: 'flat' }, + }); }); it('should fetch revenue by geography with quarterly period', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getRevenueByGeography('MSFT', 'quarter'); + await financials.getRevenueByGeography('MSFT', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-geographic-segmentation', { - searchParams: { - symbol: 'MSFT', - period: 'quarter', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-geographic-segmentation', { + searchParams: { symbol: 'MSFT', period: 'quarter', structure: 'flat' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -652,14 +582,9 @@ describe('FinancialsResource', () => { await financials.getRevenueByGeography('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v4/revenue-geographic-segmentation', { - searchParams: { - symbol: 'MSFT', - period: 'annual', - structure: 'flat', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('revenue-geographic-segmentation', { + searchParams: { symbol: 'MSFT', period: 'annual', structure: 'flat' }, + }); }); }); }); @@ -684,8 +609,9 @@ describe('FinancialsResource', () => { const result = await financials.getFinancialScores('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/score', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-scores', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockData); }); @@ -695,8 +621,9 @@ describe('FinancialsResource', () => { await financials.getFinancialScores('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/score', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-scores', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle API errors', async () => { @@ -724,8 +651,9 @@ describe('FinancialsResource', () => { const result = await financials.getOwnerEarnings('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/owner_earnings', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('owner-earnings', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockData); }); @@ -735,13 +663,9 @@ describe('FinancialsResource', () => { await financials.getOwnerEarnings('AAPL', 10); - expect(mockClient.get).toHaveBeenCalledWith('v4/owner_earnings', { - searchParams: { - symbol: 'AAPL', - limit: 10, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('owner-earnings', { + searchParams: { symbol: 'AAPL', limit: 10 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -750,8 +674,9 @@ describe('FinancialsResource', () => { await financials.getOwnerEarnings('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/owner_earnings', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('owner-earnings', { + searchParams: { symbol: 'AAPL' }, + }); }); }); @@ -803,8 +728,9 @@ describe('FinancialsResource', () => { const result = await financials.getFinancialGrowth('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/financial-growth/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-growth', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); expect(result).toEqual(mockData); }); @@ -812,25 +738,22 @@ describe('FinancialsResource', () => { const mockData: FinancialGrowth[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getFinancialGrowth('AAPL', 'quarter'); + await financials.getFinancialGrowth('AAPL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/financial-growth/AAPL', { searchParams: { period: 'quarter' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-growth', { + searchParams: { symbol: 'AAPL', period: 'quarter' }, + }); }); it('should fetch financial growth with limit', async () => { const mockData: FinancialGrowth[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getFinancialGrowth('AAPL', 'annual', 5); + await financials.getFinancialGrowth('AAPL', Period.Annual, 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/financial-growth/AAPL', { - searchParams: { - period: 'annual', - limit: 5, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-growth', { + searchParams: { symbol: 'AAPL', period: 'annual', limit: 5 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -839,8 +762,9 @@ describe('FinancialsResource', () => { await financials.getFinancialGrowth('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/financial-growth/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-growth', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); }); @@ -851,23 +775,28 @@ describe('FinancialsResource', () => { symbol: 'AAPL', date: '2023-12-31', period: 'FY', - linkXlsx: 'https://financialmodelingprep.com/api/v4/financial-reports-xlsx?symbol=AAPL&year=2023&period=FY', - linkJson: 'https://financialmodelingprep.com/api/v4/financial-reports-json?symbol=AAPL&year=2023&period=FY', + linkXlsx: + 'https://financialmodelingprep.com/api/v4/financial-reports-xlsx?symbol=AAPL&year=2023&period=FY', + linkJson: + 'https://financialmodelingprep.com/api/v4/financial-reports-json?symbol=AAPL&year=2023&period=FY', }, { symbol: 'AAPL', date: '2023-09-30', period: 'Q4', - linkXlsx: 'https://financialmodelingprep.com/api/v4/financial-reports-xlsx?symbol=AAPL&year=2023&period=Q4', - linkJson: 'https://financialmodelingprep.com/api/v4/financial-reports-json?symbol=AAPL&year=2023&period=Q4', + linkXlsx: + 'https://financialmodelingprep.com/api/v4/financial-reports-xlsx?symbol=AAPL&year=2023&period=Q4', + linkJson: + 'https://financialmodelingprep.com/api/v4/financial-reports-json?symbol=AAPL&year=2023&period=Q4', }, ]; vi.mocked(mockClient.get).mockResolvedValue(mockData); const result = await financials.getReportDates('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-dates', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-dates', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockData); }); @@ -877,8 +806,9 @@ describe('FinancialsResource', () => { await financials.getReportDates('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-dates', { searchParams: { symbol: 'AAPL' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-dates', { + searchParams: { symbol: 'AAPL' }, + }); }); }); @@ -890,41 +820,31 @@ describe('FinancialsResource', () => { await financials.getAsReportedIncomeStatement('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-as-reported/AAPL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); it('should fetch as-reported income statement with quarterly period', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getAsReportedIncomeStatement('AAPL', 'quarter'); + await financials.getAsReportedIncomeStatement('AAPL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-as-reported/AAPL', { - searchParams: { - period: 'quarter', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-as-reported', { + searchParams: { symbol: 'AAPL', period: 'quarter' }, + }); }); it('should fetch as-reported income statement with limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getAsReportedIncomeStatement('AAPL', 'annual', 3); + await financials.getAsReportedIncomeStatement('AAPL', Period.Annual, 3); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-as-reported/AAPL', { - searchParams: { - period: 'annual', - limit: 3, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual', limit: 3 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -933,12 +853,9 @@ describe('FinancialsResource', () => { await financials.getAsReportedIncomeStatement('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement-as-reported/AAPL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); }); @@ -949,27 +866,20 @@ describe('FinancialsResource', () => { await financials.getAsReportedBalanceSheet('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-as-reported/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-as-reported', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); it('should fetch as-reported balance sheet with quarterly period and limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getAsReportedBalanceSheet('MSFT', 'quarter', 8); + await financials.getAsReportedBalanceSheet('MSFT', Period.Quarter, 8); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-as-reported/MSFT', { - searchParams: { - period: 'quarter', - limit: 8, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-as-reported', { + searchParams: { symbol: 'MSFT', period: 'quarter', limit: 8 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -978,12 +888,9 @@ describe('FinancialsResource', () => { await financials.getAsReportedBalanceSheet('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement-as-reported/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement-as-reported', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); }); @@ -994,27 +901,20 @@ describe('FinancialsResource', () => { await financials.getAsReportedCashFlow('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-as-reported/GOOGL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-as-reported', { + searchParams: { symbol: 'GOOGL', period: 'annual' }, + }); }); it('should fetch as-reported cash flow with quarterly period and limit', async () => { const mockData: Record[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getAsReportedCashFlow('GOOGL', 'quarter', 12); + await financials.getAsReportedCashFlow('GOOGL', Period.Quarter, 12); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-as-reported/GOOGL', { - searchParams: { - period: 'quarter', - limit: 12, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-as-reported', { + searchParams: { symbol: 'GOOGL', period: 'quarter', limit: 12 }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -1023,12 +923,9 @@ describe('FinancialsResource', () => { await financials.getAsReportedCashFlow('googl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement-as-reported/GOOGL', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement-as-reported', { + searchParams: { symbol: 'GOOGL', period: 'annual' }, + }); }); }); @@ -1043,11 +940,9 @@ describe('FinancialsResource', () => { const result = await financials.getAsReportedFull('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'annual' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); expect(result).toEqual(mockData); }); @@ -1055,13 +950,11 @@ describe('FinancialsResource', () => { const mockData: Record = {}; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getAsReportedFull('AAPL', 'quarter'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'quarter' }, } + await financials.getAsReportedFull('AAPL', Period.Quarter); - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'quarter' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -1070,11 +963,9 @@ describe('FinancialsResource', () => { await financials.getAsReportedFull('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'annual' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); }); @@ -1098,11 +989,9 @@ describe('FinancialsResource', () => { const result = await financials.getLatestFinancialStatement('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'annual' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); expect(result).toEqual(mockData); }); @@ -1110,13 +999,11 @@ describe('FinancialsResource', () => { const mockData: LatestFinancialStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getLatestFinancialStatement('AAPL', 'quarter'); + await financials.getLatestFinancialStatement('AAPL', Period.Quarter); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'quarter' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'quarter' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -1125,11 +1012,9 @@ describe('FinancialsResource', () => { await financials.getLatestFinancialStatement('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/financial-statement-full-as-reported/AAPL', - { searchParams: { period: 'annual' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('financial-statement-full-as-reported', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); }); }); @@ -1147,14 +1032,9 @@ describe('FinancialsResource', () => { const result = await financials.getFinancialReportJSON('AAPL', 2023, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'AAPL', - year: 2023, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'AAPL', year: 2023, period: 'FY' }, + }); expect(result).toEqual(mockData); }); @@ -1164,14 +1044,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('MSFT', 2023, 'Q1'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'MSFT', - year: 2023, - period: 'Q1', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'MSFT', year: 2023, period: 'Q1' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -1180,14 +1055,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('aapl', 2023, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'AAPL', - year: 2023, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'AAPL', year: 2023, period: 'FY' }, + }); }); it('should handle different quarterly periods', async () => { @@ -1196,14 +1066,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('GOOGL', 2022, 'Q4'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'GOOGL', - year: 2022, - period: 'Q4', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'GOOGL', year: 2022, period: 'Q4' }, + }); }); it('should handle API errors', async () => { @@ -1225,14 +1090,9 @@ describe('FinancialsResource', () => { const result = await financials.getFinancialReportXLSX('AAPL', 2023, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'AAPL', - year: 2023, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'AAPL', year: 2023, period: 'FY' }, + }); expect(result).toEqual(mockData); expect(result.url).toBeDefined(); }); @@ -1245,14 +1105,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportXLSX('MSFT', 2023, 'Q2'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'MSFT', - year: 2023, - period: 'Q2', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'MSFT', year: 2023, period: 'Q2' }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -1263,14 +1118,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportXLSX('aapl', 2023, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'AAPL', - year: 2023, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'AAPL', year: 2023, period: 'FY' }, + }); }); it('should handle different years', async () => { @@ -1281,14 +1131,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportXLSX('TSLA', 2021, 'Q3'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'TSLA', - year: 2021, - period: 'Q3', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'TSLA', year: 2021, period: 'Q3' }, + }); }); it('should handle API errors', async () => { @@ -1321,7 +1166,9 @@ describe('FinancialsResource', () => { const error = new Error('Rate limit exceeded'); vi.mocked(mockClient.get).mockRejectedValue(error); - await expect(financials.getCashFlowStatement('GOOGL')).rejects.toThrow('Rate limit exceeded'); + await expect(financials.getCashFlowStatement('GOOGL')).rejects.toThrow( + 'Rate limit exceeded' + ); }); it('should propagate errors from client on getKeyMetrics', async () => { @@ -1346,8 +1193,9 @@ describe('FinancialsResource', () => { await financials.getIncomeStatement('AaPl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); it('should handle symbols with special characters', async () => { @@ -1356,8 +1204,9 @@ describe('FinancialsResource', () => { await financials.getIncomeStatement('brk.b'); - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/BRK.B', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'BRK.B', period: 'annual' }, + }); }); it('should handle already uppercase symbols', async () => { @@ -1366,12 +1215,9 @@ describe('FinancialsResource', () => { await financials.getBalanceSheet('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/balance-sheet-statement/MSFT', { - searchParams: { - period: 'annual', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('balance-sheet-statement', { + searchParams: { symbol: 'MSFT', period: 'annual' }, + }); }); }); @@ -1380,41 +1226,34 @@ describe('FinancialsResource', () => { const mockData: IncomeStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getIncomeStatement('AAPL', 'annual', 0); + await financials.getIncomeStatement('AAPL', Period.Annual, 0); // When limit is 0 (falsy), it should not be included in params - expect(mockClient.get).toHaveBeenCalledWith('v3/income-statement/AAPL', { searchParams: { period: 'annual' }, } -); + expect(mockClient.get).toHaveBeenCalledWith('income-statement', { + searchParams: { symbol: 'AAPL', period: 'annual' }, + }); }); it('should handle quarter period with large limit', async () => { const mockData: CashFlowStatement[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getCashFlowStatement('GOOGL', 'quarter', 100); + await financials.getCashFlowStatement('GOOGL', Period.Quarter, 100); - expect(mockClient.get).toHaveBeenCalledWith('v3/cash-flow-statement/GOOGL', { - searchParams: { - period: 'quarter', - limit: 100, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('cash-flow-statement', { + searchParams: { symbol: 'GOOGL', period: 'quarter', limit: 100 }, + }); }); it('should handle annual period with limit of 1', async () => { const mockData: KeyMetrics[] = []; vi.mocked(mockClient.get).mockResolvedValue(mockData); - await financials.getKeyMetrics('TSLA', 'annual', 1); + await financials.getKeyMetrics('TSLA', Period.Annual, 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/key-metrics/TSLA', { - searchParams: { - period: 'annual', - limit: 1, - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('key-metrics', { + searchParams: { symbol: 'TSLA', period: 'annual', limit: 1 }, + }); }); }); @@ -1425,14 +1264,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('AAPL', 2023, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'AAPL', - year: 2023, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'AAPL', year: 2023, period: 'FY' }, + }); }); it('should handle Q1 period', async () => { @@ -1441,14 +1275,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportXLSX('MSFT', 2023, 'Q1'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'MSFT', - year: 2023, - period: 'Q1', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'MSFT', year: 2023, period: 'Q1' }, + }); }); it('should handle Q2 period', async () => { @@ -1457,14 +1286,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('GOOGL', 2022, 'Q2'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'GOOGL', - year: 2022, - period: 'Q2', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'GOOGL', year: 2022, period: 'Q2' }, + }); }); it('should handle Q3 period', async () => { @@ -1473,14 +1297,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportXLSX('TSLA', 2021, 'Q3'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-xlsx', { - searchParams: { - symbol: 'TSLA', - year: 2021, - period: 'Q3', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-xlsx', { + searchParams: { symbol: 'TSLA', year: 2021, period: 'Q3' }, + }); }); it('should handle Q4 period', async () => { @@ -1489,14 +1308,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('AMZN', 2020, 'Q4'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'AMZN', - year: 2020, - period: 'Q4', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'AMZN', year: 2020, period: 'Q4' }, + }); }); it('should handle historical years', async () => { @@ -1505,14 +1319,9 @@ describe('FinancialsResource', () => { await financials.getFinancialReportJSON('IBM', 2015, 'FY'); - expect(mockClient.get).toHaveBeenCalledWith('v4/financial-reports-json', { - searchParams: { - symbol: 'IBM', - year: 2015, - period: 'FY', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('financial-reports-json', { + searchParams: { symbol: 'IBM', year: 2015, period: 'FY' }, + }); }); }); }); diff --git a/tests/fmp.test.ts b/tests/fmp.test.ts index b672020..69197fe 100644 --- a/tests/fmp.test.ts +++ b/tests/fmp.test.ts @@ -55,9 +55,9 @@ describe('FMP SDK', () => { expect(typeof fmp.market.getForexCurrencyPairs).toBe('function'); expect(typeof fmp.market.getForexQuoteShort).toBe('function'); expect(typeof fmp.market.getForexLightChart).toBe('function'); - expect(typeof fmp.market.getForexIntraday1Min).toBe('function'); - expect(typeof fmp.market.getForexIntraday5Min).toBe('function'); - expect(typeof fmp.market.getForexIntraday1Hour).toBe('function'); + expect(typeof fmp.market.getForexIntraday).toBe('function'); + expect(typeof fmp.market.getHistoricalForex).toBe('function'); + expect(typeof fmp.market.getAllForexPrices).toBe('function'); }); it('should have financials resource', () => { diff --git a/tests/fundraisers.test.ts b/tests/fundraisers.test.ts index cfc15ad..3b22831 100644 --- a/tests/fundraisers.test.ts +++ b/tests/fundraisers.test.ts @@ -47,7 +47,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getLatestCrowdfunding(); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding-rss-feed', { searchParams: { page: 0 }, } + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-latest', { searchParams: { page: 0 }, } ); expect(result).toEqual(mockData); expect(result).toHaveLength(2); @@ -68,7 +68,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getLatestCrowdfunding(2); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding-rss-feed', { searchParams: { page: 2 }, } + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-latest', { searchParams: { page: 2 }, } ); expect(result).toEqual(mockData); }); @@ -125,7 +125,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchCrowdfunding('Tech Startup'); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0, name: 'Tech Startup', @@ -155,7 +155,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchCrowdfunding(undefined, '0001234567'); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0, cik: '0001234567', @@ -184,7 +184,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchCrowdfunding('Tech Startup', '0001234567'); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0, name: 'Tech Startup', @@ -202,7 +202,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchCrowdfunding(); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { searchParams: { page: 0 }, } + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0 }, } ); expect(result).toEqual([]); }); @@ -214,7 +214,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchCrowdfunding('Company', undefined, 3); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 3, name: 'Company', @@ -271,8 +271,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getCrowdfundingByCIK('0001234567'); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding/0001234567', { searchParams: { page: 0 }, } -); + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings', { searchParams: { cik: '0001234567', page: 0 } }); expect(result).toEqual(mockData); expect(result).toHaveLength(2); expect(result[0].cik).toBe('0001234567'); @@ -285,8 +284,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getCrowdfundingByCIK('0001234567', 1); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding/0001234567', { searchParams: { page: 1 }, } -); + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings', { searchParams: { cik: '0001234567', page: 1 } }); expect(result).toEqual([]); }); @@ -327,7 +325,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getLatestEquity(); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising-rss-feed', { searchParams: { page: 0 }, } + expect(mockClient.get).toHaveBeenCalledWith('fundraising-latest', { searchParams: { page: 0 }, } ); expect(result).toEqual(mockData); expect(result).toHaveLength(2); @@ -348,7 +346,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getLatestEquity(5); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising-rss-feed', { searchParams: { page: 5 }, } + expect(mockClient.get).toHaveBeenCalledWith('fundraising-latest', { searchParams: { page: 5 }, } ); expect(result).toEqual(mockData); }); @@ -405,7 +403,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchEquity('BigCorp'); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising', { + expect(mockClient.get).toHaveBeenCalledWith('fundraising-search', { searchParams: { page: 0, name: 'BigCorp', @@ -436,7 +434,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchEquity(undefined, '0009876543'); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising', { + expect(mockClient.get).toHaveBeenCalledWith('fundraising-search', { searchParams: { page: 0, cik: '0009876543', @@ -466,7 +464,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchEquity('BigCorp', '0001234567'); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising', { + expect(mockClient.get).toHaveBeenCalledWith('fundraising-search', { searchParams: { page: 0, name: 'BigCorp', @@ -484,7 +482,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchEquity(); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising', { searchParams: { page: 0 }, } + expect(mockClient.get).toHaveBeenCalledWith('fundraising-search', { searchParams: { page: 0 }, } ); expect(result).toEqual([]); }); @@ -496,7 +494,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.searchEquity('Test', undefined, 2); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising', { + expect(mockClient.get).toHaveBeenCalledWith('fundraising-search', { searchParams: { page: 2, name: 'Test', @@ -554,8 +552,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getEquityByCIK('0001234567'); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising/0001234567', { searchParams: { page: 0 }, } -); + expect(mockClient.get).toHaveBeenCalledWith('fundraising', { searchParams: { cik: '0001234567', page: 0 } }); expect(result).toEqual(mockData); expect(result).toHaveLength(2); expect(result[0].cik).toBe('0001234567'); @@ -569,8 +566,7 @@ describe('FundraisersResource', () => { const result = await fundraisers.getEquityByCIK('0001234567', 3); - expect(mockClient.get).toHaveBeenCalledWith('v4/fundraising/0001234567', { searchParams: { page: 3 }, } -); + expect(mockClient.get).toHaveBeenCalledWith('fundraising', { searchParams: { cik: '0001234567', page: 3 } }); expect(result).toEqual([]); }); @@ -668,14 +664,14 @@ describe('FundraisersResource', () => { expect(results0).toEqual(page0Data); expect(results1).toEqual(page1Data); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0, name: 'Company', }, } ); - expect(mockClient.get).toHaveBeenCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenCalledWith('crowdfunding-offerings-search', { searchParams: { page: 1, name: 'Company', @@ -708,7 +704,7 @@ describe('FundraisersResource', () => { vi.mocked(mockClient.get).mockResolvedValue([]); await fundraisers.searchCrowdfunding('Test Company', '0001234567', 2); - expect(mockClient.get).toHaveBeenLastCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenLastCalledWith('crowdfunding-offerings-search', { searchParams: { page: 2, name: 'Test Company', @@ -717,7 +713,7 @@ describe('FundraisersResource', () => { }); await fundraisers.searchEquity(undefined, '0009876543', 0); - expect(mockClient.get).toHaveBeenLastCalledWith('v4/fundraising', { + expect(mockClient.get).toHaveBeenLastCalledWith('fundraising-search', { searchParams: { page: 0, cik: '0009876543', @@ -725,7 +721,7 @@ describe('FundraisersResource', () => { }); await fundraisers.searchCrowdfunding('Only Name'); - expect(mockClient.get).toHaveBeenLastCalledWith('v4/crowdfunding', { + expect(mockClient.get).toHaveBeenLastCalledWith('crowdfunding-offerings-search', { searchParams: { page: 0, name: 'Only Name', diff --git a/tests/indexes.test.ts b/tests/indexes.test.ts index 5686a6d..e1501aa 100644 --- a/tests/indexes.test.ts +++ b/tests/indexes.test.ts @@ -51,7 +51,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getSP500Constituents(); - expect(mockClient.get).toHaveBeenCalledWith('v3/sp500_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('sp500-constituent'); expect(result).toEqual(mockConstituents); expect(result).toHaveLength(2); expect(result[0].symbol).toBe('AAPL'); @@ -86,7 +86,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getNASDAQConstituents(); - expect(mockClient.get).toHaveBeenCalledWith('v3/nasdaq_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('nasdaq-constituent'); expect(result).toEqual(mockConstituents); expect(result[0].symbol).toBe('GOOGL'); }); @@ -111,7 +111,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getDowJonesConstituents(); - expect(mockClient.get).toHaveBeenCalledWith('v3/dowjones_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('dowjones-constituent'); expect(result).toEqual(mockConstituents); expect(result[0].symbol).toBe('GS'); }); @@ -137,7 +137,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalSP500(); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical/sp500_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('historical-sp500-constituent'); expect(result).toEqual(mockHistorical); expect(result[0].addedSecurity).toBe('VLTO'); }); @@ -161,7 +161,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalNASDAQ(); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical/nasdaq_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('historical-nasdaq-constituent'); expect(result).toEqual(mockHistorical); }); }); @@ -184,7 +184,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalDowJones(); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical/dowjones_constituent'); + expect(mockClient.get).toHaveBeenCalledWith('historical-dowjones-constituent'); expect(result).toEqual(mockHistorical); }); }); @@ -224,7 +224,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getQuote('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^GSPC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockQuote); expect(result[0].symbol).toBe('^GSPC'); expect(result[0].price).toBe(4783.45); @@ -262,7 +262,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getQuote('^IXIC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^IXIC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^IXIC' } }); expect(result[0].symbol).toBe('^IXIC'); }); @@ -298,7 +298,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getQuote('^DJI'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^DJI'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^DJI' } }); expect(result[0].symbol).toBe('^DJI'); }); @@ -307,7 +307,7 @@ describe('IndexesResource', () => { await indexesResource.getQuote('^gspc'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^GSPC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^GSPC' } }); }); it('should handle lowercase index symbols', async () => { @@ -315,7 +315,7 @@ describe('IndexesResource', () => { await indexesResource.getQuote('^ixic'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^IXIC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^IXIC' } }); }); }); @@ -333,7 +333,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getQuoteShort('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/^GSPC'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockShortQuote); }); @@ -342,7 +342,7 @@ describe('IndexesResource', () => { await indexesResource.getQuoteShort('^dji'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote-short/^DJI'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { searchParams: { symbol: '^DJI' } }); }); }); @@ -403,7 +403,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getAllQuotes(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/index'); + expect(mockClient.get).toHaveBeenCalledWith('batch-index-quotes'); expect(result).toEqual(mockQuotes); expect(result).toHaveLength(2); }); @@ -441,7 +441,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getList(); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/available-indexes'); + expect(mockClient.get).toHaveBeenCalledWith('index-list'); expect(result).toEqual(mockList); expect(result).toHaveLength(3); }); @@ -475,7 +475,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalPrices('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockHistorical); expect(result.historical).toHaveLength(1); }); @@ -505,8 +505,9 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalPrices('^GSPC', '2023-12-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^GSPC', from: '2023-12-01', }, } @@ -558,8 +559,9 @@ describe('IndexesResource', () => { '2023-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^GSPC', from: '2023-12-01', to: '2023-12-31', }, @@ -573,8 +575,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalPrices('^dji', '2023-01-01', '2023-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^DJI', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^DJI', from: '2023-01-01', to: '2023-12-31', }, @@ -607,7 +610,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalPrices('^IXIC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^IXIC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { symbol: '^IXIC' } }); expect(result.historical[0].symbol).toBeUndefined(); }); }); @@ -624,7 +627,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalLight('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockLightData); expect(result).toHaveLength(3); expect(result[0]).toHaveProperty('date'); @@ -641,8 +644,9 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalLight('^GSPC', '2023-12-14'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { + symbol: '^GSPC', from: '2023-12-14', }, } @@ -666,8 +670,9 @@ describe('IndexesResource', () => { '2023-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { + symbol: '^GSPC', from: '2023-12-27', to: '2023-12-31', }, @@ -682,8 +687,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalLight('^ixic', '2023-01-01', '2023-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^IXIC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { + symbol: '^IXIC', from: '2023-01-01', to: '2023-12-31', }, @@ -701,7 +707,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getHistoricalLight('^DJI'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^DJI', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { symbol: '^DJI' } }); expect(result[0].close).toBe(37305.16); }); @@ -741,7 +747,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getIntradayChart('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/1hour/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockIntraday); expect(result).toHaveLength(2); }); @@ -762,7 +768,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getIntradayChart('^GSPC', '5min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/5min/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/5min', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockIntraday); }); @@ -782,7 +788,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getIntradayChart('^GSPC', '15min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/15min/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/15min', { searchParams: { symbol: '^GSPC' } }); expect(result).toEqual(mockIntraday); }); @@ -791,7 +797,7 @@ describe('IndexesResource', () => { await indexesResource.getIntradayChart('^GSPC', '30min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/30min/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/30min', { searchParams: { symbol: '^GSPC' } }); }); it('should fetch intraday chart with 4hour interval', async () => { @@ -799,7 +805,7 @@ describe('IndexesResource', () => { await indexesResource.getIntradayChart('^GSPC', '4hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/4hour/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/4hour', { searchParams: { symbol: '^GSPC' } }); }); it('should fetch intraday chart with date range', async () => { @@ -823,8 +829,9 @@ describe('IndexesResource', () => { '2023-12-22' ); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/1hour/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { searchParams: { + symbol: '^GSPC', from: '2023-12-22', to: '2023-12-22', }, @@ -838,8 +845,9 @@ describe('IndexesResource', () => { await indexesResource.getIntradayChart('^dji', '1hour', '2023-12-22'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/1hour/^DJI', { + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { searchParams: { + symbol: '^DJI', from: '2023-12-22', }, } @@ -862,7 +870,7 @@ describe('IndexesResource', () => { const result = await indexesResource.getIntradayChart('^IXIC', '1hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/1hour/^IXIC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { searchParams: { symbol: '^IXIC' } }); expect(result[0].close).toBe(15011.35); }); }); @@ -924,38 +932,38 @@ describe('IndexesResource', () => { // S&P 500 variations await indexesResource.getQuote('^gspc'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^GSPC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^GSPC' } }); await indexesResource.getQuote('^GSPC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^GSPC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^GSPC' } }); // NASDAQ variations await indexesResource.getQuote('^ixic'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^IXIC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^IXIC' } }); await indexesResource.getQuote('^IXIC'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^IXIC'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^IXIC' } }); // Dow Jones variations await indexesResource.getQuote('^dji'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^DJI'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^DJI' } }); await indexesResource.getQuote('^DJI'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/^DJI'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: '^DJI' } }); }); it('should handle mixed case symbols', async () => { vi.mocked(mockClient.get).mockResolvedValue({ historical: [] }); await indexesResource.getHistoricalPrices('^GsPc'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { symbol: '^GSPC' } }); }); it('should handle symbols without caret prefix', async () => { vi.mocked(mockClient.get).mockResolvedValue([]); await indexesResource.getQuote('SPY'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/SPY'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { searchParams: { symbol: 'SPY' } }); }); }); @@ -966,8 +974,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalPrices('^GSPC', '2023-01-01', '2023-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^GSPC', from: '2023-01-01', to: '2023-12-31', }, @@ -981,8 +990,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalPrices('^GSPC', '2023-06-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^GSPC', from: '2023-06-01', }, } @@ -995,8 +1005,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalPrices('^GSPC', undefined, '2023-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-price-full/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { searchParams: { + symbol: '^GSPC', to: '2023-12-31', }, } @@ -1008,8 +1019,9 @@ describe('IndexesResource', () => { await indexesResource.getHistoricalLight('^GSPC', '2023-06-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/line/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { searchParams: { + symbol: '^GSPC', from: '2023-06-01', }, } @@ -1021,8 +1033,9 @@ describe('IndexesResource', () => { await indexesResource.getIntradayChart('^GSPC', '1hour', '2023-12-22'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-chart/1hour/^GSPC', { + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { searchParams: { + symbol: '^GSPC', from: '2023-12-22', }, } diff --git a/tests/insider.test.ts b/tests/insider.test.ts index 6c9667f..784ec32 100644 --- a/tests/insider.test.ts +++ b/tests/insider.test.ts @@ -53,7 +53,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getInsiderTrades('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'AAPL', }, @@ -68,7 +68,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades('tsla'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'TSLA', }, @@ -82,7 +82,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades('AAPL', 50); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'AAPL', limit: 50, @@ -97,7 +97,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'AAPL', }, @@ -134,7 +134,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getInsiderStatistics('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-roaster-statistic', { + expect(mockClient.get).toHaveBeenCalledWith('insider-roaster-statistic', { searchParams: { symbol: 'AAPL', }, @@ -149,7 +149,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderStatistics('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-roaster-statistic', { + expect(mockClient.get).toHaveBeenCalledWith('insider-roaster-statistic', { searchParams: { symbol: 'MSFT', }, @@ -179,7 +179,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getInsiderRoster('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-roaster', { + expect(mockClient.get).toHaveBeenCalledWith('insider-roaster', { searchParams: { symbol: 'AAPL', }, @@ -194,7 +194,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderRoster('googl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-roaster', { + expect(mockClient.get).toHaveBeenCalledWith('insider-roaster', { searchParams: { symbol: 'GOOGL', }, @@ -226,7 +226,9 @@ describe('InsiderResource', () => { const result = await insiderResource.getInstitutionalHolders('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/institutional-holder/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('institutional-holder', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockResponse); }); @@ -236,7 +238,9 @@ describe('InsiderResource', () => { await insiderResource.getInstitutionalHolders('nvda'); - expect(mockClient.get).toHaveBeenCalledWith('v3/institutional-holder/NVDA'); + expect(mockClient.get).toHaveBeenCalledWith('institutional-holder', { + searchParams: { symbol: 'NVDA' }, + }); }); }); @@ -262,7 +266,9 @@ describe('InsiderResource', () => { const result = await insiderResource.get13F('0001067983'); - expect(mockClient.get).toHaveBeenCalledWith('v3/form-thirteen/0001067983', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { + searchParams: { cik: '0001067983' }, + }); expect(result).toEqual(mockResponse); }); @@ -272,12 +278,12 @@ describe('InsiderResource', () => { await insiderResource.get13F('0001067983', '2024-03-31'); - expect(mockClient.get).toHaveBeenCalledWith('v3/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', date: '2024-03-31', - }, - } -); + }, + }); }); it('should not include date parameter when not provided', async () => { @@ -286,7 +292,9 @@ describe('InsiderResource', () => { await insiderResource.get13F('0001067983'); - expect(mockClient.get).toHaveBeenCalledWith('v3/form-thirteen/0001067983', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { + searchParams: { cik: '0001067983' }, + }); }); it('should handle different CIK formats', async () => { @@ -295,7 +303,9 @@ describe('InsiderResource', () => { await insiderResource.get13F('1067983'); - expect(mockClient.get).toHaveBeenCalledWith('v3/form-thirteen/1067983', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { + searchParams: { cik: '1067983' }, + }); }); }); @@ -326,7 +336,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getSenateTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: {} }); expect(result).toEqual(mockResponse); }); @@ -336,7 +346,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTrades('TSLA'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { symbol: 'TSLA', }, @@ -350,7 +360,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTrades('nvda'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { symbol: 'NVDA', }, @@ -366,7 +376,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getHouseTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure', { searchParams: {} }); expect(result).toEqual(mockResponse); }); @@ -376,7 +386,7 @@ describe('InsiderResource', () => { await insiderResource.getHouseTrades('MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure', { + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure', { searchParams: { symbol: 'MSFT', }, @@ -390,7 +400,7 @@ describe('InsiderResource', () => { await insiderResource.getHouseTrades('meta'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure', { + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure', { searchParams: { symbol: 'META', }, @@ -426,7 +436,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getLatestSenateTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading-rss-feed'); + expect(mockClient.get).toHaveBeenCalledWith('senate-trading-rss-feed'); expect(result).toEqual(mockResponse); }); @@ -436,7 +446,7 @@ describe('InsiderResource', () => { await insiderResource.getLatestSenateTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading-rss-feed'); + expect(mockClient.get).toHaveBeenCalledWith('senate-trading-rss-feed'); expect(mockClient.get).toHaveBeenCalledTimes(1); }); }); @@ -448,7 +458,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getLatestHouseTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure-rss-feed'); + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure-rss-feed'); expect(result).toEqual(mockResponse); }); @@ -458,7 +468,7 @@ describe('InsiderResource', () => { await insiderResource.getLatestHouseTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure-rss-feed'); + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure-rss-feed'); expect(mockClient.get).toHaveBeenCalledTimes(1); }); }); @@ -470,7 +480,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTradingByName('Nancy Pelosi'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { name: 'Nancy Pelosi', }, @@ -484,7 +494,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTradingByName("Dan O'Brien"); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { name: "Dan O'Brien", }, @@ -498,7 +508,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTradingByName('Pelosi'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { name: 'Pelosi', }, @@ -514,7 +524,7 @@ describe('InsiderResource', () => { await insiderResource.getHouseTradingByName('Alexandria Ocasio-Cortez'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure', { + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure', { searchParams: { name: 'Alexandria Ocasio-Cortez', }, @@ -528,7 +538,7 @@ describe('InsiderResource', () => { await insiderResource.getHouseTradingByName('Smith-Jones'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-disclosure', { + expect(mockClient.get).toHaveBeenCalledWith('house-disclosure', { searchParams: { name: 'Smith-Jones', }, @@ -544,7 +554,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getLatestInsiderTrades(); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: {} }); expect(result).toEqual(mockResponse); }); @@ -554,7 +564,7 @@ describe('InsiderResource', () => { await insiderResource.getLatestInsiderTrades(100); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { limit: 100, }, @@ -568,7 +578,7 @@ describe('InsiderResource', () => { await insiderResource.getLatestInsiderTrades(0); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: {} }); }); }); @@ -579,7 +589,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTradesByName('Tim Cook'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { reportingName: 'Tim Cook', }, @@ -593,7 +603,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTradesByName('Tim Cook', 25); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { reportingName: 'Tim Cook', limit: 25, @@ -608,7 +618,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTradesByName('Mary-Anne O\'Connor Jr.'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { reportingName: 'Mary-Anne O\'Connor Jr.', }, @@ -622,7 +632,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTradesByName('Tim Cook', 0); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { reportingName: 'Tim Cook', }, @@ -645,7 +655,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getInsiderTransactionTypes(); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/insider-trading-transaction-type' + 'insider-trading-transaction-type' ); expect(result).toEqual(mockResponse); }); @@ -657,7 +667,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTransactionTypes(); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/insider-trading-transaction-type' + 'insider-trading-transaction-type' ); expect(mockClient.get).toHaveBeenCalledTimes(1); }); @@ -678,7 +688,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getForm4Ownership('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-four', { + expect(mockClient.get).toHaveBeenCalledWith('form-four', { searchParams: { symbol: 'AAPL', }, @@ -693,7 +703,7 @@ describe('InsiderResource', () => { await insiderResource.getForm4Ownership('googl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-four', { + expect(mockClient.get).toHaveBeenCalledWith('form-four', { searchParams: { symbol: 'GOOGL', }, @@ -707,7 +717,7 @@ describe('InsiderResource', () => { await insiderResource.getForm4Ownership('AAPL', 50); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-four', { + expect(mockClient.get).toHaveBeenCalledWith('form-four', { searchParams: { symbol: 'AAPL', limit: 50, @@ -722,7 +732,7 @@ describe('InsiderResource', () => { await insiderResource.getForm4Ownership('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-four', { + expect(mockClient.get).toHaveBeenCalledWith('form-four', { searchParams: { symbol: 'AAPL', }, @@ -743,7 +753,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getLatest13FFilings(); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: {} } ); expect(result).toEqual(mockResponse); @@ -756,7 +766,7 @@ describe('InsiderResource', () => { await insiderResource.getLatest13FFilings('0001067983'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '0001067983' }, } ); @@ -769,7 +779,7 @@ describe('InsiderResource', () => { await insiderResource.getLatest13FFilings(undefined, 2); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { page: 2 }, } ); @@ -782,7 +792,7 @@ describe('InsiderResource', () => { await insiderResource.getLatest13FFilings('0001067983', 3); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '0001067983', page: 3 }, } ); @@ -795,7 +805,7 @@ describe('InsiderResource', () => { await insiderResource.getLatest13FFilings('0001067983', 0); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '0001067983' }, } ); @@ -815,7 +825,7 @@ describe('InsiderResource', () => { const result = await insiderResource.get13FFilingDates('0001067983'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '0001067983' }, } ); @@ -829,7 +839,7 @@ describe('InsiderResource', () => { await insiderResource.get13FFilingDates('1067983'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '1067983' }, } ); @@ -861,7 +871,9 @@ describe('InsiderResource', () => { const result = await insiderResource.get13FWithAnalytics('0001067983'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-thirteen/0001067983', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { + searchParams: { cik: '0001067983' }, + }); expect(result).toEqual(mockResponse); }); @@ -871,12 +883,12 @@ describe('InsiderResource', () => { await insiderResource.get13FWithAnalytics('0001067983', '2024-03-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', date: '2024-03-31', - }, - } -); + }, + }); }); it('should include page parameter for pagination', async () => { @@ -885,12 +897,12 @@ describe('InsiderResource', () => { await insiderResource.get13FWithAnalytics('0001067983', undefined, 2); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', page: 2, - }, - } -); + }, + }); }); it('should include both date and page parameters', async () => { @@ -899,13 +911,13 @@ describe('InsiderResource', () => { await insiderResource.get13FWithAnalytics('0001067983', '2024-03-31', 1); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', date: '2024-03-31', - page: 1, - }, - } -); + page: 1, + }, + }); }); it('should handle different date formats', async () => { @@ -914,12 +926,12 @@ describe('InsiderResource', () => { await insiderResource.get13FWithAnalytics('0001067983', '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', date: '2024-12-31', - }, - } -); + }, + }); }); }); @@ -942,7 +954,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getPortfolioHoldingsSummary('0001067983'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-holdings-summary', + 'institutional-ownership-portfolio-holdings-summary', { searchParams: { cik: '0001067983' }, } ); @@ -956,7 +968,7 @@ describe('InsiderResource', () => { await insiderResource.getPortfolioHoldingsSummary('0001067983', '2024-03-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-holdings-summary', + 'institutional-ownership-portfolio-holdings-summary', { searchParams: { cik: '0001067983', date: '2024-03-31' }, } ); @@ -969,7 +981,7 @@ describe('InsiderResource', () => { await insiderResource.getPortfolioHoldingsSummary('0001067983', undefined, 2); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-holdings-summary', + 'institutional-ownership-portfolio-holdings-summary', { searchParams: { cik: '0001067983', page: 2 }, } ); @@ -986,7 +998,7 @@ describe('InsiderResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-holdings-summary', + 'institutional-ownership-portfolio-holdings-summary', { searchParams: { cik: '0001067983', date: '2023-12-31', page: 3 }, } ); @@ -999,7 +1011,7 @@ describe('InsiderResource', () => { await insiderResource.getPortfolioHoldingsSummary('0001067983', undefined, 0); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-holdings-summary', + 'institutional-ownership-portfolio-holdings-summary', { searchParams: { cik: '0001067983' }, } ); @@ -1034,7 +1046,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getIndustryPortfolioBreakdown('0001067983'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/industry/portfolio-holdings-summary', + 'institutional-ownership-industry-portfolio-holdings-summary', { searchParams: { cik: '0001067983' }, } ); @@ -1048,7 +1060,7 @@ describe('InsiderResource', () => { await insiderResource.getIndustryPortfolioBreakdown('0001067983', '2024-03-31'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/industry/portfolio-holdings-summary', + 'institutional-ownership-industry-portfolio-holdings-summary', { searchParams: { cik: '0001067983', date: '2024-03-31' }, } ); @@ -1061,7 +1073,7 @@ describe('InsiderResource', () => { await insiderResource.getIndustryPortfolioBreakdown('0001067983', undefined, 2); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/industry/portfolio-holdings-summary', + 'institutional-ownership-industry-portfolio-holdings-summary', { searchParams: { cik: '0001067983', page: 2 }, } ); @@ -1078,7 +1090,7 @@ describe('InsiderResource', () => { ); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/industry/portfolio-holdings-summary', + 'institutional-ownership-industry-portfolio-holdings-summary', { searchParams: { cik: '0001067983', date: '2023-09-30', page: 1 }, } ); @@ -1106,7 +1118,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getSymbolOwnershipPositions('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL' }, } ); @@ -1120,7 +1132,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('msft'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'MSFT' }, } ); @@ -1133,7 +1145,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', true); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL', includeCurrentQuarter: true }, } ); @@ -1146,7 +1158,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', false); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL', includeCurrentQuarter: false }, } ); @@ -1159,7 +1171,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', undefined); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL' }, } ); @@ -1172,7 +1184,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', undefined, 2); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL', page: 2 }, } ); @@ -1185,7 +1197,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', true, 3); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL', includeCurrentQuarter: true, page: 3 }, } ); @@ -1198,7 +1210,7 @@ describe('InsiderResource', () => { await insiderResource.getSymbolOwnershipPositions('AAPL', false, 0); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/symbol-ownership', + 'institutional-ownership-symbol-ownership', { searchParams: { symbol: 'AAPL', includeCurrentQuarter: false }, } ); @@ -1224,7 +1236,7 @@ describe('InsiderResource', () => { const result = await insiderResource.getIndustryInstitutionalOwnership('AAPL'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/institutional-holders/symbol-ownership-percent', + 'institutional-ownership-symbol-ownership-percent', { searchParams: { symbol: 'AAPL' }, } ); @@ -1238,7 +1250,7 @@ describe('InsiderResource', () => { await insiderResource.getIndustryInstitutionalOwnership('tsla'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/institutional-holders/symbol-ownership-percent', + 'institutional-ownership-symbol-ownership-percent', { searchParams: { symbol: 'TSLA' }, } ); @@ -1251,7 +1263,7 @@ describe('InsiderResource', () => { await insiderResource.getIndustryInstitutionalOwnership('AAPL', 2); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/institutional-holders/symbol-ownership-percent', + 'institutional-ownership-symbol-ownership-percent', { searchParams: { symbol: 'AAPL', page: 2 }, } ); @@ -1264,7 +1276,7 @@ describe('InsiderResource', () => { await insiderResource.getIndustryInstitutionalOwnership('AAPL', 0); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/institutional-holders/symbol-ownership-percent', + 'institutional-ownership-symbol-ownership-percent', { searchParams: { symbol: 'AAPL' }, } ); @@ -1306,7 +1318,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades(''); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: '', }, @@ -1320,10 +1332,9 @@ describe('InsiderResource', () => { await insiderResource.get13F('00000000001067983'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/form-thirteen/00000000001067983', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { + searchParams: { cik: '00000000001067983' }, + }); }); it('should handle special characters in names', async () => { @@ -1332,7 +1343,7 @@ describe('InsiderResource', () => { await insiderResource.getSenateTradingByName('José María García-López'); - expect(mockClient.get).toHaveBeenCalledWith('v4/senate-trading', { + expect(mockClient.get).toHaveBeenCalledWith('senate-trading', { searchParams: { name: 'José María García-López', }, @@ -1346,12 +1357,12 @@ describe('InsiderResource', () => { await insiderResource.get13F('0001067983', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v3/form-thirteen/0001067983', { + expect(mockClient.get).toHaveBeenCalledWith('form-thirteen', { searchParams: { + cik: '0001067983', date: '2024-01-01', - }, - } -); + }, + }); }); it('should handle very large page numbers', async () => { @@ -1361,7 +1372,7 @@ describe('InsiderResource', () => { await insiderResource.getLatest13FFilings('0001067983', 9999); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/institutional-ownership/portfolio-date', + 'institutional-ownership-portfolio-date', { searchParams: { cik: '0001067983', page: 9999 }, } ); @@ -1373,7 +1384,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades('AAPL', 10000); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'AAPL', limit: 10000, @@ -1388,7 +1399,7 @@ describe('InsiderResource', () => { await insiderResource.getInsiderTrades('BRK.B'); - expect(mockClient.get).toHaveBeenCalledWith('v4/insider-trading', { + expect(mockClient.get).toHaveBeenCalledWith('insider-trading', { searchParams: { symbol: 'BRK.B', }, diff --git a/tests/market.test.ts b/tests/market.test.ts index 439f91c..61bfd60 100644 --- a/tests/market.test.ts +++ b/tests/market.test.ts @@ -1,8 +1,9 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { MarketResource } from '../src/resources/market.js'; +import { MarketResource, IntradayInterval } from '../src/resources/market.js'; import type { FMPClient } from '../src/client.js'; import type { IntradayChart, + HistoricalPrice, ForexPrice, ForexCurrencyPair, ForexQuoteShort, @@ -27,35 +28,32 @@ describe('MarketResource', () => { }); describe('getHistoricalPrices', () => { - const mockHistoricalData = { - historical: [ - { - date: '2024-01-01', - open: 150.5, - high: 152.3, - low: 149.8, - close: 151.2, - adjClose: 151.2, - volume: 1000000, - unadjustedVolume: 1000000, - change: 0.7, - changePercent: 0.46, - vwap: 151.0, - label: 'January 01, 24', - changeOverTime: 0.0046, - }, - ], - }; + const mockHistoricalData: HistoricalPrice[] = [ + { + date: '2024-01-01', + open: 150.5, + high: 152.3, + low: 149.8, + close: 151.2, + adjClose: 151.2, + volume: 1000000, + unadjustedVolume: 1000000, + change: 0.7, + changePercent: 0.46, + vwap: 151.0, + label: 'January 01, 24', + changeOverTime: 0.0046, + }, + ]; it('should fetch historical prices without date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockHistoricalData); const result = await marketResource.getHistoricalPrices('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockHistoricalData); }); @@ -64,11 +62,9 @@ describe('MarketResource', () => { const result = await marketResource.getHistoricalPrices('AAPL', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: { from: '2024-01-01' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL', from: '2024-01-01' }, + }); expect(result).toEqual(mockHistoricalData); }); @@ -81,11 +77,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockHistoricalData); }); @@ -94,10 +88,44 @@ describe('MarketResource', () => { await marketResource.getHistoricalPrices('aapl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: {} } + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL' }, + }); + }); + }); + + describe('getHistoricalPricesLight', () => { + const mockLightData: LightChartData[] = [ + { + date: '2024-01-01', + close: 151.2, + }, + ]; + + it('should fetch light historical prices without date range', async () => { + vi.mocked(mockClient.get).mockResolvedValue(mockLightData); + + const result = await marketResource.getHistoricalPricesLight('AAPL'); + + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'AAPL' }, + }); + expect(result).toEqual(mockLightData); + }); + + it('should fetch light historical prices with date range', async () => { + vi.mocked(mockClient.get).mockResolvedValue(mockLightData); + + const result = await marketResource.getHistoricalPricesLight( + 'AAPL', + '2024-01-01', + '2024-12-31' ); + + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-12-31' }, + }); + expect(result).toEqual(mockLightData); }); }); @@ -118,70 +146,64 @@ describe('MarketResource', () => { const result = await marketResource.getIntradayChart('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); it('should fetch intraday chart with 1min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getIntradayChart('AAPL', '1min'); + const result = await marketResource.getIntradayChart('AAPL', IntradayInterval.OneMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1min', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); it('should fetch intraday chart with 5min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getIntradayChart('AAPL', '5min'); + const result = await marketResource.getIntradayChart('AAPL', IntradayInterval.FiveMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/5min', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); it('should fetch intraday chart with 15min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getIntradayChart('AAPL', '15min'); + const result = await marketResource.getIntradayChart('AAPL', IntradayInterval.FifteenMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/15min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/15min', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); it('should fetch intraday chart with 30min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getIntradayChart('AAPL', '30min'); + const result = await marketResource.getIntradayChart('AAPL', IntradayInterval.ThirtyMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/30min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/30min', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); it('should fetch intraday chart with 4hour interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getIntradayChart('AAPL', '4hour'); + const result = await marketResource.getIntradayChart('AAPL', IntradayInterval.FourHour); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/4hour/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/4hour', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockIntradayData); }); @@ -190,28 +212,25 @@ describe('MarketResource', () => { const result = await marketResource.getIntradayChart( 'AAPL', - '1hour', + IntradayInterval.OneHour, '2024-01-01', '2024-01-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/AAPL', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-01-31' }, + }); expect(result).toEqual(mockIntradayData); }); it('should convert symbol to uppercase', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - await marketResource.getIntradayChart('tsla', '1min'); + await marketResource.getIntradayChart('tsla', IntradayInterval.OneMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/TSLA', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1min', { + searchParams: { symbol: 'TSLA' }, + }); }); }); @@ -234,16 +253,9 @@ describe('MarketResource', () => { const result = await marketResource.getForexPrice('EURUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/fx/EURUSD'); - expect(result).toEqual(mockForexData); - }); - - it('should fetch all forex prices when no pair specified', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockForexData); - - const result = await marketResource.getForexPrice(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/fx'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockForexData); }); @@ -252,7 +264,9 @@ describe('MarketResource', () => { await marketResource.getForexPrice('eurusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/fx/EURUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'EURUSD' }, + }); }); }); @@ -275,41 +289,38 @@ describe('MarketResource', () => { const result = await marketResource.getAllForexPrices(); - expect(mockClient.get).toHaveBeenCalledWith('v3/fx'); + expect(mockClient.get).toHaveBeenCalledWith('batch-forex-quotes'); expect(result).toEqual(mockForexData); }); }); describe('getHistoricalForex', () => { - const mockHistoricalForex = { - historical: [ - { - date: '2024-01-01', - open: 1.0850, - high: 1.0860, - low: 1.0840, - close: 1.0855, - adjClose: 1.0855, - volume: 0, - unadjustedVolume: 0, - change: 0.0005, - changePercent: 0.05, - vwap: 1.0851, - label: 'January 01, 24', - changeOverTime: 0.0005, - }, - ], - }; + const mockHistoricalForex: HistoricalPrice[] = [ + { + date: '2024-01-01', + open: 1.0850, + high: 1.0860, + low: 1.0840, + close: 1.0855, + adjClose: 1.0855, + volume: 0, + unadjustedVolume: 0, + change: 0.0005, + changePercent: 0.05, + vwap: 1.0851, + label: 'January 01, 24', + changeOverTime: 0.0005, + }, + ]; it('should fetch historical forex without date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockHistoricalForex); const result = await marketResource.getHistoricalForex('EURUSD'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/EURUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockHistoricalForex); }); @@ -322,11 +333,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/EURUSD', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'EURUSD', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockHistoricalForex); }); @@ -335,10 +344,9 @@ describe('MarketResource', () => { await marketResource.getHistoricalForex('gbpusd'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GBPUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'GBPUSD' }, + }); }); }); @@ -371,16 +379,9 @@ describe('MarketResource', () => { const result = await marketResource.getCryptoPrice('BTCUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/BTCUSD'); - expect(result).toEqual(mockCryptoData); - }); - - it('should fetch all crypto prices when no symbol specified', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockCryptoData); - - const result = await marketResource.getCryptoPrice(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/crypto'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockCryptoData); }); @@ -389,7 +390,9 @@ describe('MarketResource', () => { await marketResource.getCryptoPrice('ethusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/ETHUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'ETHUSD' }, + }); }); }); @@ -422,45 +425,35 @@ describe('MarketResource', () => { const result = await marketResource.getAllCryptoPrices(); - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/crypto'); + expect(mockClient.get).toHaveBeenCalledWith('batch-crypto-quotes'); expect(result).toEqual(mockCryptoData); }); }); describe('getMarketHours', () => { - const mockMarketHours: MarketHours = { - stockExchangeName: 'New York Stock Exchange', - stockMarketHours: { - openingHour: '09:30:00', - closingHour: '16:00:00', + const mockMarketHours: MarketHours[] = [ + { + stockExchangeName: 'New York Stock Exchange', + stockMarketHours: { + openingHour: '09:30:00', + closingHour: '16:00:00', + }, + stockMarketHolidays: ['2024-01-01', '2024-07-04', '2024-12-25'], + isTheStockMarketOpen: true, + isTheEuronextMarketOpen: false, + isTheForexMarketOpen: true, + isTheCryptoMarketOpen: true, }, - stockMarketHolidays: ['2024-01-01', '2024-07-04', '2024-12-25'], - isTheStockMarketOpen: true, - isTheEuronextMarketOpen: false, - isTheForexMarketOpen: true, - isTheCryptoMarketOpen: true, - }; - - it('should fetch market hours without exchange', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockMarketHours); - - const result = await marketResource.getMarketHours(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/is-the-market-open', { searchParams: {} }); - expect(result).toEqual(mockMarketHours); - }); + ]; it('should fetch market hours for specific exchange', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockMarketHours); const result = await marketResource.getMarketHours('NYSE'); - expect(mockClient.get).toHaveBeenCalledWith('v3/is-the-market-open', { - searchParams: { - exchange: 'NYSE', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('exchange-market-hours', { + searchParams: { exchange: 'NYSE' }, + }); expect(result).toEqual(mockMarketHours); }); }); @@ -477,16 +470,18 @@ describe('MarketResource', () => { 'Independence Day': '2024-07-04', 'Labor Day': '2024-09-02', 'Thanksgiving Day': '2024-11-28', - 'Christmas': '2024-12-25', + Christmas: '2024-12-25', }, ]; - it('should fetch market holidays', async () => { + it('should fetch market holidays for specific exchange', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockHolidays); - const result = await marketResource.getMarketHolidays(); + const result = await marketResource.getMarketHolidays('NYSE'); - expect(mockClient.get).toHaveBeenCalledWith('v3/market-holidays'); + expect(mockClient.get).toHaveBeenCalledWith('holidays-by-exchange', { + searchParams: { exchange: 'NYSE' }, + }); expect(result).toEqual(mockHolidays); }); }); @@ -524,7 +519,7 @@ describe('MarketResource', () => { const result = await marketResource.getAllMarketHours(); - expect(mockClient.get).toHaveBeenCalledWith('v3/market-hours'); + expect(mockClient.get).toHaveBeenCalledWith('all-exchange-market-hours'); expect(result).toEqual(mockAllMarketHours); }); }); @@ -545,9 +540,7 @@ describe('MarketResource', () => { const result = await marketResource.getForexCurrencyPairs(); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/symbol/available-forex-currency-pairs' - ); + expect(mockClient.get).toHaveBeenCalledWith('forex-list'); expect(result).toEqual(mockPairs); }); }); @@ -566,16 +559,9 @@ describe('MarketResource', () => { const result = await marketResource.getForexQuoteShort('EURUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/forex/EURUSD'); - expect(result).toEqual(mockQuotes); - }); - - it('should fetch all forex quotes when no pair specified', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockQuotes); - - const result = await marketResource.getForexQuoteShort(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/forex'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockQuotes); }); @@ -584,7 +570,9 @@ describe('MarketResource', () => { await marketResource.getForexQuoteShort('eurusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/forex/EURUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'EURUSD' }, + }); }); }); @@ -601,10 +589,9 @@ describe('MarketResource', () => { const result = await marketResource.getForexLightChart('EURUSD'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/EURUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockLightChart); }); @@ -617,11 +604,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/EURUSD', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'EURUSD', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockLightChart); }); @@ -630,14 +615,13 @@ describe('MarketResource', () => { await marketResource.getForexLightChart('gbpjpy'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/GBPJPY', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'GBPJPY' }, + }); }); }); - describe('getForexIntraday1Min', () => { + describe('getForexIntraday', () => { const mockIntradayData: IntradayChart[] = [ { date: '2024-01-01 09:30:00', @@ -649,128 +633,52 @@ describe('MarketResource', () => { }, ]; - it('should fetch 1-minute forex intraday data', async () => { + it('should fetch forex intraday data with default interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getForexIntraday1Min('EURUSD'); + const result = await marketResource.getForexIntraday('EURUSD'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/EURUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockIntradayData); }); - it('should fetch 1-minute forex intraday data with date range', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - const result = await marketResource.getForexIntraday1Min( - 'EURUSD', - '2024-01-01', - '2024-01-02' - ); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/EURUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-02' }, } - - ); - expect(result).toEqual(mockIntradayData); - }); - - it('should convert pair to uppercase', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - await marketResource.getForexIntraday1Min('usdjpy'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/USDJPY', - { searchParams: {} } - ); - }); - }); - - describe('getForexIntraday5Min', () => { - const mockIntradayData: IntradayChart[] = [ - { - date: '2024-01-01 09:30:00', - open: 1.0850, - high: 1.0855, - low: 1.0845, - close: 1.0852, - volume: 50000, - }, - ]; - - it('should fetch 5-minute forex intraday data', async () => { + it('should fetch forex intraday data with custom interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getForexIntraday5Min('EURUSD'); + const result = await marketResource.getForexIntraday('EURUSD', IntradayInterval.FiveMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/EURUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/5min', { + searchParams: { symbol: 'EURUSD' }, + }); expect(result).toEqual(mockIntradayData); }); - it('should fetch 5-minute forex intraday data with date range', async () => { + it('should fetch forex intraday data with date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getForexIntraday5Min( + const result = await marketResource.getForexIntraday( 'EURUSD', + IntradayInterval.OneMin, '2024-01-01', '2024-01-02' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/EURUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-02' }, } - - ); - expect(result).toEqual(mockIntradayData); - }); - }); - - describe('getForexIntraday1Hour', () => { - const mockIntradayData: IntradayChart[] = [ - { - date: '2024-01-01 09:00:00', - open: 1.0850, - high: 1.0870, - low: 1.0840, - close: 1.0865, - volume: 500000, - }, - ]; - - it('should fetch 1-hour forex intraday data', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - const result = await marketResource.getForexIntraday1Hour('EURUSD'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/EURUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1min', { + searchParams: { symbol: 'EURUSD', from: '2024-01-01', to: '2024-01-02' }, + }); expect(result).toEqual(mockIntradayData); }); - it('should fetch 1-hour forex intraday data with date range', async () => { + it('should convert pair to uppercase', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getForexIntraday1Hour( - 'EURUSD', - '2024-01-01', - '2024-01-31' - ); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/EURUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } + await marketResource.getForexIntraday('usdjpy'); - ); - expect(result).toEqual(mockIntradayData); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'USDJPY' }, + }); }); }); @@ -790,52 +698,28 @@ describe('MarketResource', () => { const result = await marketResource.getCryptoList(); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/symbol/available-cryptocurrencies' - ); + expect(mockClient.get).toHaveBeenCalledWith('cryptocurrency-list'); expect(result).toEqual(mockCryptoList); }); }); describe('getCryptoQuoteShort', () => { - const mockCryptoQuote: CryptoPrice[] = [ + const mockCryptoQuote: ForexQuoteShort[] = [ { symbol: 'BTCUSD', - name: 'Bitcoin USD', price: 45000, - changesPercentage: 2.5, - change: 1100, - dayLow: 44000, - dayHigh: 46000, - yearHigh: 69000, - yearLow: 15000, - marketCap: 880000000000, - priceAvg50: 43000, - priceAvg200: 35000, volume: 25000000000, - avgVolume: 22000000000, - exchange: 'CRYPTO', - open: 44500, - previousClose: 43900, - timestamp: 1704110400, }, ]; - it('should fetch specific crypto quote', async () => { + it('should fetch specific crypto quote short', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockCryptoQuote); const result = await marketResource.getCryptoQuoteShort('BTCUSD'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/BTCUSD'); - expect(result).toEqual(mockCryptoQuote); - }); - - it('should fetch all crypto quotes when no symbol specified', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockCryptoQuote); - - const result = await marketResource.getCryptoQuoteShort(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/crypto'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockCryptoQuote); }); @@ -844,7 +728,9 @@ describe('MarketResource', () => { await marketResource.getCryptoQuoteShort('ethusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/ETHUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote-short', { + searchParams: { symbol: 'ETHUSD' }, + }); }); }); @@ -861,10 +747,9 @@ describe('MarketResource', () => { const result = await marketResource.getCryptoLightChart('BTCUSD'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/BTCUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockLightChart); }); @@ -877,11 +762,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/BTCUSD', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'BTCUSD', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockLightChart); }); @@ -890,43 +773,39 @@ describe('MarketResource', () => { await marketResource.getCryptoLightChart('ethusd'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/line/ETHUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/light', { + searchParams: { symbol: 'ETHUSD' }, + }); }); }); describe('getCryptoFullChart', () => { - const mockFullChart = { - historical: [ - { - date: '2024-01-01', - open: 45000, - high: 46000, - low: 44000, - close: 45500, - adjClose: 45500, - volume: 25000000000, - unadjustedVolume: 25000000000, - change: 500, - changePercent: 1.11, - vwap: 45300, - label: 'January 01, 24', - changeOverTime: 0.0111, - }, - ], - }; + const mockFullChart: HistoricalPrice[] = [ + { + date: '2024-01-01', + open: 45000, + high: 46000, + low: 44000, + close: 45500, + adjClose: 45500, + volume: 25000000000, + unadjustedVolume: 25000000000, + change: 500, + changePercent: 1.11, + vwap: 45300, + label: 'January 01, 24', + changeOverTime: 0.0111, + }, + ]; it('should fetch crypto full chart without date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockFullChart); const result = await marketResource.getCryptoFullChart('BTCUSD'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/BTCUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockFullChart); }); @@ -939,11 +818,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/BTCUSD', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'BTCUSD', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockFullChart); }); @@ -952,14 +829,13 @@ describe('MarketResource', () => { await marketResource.getCryptoFullChart('btcusd'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/BTCUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'BTCUSD' }, + }); }); }); - describe('getCryptoIntraday1Min', () => { + describe('getCryptoIntraday', () => { const mockIntradayData: IntradayChart[] = [ { date: '2024-01-01 09:30:00', @@ -971,197 +847,71 @@ describe('MarketResource', () => { }, ]; - it('should fetch 1-minute crypto intraday data', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - const result = await marketResource.getCryptoIntraday1Min('BTCUSD'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/BTCUSD', - { searchParams: {} } - ); - expect(result).toEqual(mockIntradayData); - }); - - it('should fetch 1-minute crypto intraday data with date range', async () => { + it('should fetch crypto intraday data with default interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getCryptoIntraday1Min( - 'BTCUSD', - '2024-01-01', - '2024-01-02' - ); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/BTCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-02' }, } + const result = await marketResource.getCryptoIntraday('BTCUSD'); - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockIntradayData); }); - it('should convert symbol to uppercase', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - await marketResource.getCryptoIntraday1Min('ethusd'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/ETHUSD', - { searchParams: {} } - ); - }); - }); - - describe('getCryptoIntraday5Min', () => { - const mockIntradayData: IntradayChart[] = [ - { - date: '2024-01-01 09:30:00', - open: 45000, - high: 45200, - low: 44800, - close: 45100, - volume: 5000000, - }, - ]; - - it('should fetch 5-minute crypto intraday data', async () => { + it('should fetch crypto intraday data with custom interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getCryptoIntraday5Min('BTCUSD'); + const result = await marketResource.getCryptoIntraday('BTCUSD', IntradayInterval.FiveMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/BTCUSD', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/5min', { + searchParams: { symbol: 'BTCUSD' }, + }); expect(result).toEqual(mockIntradayData); }); - it('should fetch 5-minute crypto intraday data with date range', async () => { + it('should fetch crypto intraday data with date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - const result = await marketResource.getCryptoIntraday5Min( + const result = await marketResource.getCryptoIntraday( 'BTCUSD', + IntradayInterval.OneMin, '2024-01-01', '2024-01-02' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/BTCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-02' }, } - - ); - expect(result).toEqual(mockIntradayData); - }); - }); - - describe('getCryptoIntraday1Hour', () => { - const mockIntradayData: IntradayChart[] = [ - { - date: '2024-01-01 09:00:00', - open: 45000, - high: 45500, - low: 44500, - close: 45300, - volume: 50000000, - }, - ]; - - it('should fetch 1-hour crypto intraday data', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - const result = await marketResource.getCryptoIntraday1Hour('BTCUSD'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/BTCUSD', - { searchParams: {} } - ); - expect(result).toEqual(mockIntradayData); - }); - - it('should fetch 1-hour crypto intraday data with date range', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - - const result = await marketResource.getCryptoIntraday1Hour( - 'BTCUSD', - '2024-01-01', - '2024-01-31' - ); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/BTCUSD', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1min', { + searchParams: { symbol: 'BTCUSD', from: '2024-01-01', to: '2024-01-02' }, + }); expect(result).toEqual(mockIntradayData); }); - }); - - describe('getLightChart', () => { - const mockLightChart: LightChartData[] = [ - { - date: '2024-01-01 09:30:00', - close: 150.5, - }, - ]; - - it('should fetch light chart with interval', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockLightChart); - - const result = await marketResource.getLightChart('1min', 'AAPL'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/AAPL', - { searchParams: {} } - ); - expect(result).toEqual(mockLightChart); - }); - - it('should fetch light chart with date range', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockLightChart); - - const result = await marketResource.getLightChart( - '5min', - 'AAPL', - '2024-01-01', - '2024-01-31' - ); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/AAPL', - { searchParams: { from: '2024-01-01', to: '2024-01-31' }, } - - ); - expect(result).toEqual(mockLightChart); - }); it('should convert symbol to uppercase', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockLightChart); - - await marketResource.getLightChart('1hour', 'tsla'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/TSLA', - { searchParams: {} } - ); - }); - - it('should work with custom intervals', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockLightChart); + vi.mocked(mockClient.get).mockResolvedValue(mockIntradayData); - await marketResource.getLightChart('15min', 'AAPL'); + await marketResource.getCryptoIntraday('ethusd'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/15min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'ETHUSD' }, + }); }); }); describe('getUnadjustedPrice', () => { - const mockUnadjustedData: LightChartData[] = [ + const mockUnadjustedData: HistoricalPrice[] = [ { date: '2024-01-01', + open: 150.0, + high: 152.0, + low: 149.0, close: 150.5, + adjClose: 150.5, + volume: 1000000, + unadjustedVolume: 1000000, + change: 0.5, + changePercent: 0.33, + vwap: 150.3, + label: 'January 01, 24', + changeOverTime: 0.0033, }, ]; @@ -1170,10 +920,9 @@ describe('MarketResource', () => { const result = await marketResource.getUnadjustedPrice('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL/line', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/non-split-adjusted', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockUnadjustedData); }); @@ -1186,11 +935,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL/line', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/non-split-adjusted', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockUnadjustedData); }); @@ -1199,44 +946,39 @@ describe('MarketResource', () => { await marketResource.getUnadjustedPrice('msft'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/MSFT/line', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/non-split-adjusted', { + searchParams: { symbol: 'MSFT' }, + }); }); }); describe('getDividendAdjusted', () => { - const mockDividendAdjusted = { - historical: [ - { - date: '2024-01-01', - open: 150.0, - high: 152.0, - low: 149.0, - close: 151.0, - adjClose: 149.5, - volume: 1000000, - unadjustedVolume: 1000000, - change: 1.0, - changePercent: 0.67, - vwap: 150.5, - label: 'January 01, 24', - changeOverTime: 0.0067, - }, - ], - }; + const mockDividendAdjusted: HistoricalPrice[] = [ + { + date: '2024-01-01', + open: 150.0, + high: 152.0, + low: 149.0, + close: 151.0, + adjClose: 149.5, + volume: 1000000, + unadjustedVolume: 1000000, + change: 1.0, + changePercent: 0.67, + vwap: 150.5, + label: 'January 01, 24', + changeOverTime: 0.0067, + }, + ]; it('should fetch dividend-adjusted prices without date range', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockDividendAdjusted); const result = await marketResource.getDividendAdjusted('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: { serietype: 'line' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/dividend-adjusted', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockDividendAdjusted); }); @@ -1249,17 +991,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { - searchParams: { - serietype: 'line', - from: '2024-01-01', - to: '2024-12-31', - }, - } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/dividend-adjusted', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-12-31' }, + }); expect(result).toEqual(mockDividendAdjusted); }); @@ -1268,20 +1002,9 @@ describe('MarketResource', () => { await marketResource.getDividendAdjusted('goog'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/GOOG', - { searchParams: { serietype: 'line' }, } - - ); - }); - - it('should always include serietype parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue(mockDividendAdjusted); - - await marketResource.getDividendAdjusted('AAPL', '2024-01-01'); - - const callArgs = vi.mocked(mockClient.get).mock.calls[0]; - expect(callArgs[1].searchParams).toHaveProperty('serietype', 'line'); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/dividend-adjusted', { + searchParams: { symbol: 'GOOG' }, + }); }); }); @@ -1324,17 +1047,16 @@ describe('MarketResource', () => { }); describe('Symbol Case Handling', () => { - const mockData = { historical: [] }; + const mockData: HistoricalPrice[] = []; it('should handle mixed case symbols', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); await marketResource.getHistoricalPrices('AaPl'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should handle lowercase forex pairs', async () => { @@ -1342,7 +1064,9 @@ describe('MarketResource', () => { await marketResource.getForexPrice('eurusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/fx/EURUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'EURUSD' }, + }); }); it('should handle lowercase crypto symbols', async () => { @@ -1350,23 +1074,23 @@ describe('MarketResource', () => { await marketResource.getCryptoPrice('btcusd'); - expect(mockClient.get).toHaveBeenCalledWith('v3/quote/BTCUSD'); + expect(mockClient.get).toHaveBeenCalledWith('quote', { + searchParams: { symbol: 'BTCUSD' }, + }); }); }); describe('Date Parameter Handling', () => { - const mockData = { historical: [] }; + const mockData: HistoricalPrice[] = []; it('should handle only from date', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); await marketResource.getHistoricalPrices('AAPL', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: { from: '2024-01-01' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL', from: '2024-01-01' }, + }); }); it('should handle both from and to dates', async () => { @@ -1378,11 +1102,9 @@ describe('MarketResource', () => { '2024-12-31' ); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-price-full/AAPL', - { searchParams: { from: '2024-01-01', to: '2024-12-31' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-price-eod/full', { + searchParams: { symbol: 'AAPL', from: '2024-01-01', to: '2024-12-31' }, + }); }); it('should not include undefined dates in params', async () => { @@ -1391,9 +1113,9 @@ describe('MarketResource', () => { await marketResource.getHistoricalPrices('AAPL'); const params = vi.mocked(mockClient.get).mock.calls[0][1]; - expect(params).toEqual({ searchParams: {} }); - expect(params.searchParams).not.toHaveProperty('from'); - expect(params.searchParams).not.toHaveProperty('to'); + expect(params).toEqual({ searchParams: { symbol: 'AAPL' } }); + expect(params?.searchParams).not.toHaveProperty('from'); + expect(params?.searchParams).not.toHaveProperty('to'); }); }); @@ -1403,109 +1125,61 @@ describe('MarketResource', () => { it('should accept 1min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '1min'); + await marketResource.getIntradayChart('AAPL', IntradayInterval.OneMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1min', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should accept 5min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '5min'); + await marketResource.getIntradayChart('AAPL', IntradayInterval.FiveMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/5min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/5min', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should accept 15min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '15min'); + await marketResource.getIntradayChart('AAPL', IntradayInterval.FifteenMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/15min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/15min', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should accept 30min interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '30min'); + await marketResource.getIntradayChart('AAPL', IntradayInterval.ThirtyMin); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/30min/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/30min', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should accept 1hour interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '1hour'); + await marketResource.getIntradayChart('AAPL', IntradayInterval.OneHour); - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/1hour/AAPL', - { searchParams: {} } - ); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/1hour', { + searchParams: { symbol: 'AAPL' }, + }); }); it('should accept 4hour interval', async () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); - await marketResource.getIntradayChart('AAPL', '4hour'); - - expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-chart/4hour/AAPL', - { searchParams: {} } - ); - }); - }); - - describe('Optional Parameters', () => { - it('should handle getForexPrice without pair parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue([]); - - await marketResource.getForexPrice(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/fx'); - }); - - it('should handle getCryptoPrice without symbol parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue([]); - - await marketResource.getCryptoPrice(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/crypto'); - }); - - it('should handle getForexQuoteShort without pair parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue([]); - - await marketResource.getForexQuoteShort(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/forex'); - }); - - it('should handle getCryptoQuoteShort without symbol parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue([]); - - await marketResource.getCryptoQuoteShort(); - - expect(mockClient.get).toHaveBeenCalledWith('v3/quotes/crypto'); - }); - - it('should handle getMarketHours without exchange parameter', async () => { - vi.mocked(mockClient.get).mockResolvedValue({} as MarketHours); - - await marketResource.getMarketHours(); + await marketResource.getIntradayChart('AAPL', IntradayInterval.FourHour); - expect(mockClient.get).toHaveBeenCalledWith('v3/is-the-market-open', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('historical-chart/4hour', { + searchParams: { symbol: 'AAPL' }, + }); }); }); }); diff --git a/tests/news.test.ts b/tests/news.test.ts index 7a10cc9..4d899fc 100644 --- a/tests/news.test.ts +++ b/tests/news.test.ts @@ -50,7 +50,7 @@ describe('NewsResource', () => { const result = await newsResource.getFMPArticles(); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 0, size: 50, @@ -65,7 +65,7 @@ describe('NewsResource', () => { const result = await newsResource.getFMPArticles(2); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 2, size: 50, @@ -80,7 +80,7 @@ describe('NewsResource', () => { const result = await newsResource.getFMPArticles(0, 100); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 0, size: 100, @@ -95,7 +95,7 @@ describe('NewsResource', () => { const result = await newsResource.getFMPArticles(5, 25); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 5, size: 25, @@ -139,7 +139,7 @@ describe('NewsResource', () => { const result = await newsResource.getGeneralNews(); - expect(mockClient.get).toHaveBeenCalledWith('v4/general_news', { + expect(mockClient.get).toHaveBeenCalledWith('general-news', { searchParams: { page: 0, }, @@ -153,7 +153,7 @@ describe('NewsResource', () => { const result = await newsResource.getGeneralNews(3); - expect(mockClient.get).toHaveBeenCalledWith('v4/general_news', { + expect(mockClient.get).toHaveBeenCalledWith('general-news', { searchParams: { page: 3, }, @@ -196,7 +196,7 @@ describe('NewsResource', () => { const result = await newsResource.getCryptoNews(); - expect(mockClient.get).toHaveBeenCalledWith('v4/crypto_news', { + expect(mockClient.get).toHaveBeenCalledWith('crypto-news', { searchParams: { page: 0, limit: 50, @@ -211,7 +211,7 @@ describe('NewsResource', () => { const result = await newsResource.getCryptoNews(2); - expect(mockClient.get).toHaveBeenCalledWith('v4/crypto_news', { + expect(mockClient.get).toHaveBeenCalledWith('crypto-news', { searchParams: { page: 2, limit: 50, @@ -226,7 +226,7 @@ describe('NewsResource', () => { const result = await newsResource.getCryptoNews(0, 100); - expect(mockClient.get).toHaveBeenCalledWith('v4/crypto_news', { + expect(mockClient.get).toHaveBeenCalledWith('crypto-news', { searchParams: { page: 0, limit: 100, @@ -270,7 +270,7 @@ describe('NewsResource', () => { const result = await newsResource.getForexNews(); - expect(mockClient.get).toHaveBeenCalledWith('v4/forex_news', { + expect(mockClient.get).toHaveBeenCalledWith('forex-news', { searchParams: { page: 0, limit: 50, @@ -285,7 +285,7 @@ describe('NewsResource', () => { const result = await newsResource.getForexNews(3); - expect(mockClient.get).toHaveBeenCalledWith('v4/forex_news', { + expect(mockClient.get).toHaveBeenCalledWith('forex-news', { searchParams: { page: 3, limit: 50, @@ -300,7 +300,7 @@ describe('NewsResource', () => { const result = await newsResource.getForexNews(0, 75); - expect(mockClient.get).toHaveBeenCalledWith('v4/forex_news', { + expect(mockClient.get).toHaveBeenCalledWith('forex-news', { searchParams: { page: 0, limit: 75, @@ -353,7 +353,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, }, @@ -367,7 +367,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, tickers: 'AAPL', @@ -382,7 +382,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews('AAPL,MSFT,GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, tickers: 'AAPL,MSFT,GOOGL', @@ -397,7 +397,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews(undefined, 100); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 100, }, @@ -411,7 +411,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews('TSLA,NVDA', 25); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 25, tickers: 'TSLA,NVDA', @@ -426,7 +426,7 @@ describe('NewsResource', () => { const result = await newsResource.getStockNews(''); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, }, @@ -472,12 +472,12 @@ describe('NewsResource', () => { const result = await newsResource.getPressReleases('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'AAPL', page: 0, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -486,12 +486,12 @@ describe('NewsResource', () => { const result = await newsResource.getPressReleases('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'AAPL', page: 0, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -500,12 +500,12 @@ describe('NewsResource', () => { const result = await newsResource.getPressReleases('MSFT', 3); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/MSFT', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'MSFT', page: 3, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -514,12 +514,12 @@ describe('NewsResource', () => { const result = await newsResource.getPressReleases('googl', 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/GOOGL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'GOOGL', page: 1, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -528,12 +528,12 @@ describe('NewsResource', () => { const result = await newsResource.getPressReleases('TsLa'); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/TSLA', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'TSLA', page: 0, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -568,12 +568,12 @@ describe('NewsResource', () => { const result = await newsResource.getLatestPressReleases('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'AAPL', limit: 50, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -582,12 +582,12 @@ describe('NewsResource', () => { const result = await newsResource.getLatestPressReleases('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'AAPL', limit: 50, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -596,12 +596,12 @@ describe('NewsResource', () => { const result = await newsResource.getLatestPressReleases('MSFT', 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/MSFT', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'MSFT', limit: 10, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -610,12 +610,12 @@ describe('NewsResource', () => { const result = await newsResource.getLatestPressReleases('GOOGL', 200); - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/GOOGL', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: 'GOOGL', limit: 200, - }, - } -); + }, + }); expect(result).toEqual(mockPressReleases); }); @@ -651,13 +651,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('AAPL', 2023, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'AAPL', year: 2023, - quarter: 4, - }, - } -); + quarter: 4, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -666,13 +666,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('aapl', 2023, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'AAPL', year: 2023, - quarter: 4, - }, - } -); + quarter: 4, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -681,13 +681,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('MSFT', 2024, 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/MSFT', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'MSFT', year: 2024, - quarter: 1, - }, - } -); + quarter: 1, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -696,13 +696,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('GOOGL', 2024, 2); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/GOOGL', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'GOOGL', year: 2024, - quarter: 2, - }, - } -); + quarter: 2, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -711,13 +711,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('AMZN', 2024, 3); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/AMZN', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'AMZN', year: 2024, - quarter: 3, - }, - } -); + quarter: 3, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -726,13 +726,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('TSLA', 2020, 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/TSLA', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'TSLA', year: 2020, - quarter: 1, - }, - } -); + quarter: 1, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -741,13 +741,13 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscript('NvDa', 2023, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/NVDA', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'NVDA', year: 2023, - quarter: 4, - }, - } -); + quarter: 4, + }, + }); expect(result).toEqual(mockTranscript); }); @@ -782,12 +782,11 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscriptDates('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning_call_transcript', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript-dates', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockDates); }); @@ -796,12 +795,11 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscriptDates('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning_call_transcript', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript-dates', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockDates); }); @@ -810,12 +808,11 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscriptDates('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning_call_transcript', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript-dates', { searchParams: { symbol: 'MSFT', - }, - } -); + }, + }); expect(result).toEqual(mockDates); }); @@ -824,12 +821,11 @@ describe('NewsResource', () => { const result = await newsResource.getEarningsTranscriptDates('GoOgL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/earning_call_transcript', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript-dates', { searchParams: { symbol: 'GOOGL', - }, - } -); + }, + }); expect(result).toEqual(mockDates); }); @@ -881,7 +877,9 @@ describe('NewsResource', () => { const result = await newsResource.getBatchEarningsTranscripts('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch_earning_call_transcript/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('batch-earning-call-transcript', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockBatchTranscripts); }); @@ -890,7 +888,9 @@ describe('NewsResource', () => { const result = await newsResource.getBatchEarningsTranscripts('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch_earning_call_transcript/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('batch-earning-call-transcript', { + searchParams: { symbol: 'AAPL' }, + }); expect(result).toEqual(mockBatchTranscripts); }); @@ -899,7 +899,9 @@ describe('NewsResource', () => { const result = await newsResource.getBatchEarningsTranscripts('msft'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch_earning_call_transcript/MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('batch-earning-call-transcript', { + searchParams: { symbol: 'MSFT' }, + }); expect(result).toEqual(mockBatchTranscripts); }); @@ -908,7 +910,9 @@ describe('NewsResource', () => { const result = await newsResource.getBatchEarningsTranscripts('TsLa'); - expect(mockClient.get).toHaveBeenCalledWith('v4/batch_earning_call_transcript/TSLA'); + expect(mockClient.get).toHaveBeenCalledWith('batch-earning-call-transcript', { + searchParams: { symbol: 'TSLA' }, + }); expect(result).toEqual(mockBatchTranscripts); }); @@ -938,12 +942,12 @@ describe('NewsResource', () => { await newsResource.getPressReleases(' AAPL '); // toUpperCase preserves spaces, so the endpoint will include them - expect(mockClient.get).toHaveBeenCalledWith('v3/press-releases/ AAPL ', { + expect(mockClient.get).toHaveBeenCalledWith('press-releases', { searchParams: { + symbol: ' AAPL ', page: 0, - }, - } -); + }, + }); }); it('should handle symbol with special characters', async () => { @@ -951,13 +955,13 @@ describe('NewsResource', () => { await newsResource.getEarningsTranscript('BRK.B', 2023, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/BRK.B', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'BRK.B', year: 2023, - quarter: 4, - }, - } -); + quarter: 4, + }, + }); }); }); @@ -967,7 +971,7 @@ describe('NewsResource', () => { await newsResource.getFMPArticles(0, 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 0, size: 50, @@ -981,7 +985,7 @@ describe('NewsResource', () => { await newsResource.getFMPArticles(9999, 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/fmp/articles', { + expect(mockClient.get).toHaveBeenCalledWith('fmp-articles', { searchParams: { page: 9999, size: 10, @@ -995,7 +999,7 @@ describe('NewsResource', () => { await newsResource.getStockNews('AAPL', 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 1, tickers: 'AAPL', @@ -1011,13 +1015,13 @@ describe('NewsResource', () => { await newsResource.getEarningsTranscript('AAPL', 2024, 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'AAPL', year: 2024, - quarter: 1, - }, - } -); + quarter: 1, + }, + }); }); it('should pass quarter 4 correctly', async () => { @@ -1025,13 +1029,13 @@ describe('NewsResource', () => { await newsResource.getEarningsTranscript('AAPL', 2024, 4); - expect(mockClient.get).toHaveBeenCalledWith('v3/earning_call_transcript/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('earning-call-transcript', { searchParams: { + symbol: 'AAPL', year: 2024, - quarter: 4, - }, - } -); + quarter: 4, + }, + }); }); }); @@ -1073,7 +1077,7 @@ describe('NewsResource', () => { await newsResource.getStockNews('AAPL,MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, tickers: 'AAPL,MSFT', @@ -1087,7 +1091,7 @@ describe('NewsResource', () => { await newsResource.getStockNews('AAPL,MSFT,GOOGL,AMZN,TSLA,NVDA,META,NFLX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, tickers: 'AAPL,MSFT,GOOGL,AMZN,TSLA,NVDA,META,NFLX', @@ -1101,7 +1105,7 @@ describe('NewsResource', () => { await newsResource.getStockNews('AAPL,MSFT,GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_news', { + expect(mockClient.get).toHaveBeenCalledWith('stock-news', { searchParams: { limit: 50, tickers: 'AAPL,MSFT,GOOGL', diff --git a/tests/performance.test.ts b/tests/performance.test.ts index 8bacd0a..43b6696 100644 --- a/tests/performance.test.ts +++ b/tests/performance.test.ts @@ -56,7 +56,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getGainers(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_market/gainers'); + expect(mockClient.get).toHaveBeenCalledWith('stock-market-gainers'); expect(mockClient.get).toHaveBeenCalledTimes(1); expect(result).toEqual(mockGainersData); expect(result).toHaveLength(3); @@ -118,7 +118,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getLosers(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_market/losers'); + expect(mockClient.get).toHaveBeenCalledWith('stock-market-losers'); expect(mockClient.get).toHaveBeenCalledTimes(1); expect(result).toEqual(mockLosersData); expect(result).toHaveLength(2); @@ -163,7 +163,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getMostActive(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock_market/actives'); + expect(mockClient.get).toHaveBeenCalledWith('stock-market-actives'); expect(mockClient.get).toHaveBeenCalledTimes(1); expect(result).toEqual(mockMostActiveData); expect(result).toHaveLength(2); @@ -211,7 +211,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPerformance(); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: {} }); expect(mockClient.get).toHaveBeenCalledTimes(1); expect(result).toEqual(mockSectorPerformanceData); expect(result).toHaveLength(4); @@ -223,7 +223,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPerformance(2); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: { limit: 2 }, } + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: { limit: 2 }, } ); expect(mockClient.get).toHaveBeenCalledTimes(1); expect(result).toHaveLength(2); @@ -235,7 +235,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPerformance(1); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: { limit: 1 }, } + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: { limit: 1 }, } ); expect(result).toHaveLength(1); expect(result[0].sector).toBe('Technology'); @@ -246,7 +246,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPerformance(100); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: { limit: 100 }, } + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: { limit: 100 }, } ); expect(result).toEqual(mockSectorPerformanceData); }); @@ -256,7 +256,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPerformance(undefined); - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: {} }); }); it('should return empty array when no sectors available', async () => { @@ -305,7 +305,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPerformance('Technology'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Technology', }, @@ -322,7 +322,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPerformance('Healthcare', 2); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Healthcare', limit: 2, @@ -340,7 +340,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPerformance(sector); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector, }, @@ -357,7 +357,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPerformance('Financial Services', 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Financial Services', limit: 5, @@ -372,7 +372,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPerformance('Technology', 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Technology', limit: 1, @@ -388,7 +388,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPerformance('Energy', 365); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Energy', limit: 365, @@ -403,7 +403,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPerformance('Technology', undefined); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Technology', }, @@ -462,7 +462,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPE('2024-01-15'); - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date: '2024-01-15', }, @@ -478,7 +478,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getSectorPE('2024-01-15', 'NYSE'); - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date: '2024-01-15', exchange: 'NYSE', @@ -496,7 +496,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPE('2024-01-15', exchange); - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date: '2024-01-15', exchange, @@ -514,7 +514,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPE(date); - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date, }, @@ -528,7 +528,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPE('2024-01-15', undefined); - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date: '2024-01-15', }, @@ -603,7 +603,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getIndustryPE('2024-01-15'); - expect(mockClient.get).toHaveBeenCalledWith('v4/industry_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('industry-price-earning-ratio', { searchParams: { date: '2024-01-15', }, @@ -617,7 +617,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getIndustryPE('2024-01-15', 'NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v4/industry_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('industry-price-earning-ratio', { searchParams: { date: '2024-01-15', exchange: 'NASDAQ', @@ -659,7 +659,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalSectorPE('Technology'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical-sector-pe', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-pe', { searchParams: { sector: 'Technology', }, @@ -674,7 +674,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPE('Financial Services'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical-sector-pe', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-pe', { searchParams: { sector: 'Financial Services', }, @@ -719,7 +719,7 @@ describe('PerformanceResource', () => { const result = await performanceResource.getHistoricalIndustryPE('Software'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical-industry-pe', { + expect(mockClient.get).toHaveBeenCalledWith('historical-industry-pe', { searchParams: { industry: 'Software', }, @@ -734,7 +734,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalIndustryPE('Semiconductors'); - expect(mockClient.get).toHaveBeenCalledWith('v4/historical-industry-pe', { + expect(mockClient.get).toHaveBeenCalledWith('historical-industry-pe', { searchParams: { industry: 'Semiconductors', }, @@ -809,7 +809,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPerformance(0); // Note: limit of 0 is falsy, so it should not be included - expect(mockClient.get).toHaveBeenCalledWith('v3/sector-performance', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sector-performance', { searchParams: {} }); }); it('should handle zero limit for getHistoricalSectorPerformance', async () => { @@ -818,7 +818,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPerformance('Technology', 0); // Note: limit of 0 is falsy, so it should not be included - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Technology', }, @@ -831,7 +831,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPerformance(''); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: '', }, @@ -845,7 +845,7 @@ describe('PerformanceResource', () => { await performanceResource.getSectorPE('2024-01-15', ''); // Note: empty string is falsy, so exchange parameter should not be included - expect(mockClient.get).toHaveBeenCalledWith('v4/sector_price_earning_ratio', { + expect(mockClient.get).toHaveBeenCalledWith('sector-price-earning-ratio', { searchParams: { date: '2024-01-15', }, @@ -858,7 +858,7 @@ describe('PerformanceResource', () => { await performanceResource.getHistoricalSectorPerformance('Real Estate & Construction'); - expect(mockClient.get).toHaveBeenCalledWith('v3/historical-sector-performance', { + expect(mockClient.get).toHaveBeenCalledWith('historical-sector-performance', { searchParams: { sector: 'Real Estate & Construction', }, diff --git a/tests/search.test.ts b/tests/search.test.ts index 3d3f67d..f24e688 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -47,7 +47,7 @@ describe('SearchResource', () => { const result = await searchResource.searchBySymbol('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-ticker', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'AAPL', limit: 10, @@ -62,7 +62,7 @@ describe('SearchResource', () => { await searchResource.searchBySymbol('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-ticker', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'AAPL', limit: 10, @@ -76,7 +76,7 @@ describe('SearchResource', () => { await searchResource.searchBySymbol('AAPL', 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-ticker', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'AAPL', limit: 20, @@ -90,7 +90,7 @@ describe('SearchResource', () => { await searchResource.searchBySymbol('AAPL', 10, 'NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-ticker', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'AAPL', limit: 10, @@ -105,7 +105,7 @@ describe('SearchResource', () => { await searchResource.searchBySymbol('AAPL', 10, 'nasdaq'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-ticker', { + expect(mockClient.get).toHaveBeenCalledWith('search-symbol', { searchParams: { query: 'AAPL', limit: 10, @@ -173,7 +173,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByName('Apple'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-name', { + expect(mockClient.get).toHaveBeenCalledWith('search-name', { searchParams: { query: 'Apple', limit: 10, @@ -188,7 +188,7 @@ describe('SearchResource', () => { await searchResource.searchByName('apple'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-name', { + expect(mockClient.get).toHaveBeenCalledWith('search-name', { searchParams: { query: 'apple', limit: 10, @@ -202,7 +202,7 @@ describe('SearchResource', () => { await searchResource.searchByName('Apple', 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-name', { + expect(mockClient.get).toHaveBeenCalledWith('search-name', { searchParams: { query: 'Apple', limit: 50, @@ -216,7 +216,7 @@ describe('SearchResource', () => { await searchResource.searchByName('Apple', 10, 'NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-name', { + expect(mockClient.get).toHaveBeenCalledWith('search-name', { searchParams: { query: 'Apple', limit: 10, @@ -231,7 +231,7 @@ describe('SearchResource', () => { await searchResource.searchByName('Apple', 10, 'nyse'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-name', { + expect(mockClient.get).toHaveBeenCalledWith('search-name', { searchParams: { query: 'Apple', limit: 10, @@ -288,7 +288,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByCIK('0000320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik/0000320193'); + expect(mockClient.get).toHaveBeenCalledWith('search-cik', { searchParams: { cik: '0000320193' } }); expect(result).toEqual(mockCIKResults); }); @@ -303,7 +303,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByCIK('320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik/320193'); + expect(mockClient.get).toHaveBeenCalledWith('search-cik', { searchParams: { cik: '320193' } }); expect(result).toEqual(results); }); @@ -332,7 +332,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByCUSIP('037833100'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cusip/037833100'); + expect(mockClient.get).toHaveBeenCalledWith('search-cusip', { searchParams: { cusip: '037833100' } }); expect(result).toEqual(mockCUSIPResults); }); @@ -341,7 +341,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByCUSIP('037833100'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cusip/037833100'); + expect(mockClient.get).toHaveBeenCalledWith('search-cusip', { searchParams: { cusip: '037833100' } }); expect(result).toHaveLength(1); expect(result[0].cusip).toBe('037833100'); }); @@ -371,7 +371,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByISIN('US0378331005'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-isin', { + expect(mockClient.get).toHaveBeenCalledWith('search-isin', { searchParams: { isin: 'US0378331005', }, @@ -395,7 +395,7 @@ describe('SearchResource', () => { const result = await searchResource.searchByISIN('CH0038863350'); - expect(mockClient.get).toHaveBeenCalledWith('v3/search-isin', { + expect(mockClient.get).toHaveBeenCalledWith('search-isin', { searchParams: { isin: 'CH0038863350', }, @@ -457,7 +457,7 @@ describe('SearchResource', () => { marketCapLowerThan: 5000000000000, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { marketCapMoreThan: 1000000000000, marketCapLowerThan: 5000000000000, @@ -475,7 +475,7 @@ describe('SearchResource', () => { priceLowerThan: 500, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { priceMoreThan: 100, priceLowerThan: 500, @@ -492,7 +492,7 @@ describe('SearchResource', () => { betaLowerThan: 1.0, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { betaMoreThan: 0.5, betaLowerThan: 1.0, @@ -509,7 +509,7 @@ describe('SearchResource', () => { volumeLowerThan: 100000000, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { volumeMoreThan: 10000000, volumeLowerThan: 100000000, @@ -526,7 +526,7 @@ describe('SearchResource', () => { dividendLowerThan: 5, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { dividendMoreThan: 1, dividendLowerThan: 5, @@ -542,7 +542,7 @@ describe('SearchResource', () => { sector: 'Technology', }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { sector: 'Technology', }, @@ -557,7 +557,7 @@ describe('SearchResource', () => { industry: 'Consumer Electronics', }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { industry: 'Consumer Electronics', }, @@ -572,7 +572,7 @@ describe('SearchResource', () => { country: 'US', }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { country: 'US', }, @@ -587,7 +587,7 @@ describe('SearchResource', () => { exchange: 'NASDAQ', }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { exchange: 'NASDAQ', }, @@ -602,7 +602,7 @@ describe('SearchResource', () => { exchange: 'nasdaq', }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { exchange: 'NASDAQ', }, @@ -636,7 +636,7 @@ describe('SearchResource', () => { isEtf: true, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { isEtf: true, }, @@ -651,7 +651,7 @@ describe('SearchResource', () => { isActivelyTrading: true, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { isActivelyTrading: true, }, @@ -667,7 +667,7 @@ describe('SearchResource', () => { limit: 100, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { sector: 'Technology', limit: 100, @@ -689,7 +689,7 @@ describe('SearchResource', () => { limit: 50, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { marketCapMoreThan: 100000000000, sector: 'Technology', @@ -708,7 +708,7 @@ describe('SearchResource', () => { await searchResource.screenStocks({}); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: {} }); }); it('should screen stocks with no parameters', async () => { @@ -716,7 +716,7 @@ describe('SearchResource', () => { await searchResource.screenStocks(); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: {} }); }); it('should not include undefined parameters', async () => { @@ -728,7 +728,7 @@ describe('SearchResource', () => { marketCapMoreThan: undefined, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { sector: 'Technology', }, @@ -744,7 +744,7 @@ describe('SearchResource', () => { volumeMoreThan: 0, }); - expect(mockClient.get).toHaveBeenCalledWith('v3/stock-screener', { + expect(mockClient.get).toHaveBeenCalledWith('company-screener', { searchParams: { priceMoreThan: 0, volumeMoreThan: 0, @@ -805,7 +805,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('NASDAQ'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/NASDAQ'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'NASDAQ' } }); expect(result).toEqual(mockNasdaqSymbols); }); @@ -814,7 +814,7 @@ describe('SearchResource', () => { await searchResource.getExchangeSymbols('nasdaq'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/NASDAQ'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'NASDAQ' } }); }); it('should get NYSE symbols', async () => { @@ -833,7 +833,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('NYSE'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/NYSE'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'NYSE' } }); expect(result).toEqual(nyseSymbols); }); @@ -861,7 +861,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('ETF'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/ETF'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'ETF' } }); expect(result).toEqual(etfSymbols); }); @@ -881,7 +881,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('AMEX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/AMEX'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'AMEX' } }); expect(result).toEqual(amexSymbols); }); @@ -901,7 +901,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('MUTUAL_FUND'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/MUTUAL_FUND'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'MUTUAL_FUND' } }); expect(result).toEqual(mutualFundSymbols); }); @@ -921,7 +921,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('COMMODITY'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/COMMODITY'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'COMMODITY' } }); expect(result).toEqual(commoditySymbols); }); @@ -941,7 +941,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('INDEX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/INDEX'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'INDEX' } }); expect(result).toEqual(indexSymbols); }); @@ -961,7 +961,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('CRYPTO'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/CRYPTO'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'CRYPTO' } }); expect(result).toEqual(cryptoSymbols); }); @@ -981,7 +981,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('FOREX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/FOREX'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'FOREX' } }); expect(result).toEqual(forexSymbols); }); @@ -1001,7 +1001,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('TSX'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/TSX'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'TSX' } }); expect(result).toEqual(tsxSymbols); }); @@ -1021,7 +1021,7 @@ describe('SearchResource', () => { const result = await searchResource.getExchangeSymbols('EURONEXT'); - expect(mockClient.get).toHaveBeenCalledWith('v3/symbol/EURONEXT'); + expect(mockClient.get).toHaveBeenCalledWith('exchange-symbols', { searchParams: { exchange: 'EURONEXT' } }); expect(result).toEqual(euronextSymbols); }); diff --git a/tests/sec.test.ts b/tests/sec.test.ts index d97ee7c..4e1c626 100644 --- a/tests/sec.test.ts +++ b/tests/sec.test.ts @@ -47,7 +47,7 @@ describe('SECResource', () => { const result = await secResource.getFilings('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'AAPL' } }); expect(result).toEqual(mockFilings); }); @@ -56,7 +56,7 @@ describe('SECResource', () => { await secResource.getFilings('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'AAPL' } }); }); it('should get filings with type filter', async () => { @@ -64,12 +64,12 @@ describe('SECResource', () => { const result = await secResource.getFilings('AAPL', '10-K'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + symbol: 'AAPL', type: '10-K', - }, - } -); + }, + }); expect(result).toEqual([mockFilings[0]]); }); @@ -78,12 +78,12 @@ describe('SECResource', () => { const result = await secResource.getFilings('AAPL', undefined, 1); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + symbol: 'AAPL', limit: 1, - }, - } -); + }, + }); expect(result).toHaveLength(1); }); @@ -92,13 +92,13 @@ describe('SECResource', () => { await secResource.getFilings('AAPL', '10-K', 5); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + symbol: 'AAPL', type: '10-K', - limit: 5, - }, - } -); + limit: 5, + }, + }); }); it('should handle various filing types', async () => { @@ -108,12 +108,12 @@ describe('SECResource', () => { vi.mocked(mockClient.get).mockResolvedValue([]); await secResource.getFilings('AAPL', type); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + symbol: 'AAPL', type, - }, - } -); + }, + }); } }); @@ -150,7 +150,7 @@ describe('SECResource', () => { const result = await secResource.getRSSFeed(); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: {} }); expect(result).toEqual(mockRSSFeed); }); @@ -159,12 +159,11 @@ describe('SECResource', () => { await secResource.getRSSFeed('8-K'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - }, - } -); + }, + }); }); it('should get RSS feed with date range', async () => { @@ -172,13 +171,12 @@ describe('SECResource', () => { await secResource.getRSSFeed(undefined, '2024-01-01', '2024-01-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { from: '2024-01-01', - to: '2024-01-31', - }, - } -); + to: '2024-01-31', + }, + }); }); it('should get RSS feed with all parameters', async () => { @@ -186,15 +184,14 @@ describe('SECResource', () => { await secResource.getRSSFeed('10-K', '2024-01-01', '2024-12-31', 100); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '10-K', - from: '2024-01-01', - to: '2024-12-31', - limit: 100, - }, - } -); + from: '2024-01-01', + to: '2024-12-31', + limit: 100, + }, + }); }); it('should handle date range with only from date', async () => { @@ -202,12 +199,11 @@ describe('SECResource', () => { await secResource.getRSSFeed(undefined, '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { from: '2024-01-01', - }, - } -); + }, + }); }); it('should handle date range with only to date', async () => { @@ -215,12 +211,11 @@ describe('SECResource', () => { await secResource.getRSSFeed(undefined, undefined, '2024-12-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { to: '2024-12-31', - }, - } -); + }, + }); }); }); @@ -248,12 +243,11 @@ describe('SECResource', () => { const result = await secResource.searchByFormType('10-K'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '10-K', - }, - } -); + }, + }); expect(result).toEqual(mockRSSFeed); }); @@ -262,14 +256,13 @@ describe('SECResource', () => { await secResource.searchByFormType('10-Q', '2024-01-01', '2024-03-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '10-Q', - from: '2024-01-01', - to: '2024-03-31', - }, - } -); + from: '2024-01-01', + to: '2024-03-31', + }, + }); }); it('should search by form type with limit', async () => { @@ -277,13 +270,12 @@ describe('SECResource', () => { await secResource.searchByFormType('8-K', undefined, undefined, 50); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - limit: 50, - }, - } -); + limit: 50, + }, + }); }); it('should handle various form types', async () => { @@ -293,12 +285,11 @@ describe('SECResource', () => { vi.mocked(mockClient.get).mockResolvedValue(mockRSSFeed); await secResource.searchByFormType(formType); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: formType, - }, - } -); + }, + }); } }); }); @@ -327,12 +318,11 @@ describe('SECResource', () => { const result = await secResource.get8KFilings(); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - }, - } -); + }, + }); expect(result).toEqual(mock8KFilings); }); @@ -341,14 +331,13 @@ describe('SECResource', () => { await secResource.get8KFilings('2024-01-01', '2024-01-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - from: '2024-01-01', - to: '2024-01-31', - }, - } -); + from: '2024-01-01', + to: '2024-01-31', + }, + }); }); it('should get 8-K filings with limit', async () => { @@ -356,13 +345,12 @@ describe('SECResource', () => { await secResource.get8KFilings(undefined, undefined, 25); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - limit: 25, - }, - } -); + limit: 25, + }, + }); }); it('should get 8-K filings with all parameters', async () => { @@ -370,15 +358,14 @@ describe('SECResource', () => { await secResource.get8KFilings('2024-01-01', '2024-12-31', 100); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '8-K', - from: '2024-01-01', - to: '2024-12-31', - limit: 100, - }, - } -); + from: '2024-01-01', + to: '2024-12-31', + limit: 100, + }, + }); }); }); @@ -400,7 +387,7 @@ describe('SECResource', () => { const result = await secResource.getFilingsByCIK('0000320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/0000320193', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { cik: '0000320193' } }); expect(result).toEqual(mockFilings); }); @@ -409,12 +396,12 @@ describe('SECResource', () => { await secResource.getFilingsByCIK('0000320193', '10-K'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/0000320193', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + cik: '0000320193', type: '10-K', - }, - } -); + }, + }); }); it('should get filings by CIK with limit', async () => { @@ -422,12 +409,12 @@ describe('SECResource', () => { await secResource.getFilingsByCIK('0000320193', undefined, 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/0000320193', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + cik: '0000320193', limit: 10, - }, - } -); + }, + }); }); it('should handle CIK without leading zeros', async () => { @@ -435,7 +422,7 @@ describe('SECResource', () => { await secResource.getFilingsByCIK('320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/320193', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { cik: '320193' } }); }); it('should handle CIK with all parameters', async () => { @@ -443,13 +430,13 @@ describe('SECResource', () => { await secResource.getFilingsByCIK('0000320193', '8-K', 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/0000320193', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + cik: '0000320193', type: '8-K', - limit: 50, - }, - } -); + limit: 50, + }, + }); }); }); @@ -471,12 +458,11 @@ describe('SECResource', () => { const result = await secResource.getFilingsByName('Apple Inc.'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'Apple Inc.', - }, - } -); + }, + }); expect(result).toEqual(mockFilings); }); @@ -485,13 +471,12 @@ describe('SECResource', () => { await secResource.getFilingsByName('Apple Inc.', '10-Q'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'Apple Inc.', - type: '10-Q', - }, - } -); + type: '10-Q', + }, + }); }); it('should get filings by name with limit', async () => { @@ -499,13 +484,12 @@ describe('SECResource', () => { await secResource.getFilingsByName('Apple Inc.', undefined, 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'Apple Inc.', - limit: 20, - }, - } -); + limit: 20, + }, + }); }); it('should handle company names with special characters', async () => { @@ -513,12 +497,11 @@ describe('SECResource', () => { await secResource.getFilingsByName('AT&T Inc.'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'AT&T Inc.', - }, - } -); + }, + }); }); it('should get filings by name with all parameters', async () => { @@ -526,14 +509,13 @@ describe('SECResource', () => { await secResource.getFilingsByName('Microsoft Corporation', '8-K', 30); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'Microsoft Corporation', - type: '8-K', - limit: 30, - }, - } -); + type: '8-K', + limit: 30, + }, + }); }); }); @@ -550,7 +532,7 @@ describe('SECResource', () => { const result = await secResource.searchCompanyBySymbol('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik-search/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('cik-search', { searchParams: { symbol: 'AAPL' } }); expect(result).toEqual(mockCIKSearch); }); @@ -559,7 +541,7 @@ describe('SECResource', () => { await secResource.searchCompanyBySymbol('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik-search/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('cik-search', { searchParams: { symbol: 'AAPL' } }); }); it('should handle mixed case symbols', async () => { @@ -567,7 +549,7 @@ describe('SECResource', () => { await secResource.searchCompanyBySymbol('MsFt'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik-search/MSFT'); + expect(mockClient.get).toHaveBeenCalledWith('cik-search', { searchParams: { symbol: 'MSFT' } }); }); it('should return empty array for invalid symbol', async () => { @@ -592,7 +574,7 @@ describe('SECResource', () => { const result = await secResource.searchCompanyByCIK('0000320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik/0000320193'); + expect(mockClient.get).toHaveBeenCalledWith('cik', { searchParams: { cik: '0000320193' } }); expect(result).toEqual(mockCIKSearch); }); @@ -601,7 +583,7 @@ describe('SECResource', () => { await secResource.searchCompanyByCIK('320193'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik/320193'); + expect(mockClient.get).toHaveBeenCalledWith('cik', { searchParams: { cik: '320193' } }); }); it('should handle long CIK numbers', async () => { @@ -609,7 +591,7 @@ describe('SECResource', () => { await secResource.searchCompanyByCIK('0001234567890'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik/0001234567890'); + expect(mockClient.get).toHaveBeenCalledWith('cik', { searchParams: { cik: '0001234567890' } }); }); it('should return empty array for invalid CIK', async () => { @@ -645,7 +627,7 @@ describe('SECResource', () => { const result = await secResource.getLatestFilings(); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed_8k', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('rss-feed-8k', { searchParams: {} }); expect(result).toEqual(mockLatestFilings); }); @@ -654,12 +636,11 @@ describe('SECResource', () => { await secResource.getLatestFilings(10); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed_8k', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed-8k', { searchParams: { limit: 10, - }, - } -); + }, + }); }); it('should handle various limit values', async () => { @@ -669,12 +650,11 @@ describe('SECResource', () => { vi.mocked(mockClient.get).mockResolvedValue(mockLatestFilings); await secResource.getLatestFilings(limit); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed_8k', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed-8k', { searchParams: { limit, - }, - } -); + }, + }); } }); }); @@ -703,9 +683,7 @@ describe('SECResource', () => { const result = await secResource.getAllSICCodes(); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification/all' - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification-all'); expect(result).toEqual(mockSICCodes); expect(result).toHaveLength(3); }); @@ -733,11 +711,9 @@ describe('SECResource', () => { const result = await secResource.getSICByCode('7370'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { sicCode: '7370' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { sicCode: '7370' }, + }); expect(result).toEqual(mockSICCode); }); @@ -746,11 +722,9 @@ describe('SECResource', () => { await secResource.getSICByCode('2834'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { sicCode: '2834' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { sicCode: '2834' }, + }); }); it('should handle 3-digit SIC codes', async () => { @@ -758,11 +732,9 @@ describe('SECResource', () => { await secResource.getSICByCode('367'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { sicCode: '367' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { sicCode: '367' }, + }); }); it('should return empty array for invalid SIC code', async () => { @@ -814,11 +786,9 @@ describe('SECResource', () => { const result = await secResource.searchSIC('Computer'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { industry: 'Computer' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { industry: 'Computer' }, + }); expect(result).toEqual(mockSICResults); }); @@ -827,11 +797,9 @@ describe('SECResource', () => { await secResource.searchSIC('computer'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { industry: 'computer' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { industry: 'computer' }, + }); }); it('should search with partial industry names', async () => { @@ -839,11 +807,9 @@ describe('SECResource', () => { await secResource.searchSIC('Programming'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { industry: 'Programming' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { industry: 'Programming' }, + }); }); it('should return empty array when no matches found', async () => { @@ -859,11 +825,9 @@ describe('SECResource', () => { await secResource.searchSIC('Services-Computer'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { industry: 'Services-Computer' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { industry: 'Services-Computer' }, + }); }); it('should handle industry names with spaces', async () => { @@ -877,11 +841,9 @@ describe('SECResource', () => { await secResource.searchSIC('Pharmaceutical Preparations'); - expect(mockClient.get).toHaveBeenCalledWith( - 'v4/standard_industrial_classification', - { searchParams: { industry: 'Pharmaceutical Preparations' }, } - - ); + expect(mockClient.get).toHaveBeenCalledWith('standard-industrial-classification', { + searchParams: { industry: 'Pharmaceutical Preparations' }, + }); }); }); @@ -1092,12 +1054,11 @@ describe('SECResource', () => { const result = await secResource.getFullProfile('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-outlook', { + expect(mockClient.get).toHaveBeenCalledWith('company-outlook', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); expect(result).toEqual(mockFullProfile); }); @@ -1106,12 +1067,11 @@ describe('SECResource', () => { await secResource.getFullProfile('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-outlook', { + expect(mockClient.get).toHaveBeenCalledWith('company-outlook', { searchParams: { symbol: 'AAPL', - }, - } -); + }, + }); }); it('should handle mixed case symbols', async () => { @@ -1119,12 +1079,11 @@ describe('SECResource', () => { await secResource.getFullProfile('MsFt'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-outlook', { + expect(mockClient.get).toHaveBeenCalledWith('company-outlook', { searchParams: { symbol: 'MSFT', - }, - } -); + }, + }); }); it('should return comprehensive profile data', async () => { @@ -1195,7 +1154,7 @@ describe('SECResource', () => { await secResource.getFilings(''); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: '' } }); }); it('should handle symbols with special characters', async () => { @@ -1203,7 +1162,7 @@ describe('SECResource', () => { await secResource.getFilings('BRK.B'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/BRK.B', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'BRK.B' } }); }); it('should handle very large limit values', async () => { @@ -1211,12 +1170,12 @@ describe('SECResource', () => { await secResource.getFilings('AAPL', undefined, 10000); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { + symbol: 'AAPL', limit: 10000, - }, - } -); + }, + }); }); it('should handle limit value of 0', async () => { @@ -1225,7 +1184,7 @@ describe('SECResource', () => { await secResource.getFilings('AAPL', undefined, 0); // Limit of 0 should not be included in params - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'AAPL' } }); }); it('should handle empty type string', async () => { @@ -1234,7 +1193,7 @@ describe('SECResource', () => { await secResource.getFilings('AAPL', ''); // Empty string is falsy, should not be included - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'AAPL' } }); }); it('should handle date ranges in wrong order', async () => { @@ -1243,13 +1202,12 @@ describe('SECResource', () => { // API should handle validation, we just pass the params await secResource.getRSSFeed(undefined, '2024-12-31', '2024-01-01'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { from: '2024-12-31', - to: '2024-01-01', - }, - } -); + to: '2024-01-01', + }, + }); }); it('should handle various date formats', async () => { @@ -1257,13 +1215,12 @@ describe('SECResource', () => { await secResource.getRSSFeed(undefined, '2024-01-01', '2024-01-31'); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { from: '2024-01-01', - to: '2024-01-31', - }, - } -); + to: '2024-01-31', + }, + }); }); }); @@ -1273,7 +1230,7 @@ describe('SECResource', () => { await secResource.getFilings('AAPL', undefined, undefined); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/AAPL', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'AAPL' } }); }); it('should handle mixed defined and undefined parameters', async () => { @@ -1281,13 +1238,12 @@ describe('SECResource', () => { await secResource.getRSSFeed('10-K', undefined, '2024-12-31', undefined); - expect(mockClient.get).toHaveBeenCalledWith('v4/rss_feed', { + expect(mockClient.get).toHaveBeenCalledWith('rss-feed', { searchParams: { type: '10-K', - to: '2024-12-31', - }, - } -); + to: '2024-12-31', + }, + }); }); it('should properly construct params with all options', async () => { @@ -1295,14 +1251,13 @@ describe('SECResource', () => { await secResource.getFilingsByName('Apple Inc.', '10-K', 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings', { + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { name: 'Apple Inc.', - type: '10-K', - limit: 50, - }, - } -); + type: '10-K', + limit: 50, + }, + }); }); }); @@ -1312,7 +1267,7 @@ describe('SECResource', () => { await secResource.getFilings('tsla'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/TSLA', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'TSLA' } }); }); it('should preserve already uppercase symbols', async () => { @@ -1320,7 +1275,7 @@ describe('SECResource', () => { await secResource.searchCompanyBySymbol('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/cik-search/GOOGL'); + expect(mockClient.get).toHaveBeenCalledWith('cik-search', { searchParams: { symbol: 'GOOGL' } }); }); it('should normalize mixed case symbols', async () => { @@ -1328,12 +1283,11 @@ describe('SECResource', () => { await secResource.getFullProfile('AmZn'); - expect(mockClient.get).toHaveBeenCalledWith('v4/company-outlook', { + expect(mockClient.get).toHaveBeenCalledWith('company-outlook', { searchParams: { symbol: 'AMZN', - }, - } -); + }, + }); }); it('should handle symbols with numbers', async () => { @@ -1341,7 +1295,7 @@ describe('SECResource', () => { await secResource.getFilings('BRK.B'); - expect(mockClient.get).toHaveBeenCalledWith('v3/sec_filings/BRK.B', { searchParams: {} }); + expect(mockClient.get).toHaveBeenCalledWith('sec-filings', { searchParams: { symbol: 'BRK.B' } }); }); }); }); diff --git a/tests/technical.test.ts b/tests/technical.test.ts index f3fec74..e0eff8d 100644 --- a/tests/technical.test.ts +++ b/tests/technical.test.ts @@ -44,13 +44,13 @@ describe('TechnicalResource', () => { const result = await technical.getSMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -60,8 +60,9 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { - searchParams: { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { + searchParams: { + symbol: 'AAPL', type: 'sma', period: 20, }, @@ -74,8 +75,9 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '1min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1min/AAPL', { - searchParams: { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1min', { + searchParams: { + symbol: 'AAPL', type: 'sma', period: 10, }, @@ -88,13 +90,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '5min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/5min/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/5min', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch SMA with 15min timeframe', async () => { @@ -103,13 +105,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '15min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/15min/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/15min', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch SMA with 30min timeframe', async () => { @@ -118,13 +120,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '30min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/30min/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/30min', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch SMA with 1hour timeframe', async () => { @@ -133,13 +135,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '1hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1hour/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1hour', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch SMA with 4hour timeframe', async () => { @@ -148,13 +150,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '4hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/4hour/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/4hour', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch SMA with 1day timeframe', async () => { @@ -163,13 +165,13 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, '1day'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -178,13 +180,13 @@ describe('TechnicalResource', () => { await technical.getSMA('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'sma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -213,13 +215,13 @@ describe('TechnicalResource', () => { const result = await technical.getEMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'ema', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -229,13 +231,13 @@ describe('TechnicalResource', () => { await technical.getEMA('AAPL', 50); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'ema', - period: 50, - }, - } -); + period: 50, + }, + }); }); it('should fetch EMA with different timeframes', async () => { @@ -244,13 +246,13 @@ describe('TechnicalResource', () => { await technical.getEMA('MSFT', 20, '1hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1hour/MSFT', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1hour', { searchParams: { + symbol: 'MSFT', type: 'ema', - period: 20, - }, - } -); + period: 20, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -259,13 +261,13 @@ describe('TechnicalResource', () => { await technical.getEMA('tsla'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/TSLA', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'TSLA', type: 'ema', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -294,13 +296,13 @@ describe('TechnicalResource', () => { const result = await technical.getRSI('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'rsi', - period: 14, - }, - } -); + period: 14, + }, + }); expect(result).toEqual(mockData); }); @@ -310,13 +312,13 @@ describe('TechnicalResource', () => { await technical.getRSI('AAPL', 21); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'rsi', - period: 21, - }, - } -); + period: 21, + }, + }); }); it('should fetch RSI with different timeframes', async () => { @@ -325,13 +327,13 @@ describe('TechnicalResource', () => { await technical.getRSI('GOOGL', 14, '15min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/15min/GOOGL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/15min', { searchParams: { + symbol: 'GOOGL', type: 'rsi', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -340,13 +342,13 @@ describe('TechnicalResource', () => { await technical.getRSI('nvda'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/NVDA', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'NVDA', type: 'rsi', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should handle client errors', async () => { @@ -375,13 +377,13 @@ describe('TechnicalResource', () => { const result = await technical.getADX('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'adx', - period: 14, - }, - } -); + period: 14, + }, + }); expect(result).toEqual(mockData); }); @@ -391,13 +393,13 @@ describe('TechnicalResource', () => { await technical.getADX('AAPL', 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'adx', - period: 20, - }, - } -); + period: 20, + }, + }); }); it('should fetch ADX with different timeframes', async () => { @@ -406,13 +408,13 @@ describe('TechnicalResource', () => { await technical.getADX('AMZN', 14, '30min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/30min/AMZN', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/30min', { searchParams: { + symbol: 'AMZN', type: 'adx', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -421,13 +423,13 @@ describe('TechnicalResource', () => { await technical.getADX('meta'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/META', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'META', type: 'adx', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should handle client errors', async () => { @@ -456,13 +458,13 @@ describe('TechnicalResource', () => { const result = await technical.getWilliams('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'williams', - period: 14, - }, - } -); + period: 14, + }, + }); expect(result).toEqual(mockData); }); @@ -472,13 +474,13 @@ describe('TechnicalResource', () => { await technical.getWilliams('AAPL', 10); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'williams', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should fetch Williams %R with different timeframes', async () => { @@ -487,13 +489,13 @@ describe('TechnicalResource', () => { await technical.getWilliams('NFLX', 14, '4hour'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/4hour/NFLX', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/4hour', { searchParams: { + symbol: 'NFLX', type: 'williams', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -502,13 +504,13 @@ describe('TechnicalResource', () => { await technical.getWilliams('dis'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/DIS', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'DIS', type: 'williams', - period: 14, - }, - } -); + period: 14, + }, + }); }); it('should handle client errors', async () => { @@ -537,13 +539,13 @@ describe('TechnicalResource', () => { const result = await technical.getStandardDeviation('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'standardDeviation', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -553,13 +555,13 @@ describe('TechnicalResource', () => { await technical.getStandardDeviation('AAPL', 20); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'standardDeviation', - period: 20, - }, - } -); + period: 20, + }, + }); }); it('should fetch Standard Deviation with different timeframes', async () => { @@ -568,13 +570,13 @@ describe('TechnicalResource', () => { await technical.getStandardDeviation('AMD', 10, '1min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1min/AMD', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1min', { searchParams: { + symbol: 'AMD', type: 'standardDeviation', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -583,13 +585,13 @@ describe('TechnicalResource', () => { await technical.getStandardDeviation('intc'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/INTC', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'INTC', type: 'standardDeviation', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -618,13 +620,13 @@ describe('TechnicalResource', () => { const result = await technical.getWMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'wma', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -634,13 +636,13 @@ describe('TechnicalResource', () => { await technical.getWMA('AAPL', 25); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'wma', - period: 25, - }, - } -); + period: 25, + }, + }); }); it('should fetch WMA with different timeframes', async () => { @@ -649,13 +651,13 @@ describe('TechnicalResource', () => { await technical.getWMA('IBM', 10, '5min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/5min/IBM', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/5min', { searchParams: { + symbol: 'IBM', type: 'wma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -664,13 +666,13 @@ describe('TechnicalResource', () => { await technical.getWMA('ba'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/BA', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'BA', type: 'wma', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -699,13 +701,13 @@ describe('TechnicalResource', () => { const result = await technical.getDEMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'dema', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -715,13 +717,13 @@ describe('TechnicalResource', () => { await technical.getDEMA('AAPL', 30); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'dema', - period: 30, - }, - } -); + period: 30, + }, + }); }); it('should fetch DEMA with different timeframes', async () => { @@ -730,13 +732,13 @@ describe('TechnicalResource', () => { await technical.getDEMA('JPM', 10, '15min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/15min/JPM', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/15min', { searchParams: { + symbol: 'JPM', type: 'dema', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -745,13 +747,13 @@ describe('TechnicalResource', () => { await technical.getDEMA('v'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/V', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'V', type: 'dema', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -780,13 +782,13 @@ describe('TechnicalResource', () => { const result = await technical.getTEMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'tema', - period: 10, - }, - } -); + period: 10, + }, + }); expect(result).toEqual(mockData); }); @@ -796,13 +798,13 @@ describe('TechnicalResource', () => { await technical.getTEMA('AAPL', 15); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'AAPL', type: 'tema', - period: 15, - }, - } -); + period: 15, + }, + }); }); it('should fetch TEMA with different timeframes', async () => { @@ -811,13 +813,13 @@ describe('TechnicalResource', () => { await technical.getTEMA('WMT', 10, '30min'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/30min/WMT', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/30min', { searchParams: { + symbol: 'WMT', type: 'tema', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should normalize symbol to uppercase', async () => { @@ -826,13 +828,13 @@ describe('TechnicalResource', () => { await technical.getTEMA('pg'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/PG', { + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', { searchParams: { + symbol: 'PG', type: 'tema', - period: 10, - }, - } -); + period: 10, + }, + }); }); it('should handle client errors', async () => { @@ -849,7 +851,9 @@ describe('TechnicalResource', () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); await technical.getSMA('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'AAPL' }) + })); }); it('should handle mixed case symbols', async () => { @@ -857,7 +861,9 @@ describe('TechnicalResource', () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); await technical.getSMA('AaPl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'AAPL' }) + })); }); it('should handle already uppercase symbols', async () => { @@ -865,7 +871,9 @@ describe('TechnicalResource', () => { vi.mocked(mockClient.get).mockResolvedValue(mockData); await technical.getSMA('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'AAPL' }) + })); }); }); @@ -876,7 +884,7 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 5); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 5 }) }) @@ -884,7 +892,7 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 50); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 50 }) }) @@ -892,7 +900,7 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 200); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 200 }) }) @@ -905,7 +913,7 @@ describe('TechnicalResource', () => { await technical.getRSI('AAPL', 9); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 9 }) }) @@ -913,7 +921,7 @@ describe('TechnicalResource', () => { await technical.getRSI('AAPL', 14); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 14 }) }) @@ -921,7 +929,7 @@ describe('TechnicalResource', () => { await technical.getRSI('AAPL', 25); expect(mockClient.get).toHaveBeenLastCalledWith( - 'v3/technical_indicator/1day/AAPL', + 'technical-indicator/1day', expect.objectContaining({ searchParams: expect.objectContaining({ period: 25 }) }) @@ -939,55 +947,55 @@ describe('TechnicalResource', () => { await technical.getSMA('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getEMA('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getRSI('AAPL', 14, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getADX('AAPL', 14, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getWilliams('AAPL', 14, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getStandardDeviation('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getWMA('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getDEMA('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); await technical.getTEMA('AAPL', 10, timeframe); expect(mockClient.get).toHaveBeenLastCalledWith( - `v3/technical_indicator/${timeframe}/AAPL`, + `technical-indicator/${timeframe}`, expect.any(Object) ); }); @@ -1127,9 +1135,15 @@ describe('TechnicalResource', () => { technical.getSMA('GoOgL'), ]); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', expect.any(Object)); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/MSFT', expect.any(Object)); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/GOOGL', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'AAPL' }) + })); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'MSFT' }) + })); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.objectContaining({ + searchParams: expect.objectContaining({ symbol: 'GOOGL' }) + })); }); it('should handle different timeframes for same symbol', async () => { @@ -1142,9 +1156,9 @@ describe('TechnicalResource', () => { technical.getSMA('AAPL', 10, '1day'), ]); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1min/AAPL', expect.any(Object)); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1hour/AAPL', expect.any(Object)); - expect(mockClient.get).toHaveBeenCalledWith('v3/technical_indicator/1day/AAPL', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1min', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1hour', expect.any(Object)); + expect(mockClient.get).toHaveBeenCalledWith('technical-indicator/1day', expect.any(Object)); }); }); }); diff --git a/tests/valuation.test.ts b/tests/valuation.test.ts index 06c9393..7e88bd6 100644 --- a/tests/valuation.test.ts +++ b/tests/valuation.test.ts @@ -32,7 +32,7 @@ describe('ValuationResource', () => { const result = await valuationResource.getDCF('AAPL'); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: 'AAPL' } }); expect(result).toEqual(mockDCFResponse); }); @@ -41,7 +41,7 @@ describe('ValuationResource', () => { await valuationResource.getDCF('aapl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: 'AAPL' } }); }); it('should handle mixed case symbols', async () => { @@ -49,7 +49,7 @@ describe('ValuationResource', () => { await valuationResource.getDCF('AaPl'); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/AAPL'); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: 'AAPL' } }); }); it('should handle symbols with special characters', async () => { @@ -65,7 +65,7 @@ describe('ValuationResource', () => { await valuationResource.getDCF('brk.b'); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/BRK.B'); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: 'BRK.B' } }); }); it('should return empty array for invalid symbol', async () => { @@ -112,7 +112,7 @@ describe('ValuationResource', () => { const result = await valuationResource.getDCF(''); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/'); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: '' } }); expect(result).toEqual([]); }); }); @@ -133,9 +133,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getLeveredDCF('MSFT'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: 'MSFT' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: 'MSFT' } } ); expect(result).toEqual(mockLeveredDCFResponse); }); @@ -146,9 +145,8 @@ describe('ValuationResource', () => { await valuationResource.getLeveredDCF('msft'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: 'MSFT' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: 'MSFT' } } ); }); @@ -158,9 +156,8 @@ describe('ValuationResource', () => { await valuationResource.getLeveredDCF('MsFt'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: 'MSFT' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: 'MSFT' } } ); }); @@ -178,9 +175,8 @@ describe('ValuationResource', () => { await valuationResource.getLeveredDCF('spy-l'); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: 'SPY-L' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: 'SPY-L' } } ); }); @@ -222,9 +218,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getLeveredDCF(''); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: '' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: '' } } ); expect(result).toEqual([]); }); @@ -235,9 +230,8 @@ describe('ValuationResource', () => { await valuationResource.getLeveredDCF(' msft '); expect(mockClient.get).toHaveBeenCalledWith( - 'v4/advanced_levered_discounted_cash_flow', - { searchParams: { symbol: ' MSFT ' }, } - + 'levered-discounted-cash-flow', + { searchParams: { symbol: ' MSFT ' } } ); }); }); @@ -274,12 +268,9 @@ describe('ValuationResource', () => { const result = await valuationResource.getAdvancedDCF('GOOGL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: 'GOOGL', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: 'GOOGL' } + }); expect(result).toEqual(mockAdvancedDCFResponse); }); @@ -288,12 +279,9 @@ describe('ValuationResource', () => { await valuationResource.getAdvancedDCF('googl'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: 'GOOGL', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: 'GOOGL' } + }); }); it('should handle mixed case symbols', async () => { @@ -301,12 +289,9 @@ describe('ValuationResource', () => { await valuationResource.getAdvancedDCF('GoOgL'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: 'GOOGL', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: 'GOOGL' } + }); }); it('should handle international symbols', async () => { @@ -339,12 +324,9 @@ describe('ValuationResource', () => { await valuationResource.getAdvancedDCF('0700.hk'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: '0700.HK', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: '0700.HK' } + }); }); it('should return empty array for invalid symbol', async () => { @@ -396,12 +378,9 @@ describe('ValuationResource', () => { const result = await valuationResource.getAdvancedDCF(''); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: '', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: '' } + }); expect(result).toEqual([]); }); @@ -445,8 +424,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDailyDCF('TSLA'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: {} } + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA' } } ); expect(result).toEqual(mockHistoricalDailyDCFResponse); }); @@ -457,9 +436,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDailyDCF('TSLA', 10); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: { limit: 10 }, } - + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA', limit: 10 } } ); expect(result).toEqual(mockHistoricalDailyDCFResponse); }); @@ -470,9 +448,8 @@ describe('ValuationResource', () => { await valuationResource.getHistoricalDailyDCF('tsla', 5); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: { limit: 5 }, } - + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA', limit: 5 } } ); }); @@ -482,9 +459,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDailyDCF('TSLA', 1); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: { limit: 1 }, } - + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA', limit: 1 } } ); expect(result).toHaveLength(1); }); @@ -495,9 +471,8 @@ describe('ValuationResource', () => { await valuationResource.getHistoricalDailyDCF('TSLA', 1000); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: { limit: 1000 }, } - + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA', limit: 1000 } } ); }); @@ -507,8 +482,8 @@ describe('ValuationResource', () => { await valuationResource.getHistoricalDailyDCF('TSLA', undefined); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-daily-discounted-cash-flow/TSLA', - { searchParams: {} } + 'historical-daily-discounted-cash-flow', + { searchParams: { symbol: 'TSLA' } } ); }); @@ -542,9 +517,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDCF('NVDA'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'annual' }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'annual' } } ); expect(result).toEqual(mockHistoricalDCFResponse); }); @@ -555,9 +529,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDCF('NVDA', 'quarter'); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'quarter' }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'quarter' } } ); expect(result).toEqual(mockHistoricalDCFResponse); }); @@ -568,9 +541,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDCF('NVDA', 'annual', 5); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'annual', limit: 5 }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'annual', limit: 5 } } ); expect(result).toEqual(mockHistoricalDCFResponse); }); @@ -581,9 +553,8 @@ describe('ValuationResource', () => { const result = await valuationResource.getHistoricalDCF('NVDA', 'quarter', 10); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'quarter', limit: 10 }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'quarter', limit: 10 } } ); expect(result).toEqual(mockHistoricalDCFResponse); }); @@ -594,9 +565,8 @@ describe('ValuationResource', () => { await valuationResource.getHistoricalDCF('nvda', 'quarter', 3); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'quarter', limit: 3 }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'quarter', limit: 3 } } ); }); @@ -606,9 +576,8 @@ describe('ValuationResource', () => { await valuationResource.getHistoricalDCF('NVDA', 'annual', undefined); expect(mockClient.get).toHaveBeenCalledWith( - 'v3/historical-discounted-cash-flow-statement/NVDA', - { searchParams: { period: 'annual' }, } - + 'historical-discounted-cash-flow-statement', + { searchParams: { symbol: 'NVDA', period: 'annual' } } ); }); @@ -653,7 +622,7 @@ describe('ValuationResource', () => { await valuationResource.getDCF('AAPL '); - expect(mockClient.get).toHaveBeenCalledWith('v3/discounted-cash-flow/AAPL '); + expect(mockClient.get).toHaveBeenCalledWith('discounted-cash-flow', { searchParams: { symbol: 'AAPL ' } }); }); it('should handle symbols with leading spaces in getLeveredDCF', async () => { @@ -661,12 +630,9 @@ describe('ValuationResource', () => { await valuationResource.getLeveredDCF(' MSFT'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_levered_discounted_cash_flow', { - searchParams: { - symbol: ' MSFT', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('levered-discounted-cash-flow', { + searchParams: { symbol: ' MSFT' } + }); }); it('should handle numeric symbols', async () => { @@ -674,12 +640,9 @@ describe('ValuationResource', () => { await valuationResource.getAdvancedDCF('0700'); - expect(mockClient.get).toHaveBeenCalledWith('v4/advanced_discounted_cash_flow', { - searchParams: { - symbol: '0700', - }, - } -); + expect(mockClient.get).toHaveBeenCalledWith('custom-discounted-cash-flow', { + searchParams: { symbol: '0700' } + }); }); it('should handle very long symbols', async () => { @@ -689,7 +652,8 @@ describe('ValuationResource', () => { await valuationResource.getDCF(longSymbol.toLowerCase()); expect(mockClient.get).toHaveBeenCalledWith( - `v3/discounted-cash-flow/${longSymbol.toUpperCase()}` + 'discounted-cash-flow', + { searchParams: { symbol: longSymbol.toUpperCase() } } ); }); });