### Getting Started Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Initialize the Finnhub client with your API key to begin making requests. The client uses a callback pattern for all API methods. ```javascript const finnhub = require('finnhub'); // Initialize the client with your API key const finnhubClient = new finnhub.DefaultApi("YOUR_API_KEY"); // Example: Get quote for AAPL finnhubClient.quote("AAPL", (error, data, response) => { if (error) { console.error("Error:", error); } else { console.log(data); // Output: { c: 178.72, d: 1.23, dp: 0.69, h: 179.50, l: 177.25, o: 177.90, pc: 177.49, t: 1699574400 } } }); ``` -------------------------------- ### Install finnhub-js using npm Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Install the finnhub-js package as a dependency for your project using npm. ```shell npm install finnhub --save ``` -------------------------------- ### Get Investment Themes Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches stocks grouped by investment themes. Requires a theme identifier. ```javascript finnhubClient.investmentThemes('financialExchangesData', (error, data, response) => { if (error) { console.error(error); return; } data.data.forEach(stock => { console.log(`${stock.symbol}: ${stock.companyName}`); }); }); ``` -------------------------------- ### Get Crypto Exchanges Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns a list of supported cryptocurrency exchanges. ```APIDOC ## Get Crypto Exchanges ### Description Returns a list of supported cryptocurrency exchanges. ### Method GET ### Endpoint /api/v1/crypto/exchanges ### Parameters No parameters required. ### Request Example ```javascript finnhubClient.cryptoExchanges((error, data, response) => { if (error) { console.error(error); return; } console.log("Supported exchanges:", data); }); ``` ### Response #### Success Response (200) - **exchanges** (array) - An array of supported cryptocurrency exchange names. #### Response Example ```json ["BINANCE", "COINBASE", "KRAKEN", "GEMINI", ...] ``` ``` -------------------------------- ### Get Support and Resistance Levels Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns calculated support and resistance price levels for a given symbol and resolution. ```APIDOC ## Get Support and Resistance Levels ### Description Returns calculated support and resistance price levels. ### Method GET ### Endpoint /api/v1/support-resistance ### Parameters #### Query Parameters - **symbol** (string) - Required - Stock symbol - **resolution** (string) - Required - Calendar interval (e.g., D for daily, W for weekly, M for monthly) ### Request Example ```javascript finnhubClient.supportResistance("AAPL", "D", (error, data, response) => { if (error) { console.error(error); return; } console.log("Support/Resistance levels:", data.levels); }); ``` ### Response #### Success Response (200) - **levels** (array) - An array of calculated support and resistance price levels. #### Response Example ```json { "levels": [145.50, 150.25, 155.00, 160.75, 165.30] } ``` ``` -------------------------------- ### Get Upgrade/Downgrade Information Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve analyst upgrade and downgrade data for a stock. Requires a symbol object. ```javascript finnhubClient.upgradeDowngrade({"symbol": "AAPL"}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Forex Exchanges Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get a list of supported forex exchanges. This endpoint does not require any parameters. ```javascript // Forex exchanges finnhubClient.forexExchanges((error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Upgrade/Downgrade Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns analyst upgrade and downgrade history for a given stock symbol. ```APIDOC ## Get Upgrade/Downgrade ### Description Returns analyst upgrade and downgrade history. ### Method GET ### Endpoint /api/v1/upgrade-downgrade ### Parameters #### Query Parameters - **symbol** (string) - Required - Stock symbol ### Request Example ```javascript finnhubClient.upgradeDowngrade({"symbol": "AAPL"}, (error, data, response) => { if (error) { console.error(error); return; } data.slice(0, 5).forEach(change => { console.log(`[${change.gradeDate}] ${change.company}: ${change.fromGrade} -> ${change.toGrade}`); }); }); ``` ### Response #### Success Response (200) - **gradeDate** (string) - The date of the upgrade or downgrade. - **company** (string) - The name of the company. - **fromGrade** (string) - The previous grade. - **toGrade** (string) - The new grade. - **action** (string) - The action taken (e.g., "upgrade", "downgrade"). #### Response Example ```json [ { "gradeDate": "2023-05-15", "company": "Apple Inc.", "fromGrade": "Hold", "toGrade": "Buy", "action": "upgrade" }, { "gradeDate": "2023-04-10", "company": "Apple Inc.", "fromGrade": "Buy", "toGrade": "Hold", "action": "downgrade" } ] ``` ``` -------------------------------- ### Get Forex Exchanges Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves a list of all supported forex exchanges and brokers. No input parameters are required. ```javascript finnhubClient.forexExchanges((error, data, response) => { if (error) { console.error(error); return; } console.log("Supported forex exchanges:", data); // Output: ["oanda", "fxcm", ...] }); ``` -------------------------------- ### Fetch Earnings Calendar Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get a calendar of upcoming earnings releases. Requires 'from' and 'to' dates. ```javascript // Earnings calendar finnhubClient.earningsCalendar({"from": "2020-06-01", "to": "2020-06-30"}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Investment Themes Data Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch data related to investment themes. Requires the theme name as input. ```javascript finnhubClient.investmentThemes('financialExchangesData', (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Fetch Crypto Exchanges Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get a list of supported cryptocurrency exchanges. This endpoint does not require any parameters. ```javascript // Crypto exchanges finnhubClient.cryptoExchanges((error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Crypto Profile Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch profile information for a cryptocurrency. Requires the crypto symbol (e.g., 'BTC'). ```javascript finnhubClient.cryptoProfile('BTC', (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Fetch IPO Calendar Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get a calendar of upcoming Initial Public Offerings (IPOs). Requires 'from' and 'to' dates. ```javascript // Ipo calendar finnhubClient.ipoCalendar("2020-01-01", "2020-06-15", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Economic Codes List Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches a list of available economic indicator codes and their names. Logs the first 10 codes. ```javascript finnhubClient.economicCode((error, data, response) => { if (error) { console.error(error); return; } data.forEach(code => { console.log(`${code.code}: ${code.name}`); }); }); ``` -------------------------------- ### Get Revenue Breakdown Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch revenue breakdown data for a stock. Requires a stock symbol object. ```javascript finnhubClient.revenueBreakdown({'symbol': 'AAPL'}, (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Fetch Quote Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get real-time quote data for a stock symbol. Requires a stock symbol. ```javascript //Quote finnhubClient.quote("AAPL", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Forex Rates Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get current forex rates. Requires a base currency. ```javascript // Forex rates finnhubClient.forexRates({"base": "USD"}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get List of Transcripts Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch a list of available transcripts for a given stock symbol. Requires the stock symbol. ```javascript finnhubClient.transcriptsList("AAPL", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get List of Supported Crypto Exchanges Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches a list of all cryptocurrency exchanges supported by the API. Logs the array of exchange names. ```javascript finnhubClient.cryptoExchanges((error, data, response) => { if (error) { console.error(error); return; } console.log("Supported exchanges:", data); // Output: ["BINANCE", "COINBASE", "KRAKEN", "GEMINI", ...] }); ``` -------------------------------- ### Fetch Revenue Estimates Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get revenue estimates for a company. Accepts an empty options object or specific filters. ```javascript // Revenue Estimates finnhubClient.companyRevenueEstimates("AAPL", {}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get EBITDA Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves analyst EBITDA estimates. Use 'annual' frequency for yearly estimates. ```javascript finnhubClient.companyEbitdaEstimates("AAPL", {"freq": "annual"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get ETF Profile Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve profile information for a specific ETF. Requires an ETF symbol object. ```javascript finnhubClient.etfsProfile({'symbol': 'SPY'}, (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get Supported Country List Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches a list of supported countries, including their codes and currency. Iterates and logs country details. ```javascript finnhubClient.country((error, data, response) => { if (error) { console.error(error); return; } data.forEach(country => { console.log(`${country.country} (${country.code2}): Currency ${country.currency}`); }); }); ``` -------------------------------- ### Fetch Recommendation Trends Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get analyst recommendation trends for a stock symbol. Requires a stock symbol. ```javascript // Recommendation trends finnhubClient.recommendationTrends("AAPL", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Company Profile by Symbol Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get general company profile information using its stock symbol. Requires a symbol object. ```javascript // Company profile finnhubClient.companyProfile({'symbol': 'AAPL'}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Forex Symbols Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches available currency pairs for a specified forex exchange. Requires the exchange name as input. ```javascript finnhubClient.forexSymbols("OANDA", (error, data, response) => { if (error) { console.error(error); return; } data.slice(0, 10).forEach(pair => { console.log(`${pair.displaySymbol}: ${pair.description}`); }); }); ``` -------------------------------- ### Get Company Profile by Symbol Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves company profile data using its stock symbol. Requires the Finnhub client to be initialized. ```javascript finnhubClient.companyProfile({'symbol': 'AAPL'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(`Company: ${data.name}`); console.log(`Industry: ${data.finnhubIndustry}`); console.log(`Market Cap: $${data.marketCapitalization}M`); console.log(`Website: ${data.weburl}`); }); ``` -------------------------------- ### Get Mutual Fund Profile Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches profile information for a mutual fund. Requires the mutual fund symbol. ```javascript finnhubClient.mutualFundProfile({'symbol': 'VTSAX'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(`Name: ${data.name}`); console.log(`Category: ${data.category}`); console.log(`AUM: $${data.aum}`); }); ``` -------------------------------- ### Get Gross Income Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves analyst gross income estimates. Specify 'quarterly' for quarterly frequency. ```javascript finnhubClient.companyGrossIncomeEstimates("AAPL", {"freq": "quarterly"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Sector Metrics Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves sector performance and valuation metrics for a specified sector. Logs the entire data object or handles errors. ```javascript finnhubClient.sectorMetric("NA", (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Pretax Income Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches analyst pretax income estimates. Use 'quarterly' frequency for quarterly data. ```javascript finnhubClient.companyPretaxIncomeEstimates("AAPL", {"freq": "quarterly"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Bond Yield Curve Data Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves yield curve data for a specified country. Includes error logging. ```javascript finnhubClient.bondYieldCurve("US", (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Bond Profile Information Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves profile details for a bond by its ISIN. Includes standard error handling. ```javascript finnhubClient.bondProfile({'isin': 'US912810TD00'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Transcripts List Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches a list of available earnings call transcripts for a specific company. Requires a company symbol. ```javascript finnhubClient.transcriptsList("AAPL", (error, data, response) => { if (error) { console.error(error); return; } data.transcripts.forEach(transcript => { console.log(`${transcript.id}: Q${transcript.quarter} ${transcript.year} - ${transcript.time}`); }); }); ``` -------------------------------- ### Get Revenue Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches analyst revenue estimates for future periods. Specify frequency (e.g., 'quarterly') for the desired granularity. ```javascript finnhubClient.companyRevenueEstimates("AAPL", {'freq': 'quarterly'}, (error, data, response) => { if (error) { console.error(error); return; } data.data.forEach(estimate => { console.log(`Period: ${estimate.period}`); console.log(` Revenue Avg: $${estimate.revenueAvg}M`); }); }); ``` -------------------------------- ### Get Index Constituents Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches the current constituents of a given stock index. Ensure the Finnhub client is initialized before use. ```javascript finnhubClient.indicesConstituents("^GSPC", (error, data, response) => { if (error) { console.error(error); return; } console.log(`Index: ${data.symbol}`); console.log(`Constituents count: ${data.constituents.length}`); console.log("First 10:", data.constituents.slice(0, 10)); }); ``` -------------------------------- ### Fetch Economic Data Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get specific economic data using its code. Requires an economic data code. ```javascript // Economic data finnhubClient.economicData("MA-USA-656880", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Company Executives Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves a list of company executives and their positions. The response includes compensation details for each executive. ```javascript finnhubClient.companyExecutive("AAPL", (error, data, response) => { if (error) { console.error(error); return; } data.executive.forEach(exec => { console.log(`${exec.name}: ${exec.position}`); console.log(` Compensation: $${exec.compensation}`); }); // Output: // Tim Cook: Chief Executive Officer // Compensation: $14769259 }); ``` -------------------------------- ### Initialize Finnhub API Client Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Instantiate the Finnhub API client with your API key. Replace '' with your actual key. ```javascript const finnhub = require('finnhub'); const finnhubClient = new finnhub.DefaultApi("") // Replace this ``` -------------------------------- ### Fetch Company News Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get news articles for a specific company within a date range. Requires symbol, start date, and end date. ```javascript //Company News finnhubClient.companyNews("AAPL", "2020-01-01", "2020-05-01", (error, data, response) => { if (error) { console.error(error); } else { console.log(data) } }); ``` -------------------------------- ### Get ETF Profile Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves comprehensive profile data for an Exchange Traded Fund (ETF). Requires the ETF symbol. ```javascript finnhubClient.etfsProfile({'symbol': 'SPY'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(`Name: ${data.profile.name}`); console.log(`AUM: $${data.profile.aum}`); console.log(`Expense Ratio: ${data.profile.expenseRatio}%`); console.log(`NAV: $${data.profile.nav}`); }); ``` -------------------------------- ### Initialize Finnhub Client and Get Quote Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Initialize the Finnhub client with your API key and make a request for real-time stock quote data. Requires the 'finnhub' module and an API key. ```javascript const finnhub = require('finnhub'); // Initialize the client with your API key const finnhubClient = new finnhub.DefaultApi("YOUR_API_KEY"); // All API methods use a callback pattern: (error, data, response) finnhubClient.quote("AAPL", (error, data, response) => { if (error) { console.error("Error:", error); } else { console.log(data); // Output: { c: 178.72, d: 1.23, dp: 0.69, h: 179.50, l: 177.25, o: 177.90, pc: 177.49, t: 1699574400 } } }); ``` -------------------------------- ### Get Institutional Portfolio Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves the portfolio holdings of an institutional investor by CIK number and date range. Requires CIK, start date, and end date. ```javascript finnhubClient.institutionalPortfolio("0001067983", "2022-01-01", "2023-01-01", (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Ownership Details Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches detailed ownership breakdown for a stock. The 'limit' parameter can be used to control the number of holders returned. ```javascript finnhubClient.ownership("AAPL", {'limit': 10}, (error, data, response) => { if (error) { console.error(error); return; } data.ownership.forEach(holder => { console.log(`${holder.name}: ${holder.share} shares`); }); }); ``` -------------------------------- ### Get Institutional Ownership Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches institutional ownership data for a stock within a specified date range. Requires symbol, start date, and end date. ```javascript finnhubClient.institutionalOwnership("AAPL", "", "2022-01-01", "2023-01-01", (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get DPS Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches analyst dividend per share (DPS) estimates. Use 'quarterly' for quarterly estimates. ```javascript finnhubClient.companyDpsEstimates("AAPL", {"freq": "quarterly"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Market Holidays Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches the market holiday calendar for a given exchange. Iterates through the holidays and logs the event name and date. ```javascript finnhubClient.marketHoliday("US", (error, data, response) => { if (error) { console.error(error); return; } data.data.forEach(holiday => { console.log(`${holiday.eventName}: ${holiday.atDate}`); }); }); ``` -------------------------------- ### Get Company Peers Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches a list of peer companies within the same industry sector. The 'grouping' parameter can be set to 'industry' or 'sector'. ```javascript finnhubClient.companyPeers("AAPL", {'grouping': 'industry'}, (error, data, response) => { if (error) { console.error(error); return; } console.log("Peer companies:", data); // Output: ["MSFT", "GOOGL", "META", "AMZN", "NVDA", ...] }); ``` -------------------------------- ### Get Support and Resistance Levels Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch support and resistance levels for a stock symbol. Requires symbol and a valid resolution (e.g., 'D' for daily). ```javascript finnhubClient.supportResistance("AAPL", "D", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Index Constituents Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns the current constituents of a stock index. ```APIDOC ## Get Index Constituents ### Description Returns the current constituents of a stock index. ### Method GET ### Endpoint /indices/constituents ### Parameters #### Query Parameters - **symbol** (string) - Required - The symbol of the stock index (e.g., "^GSPC"). ### Response #### Success Response (200) - **symbol** (string) - The symbol of the index. - **constituents** (array) - An array of strings, where each string is a constituent symbol. ### Response Example ```json { "symbol": "^GSPC", "constituents": [ "AAPL", "MSFT", "GOOGL", ... ] } ``` ``` -------------------------------- ### Get Crypto Candles Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves OHLCV (Open, High, Low, Close, Volume) candlestick data for cryptocurrency pairs. ```APIDOC ## Get Crypto Candles ### Description Retrieves OHLCV candlestick data for cryptocurrency pairs. ### Method GET ### Endpoint /api/v1/crypto/candle ### Parameters #### Query Parameters - **symbol** (string) - Required - Cryptocurrency symbol (e.g., "BINANCE:BTCUSDT") - **resolution** (string) - Required - Calendar interval (e.g., D for daily, W for weekly, M for monthly) - **from** (integer) - Required - Unix timestamp of the start date - **to** (integer) - Required - Unix timestamp of the end date ### Request Example ```javascript finnhubClient.cryptoCandles("BINANCE:BTCUSDT", "D", 1590988249, 1591852249, (error, data, response) => { if (error) { console.error(error); return; } console.log("Close prices:", data.c); console.log("Volumes:", data.v); console.log("Timestamps:", data.t); }); ``` ### Response #### Success Response (200) - **c** (array) - Array of closing prices. - **v** (array) - Array of volumes. - **t** (array) - Array of Unix timestamps for each candle. - **o** (array) - Array of opening prices. - **h** (array) - Array of high prices. - **l** (array) - Array of low prices. #### Response Example ```json { "c": [35000.50, 35500.75, 36000.00, ...], "v": [10000, 12000, 11000, ...], "t": [1590988249, 1591074649, 1591161049, ...], "o": [34900.00, 35400.25, 35900.50, ...], "h": [35200.00, 35700.50, 36200.00, ...], "l": [34800.00, 35300.00, 35800.00, ...] } ``` ``` -------------------------------- ### Get EPS Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves analyst EPS estimates for future quarters. Ensure the Finnhub client is initialized and the symbol is valid. ```javascript finnhubClient.companyEpsEstimates("AAPL", {'freq': 'quarterly'}, (error, data, response) => { if (error) { console.error(error); return; } data.data.forEach(estimate => { console.log(`Period: ${estimate.period}`); console.log(` EPS Avg Est: $${estimate.epsAvg}`); console.log(` EPS High: $${estimate.epsHigh}, Low: $${estimate.epsLow}`); }); }); ``` -------------------------------- ### Get Basic Financials (Margins) Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves key financial metrics, specifically margins, for a company. The 'metricType' parameter can be 'margin', 'growth', or 'valuation'. ```javascript finnhubClient.companyBasicFinancials("AAPL", "margin", (error, data, response) => { if (error) { console.error(error); return; } console.log("Metric:", data.metric); console.log(`Gross Margin: ${data.metric.grossMarginTTM}%`); console.log(`Operating Margin: ${data.metric.operatingMarginTTM}%`); console.log(`Net Profit Margin: ${data.metric.netProfitMarginTTM}%`); }); ``` -------------------------------- ### Get Index Historical Constituents Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns historical changes to index constituents. ```APIDOC ## Get Index Historical Constituents ### Description Returns historical changes to index constituents. ### Method GET ### Endpoint /indices/historical-constituents ### Parameters #### Query Parameters - **symbol** (string) - Required - The symbol of the stock index (e.g., "^GSPC"). ### Response #### Success Response (200) - **historicalConstituents** (array) - An array of objects, each representing a historical change. - **date** (string) - The date of the change. - **action** (string) - The action taken (e.g., "add", "remove"). - **symbol** (string) - The constituent symbol affected. ### Response Example ```json { "historicalConstituents": [ { "date": "2023-01-01", "action": "add", "symbol": "NVDA" }, { "date": "2023-01-05", "action": "remove", "symbol": "INTC" }, ... ] } ``` ``` -------------------------------- ### Get Net Income Estimates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves analyst net income estimates for future periods. Specify 'quarterly' for quarterly estimates. ```javascript finnhubClient.companyNetIncomeEstimates("AAPL", {"freq": "quarterly"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Crypto Symbols Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns available trading pairs for a specific cryptocurrency exchange. ```APIDOC ## Get Crypto Symbols ### Description Returns available trading pairs for a specific exchange. ### Method GET ### Endpoint /api/v1/crypto/symbols ### Parameters #### Query Parameters - **exchange** (string) - Required - The cryptocurrency exchange name (e.g., "BINANCE") ### Request Example ```javascript finnhubClient.cryptoSymbols("BINANCE", (error, data, response) => { if (error) { console.error(error); return; } data.slice(0, 10).forEach(symbol => { console.log(`${symbol.displaySymbol}: ${symbol.description}`); }); }); ``` ### Response #### Success Response (200) - **symbols** (array) - An array of trading symbols available on the exchange. - **symbol** (string) - The trading symbol (e.g., "BTC/USDT"). - **baseCurrency** (string) - The base currency of the trading pair. - **quoteCurrency** (string) - The quote currency of the trading pair. - **description** (string) - A description of the trading pair. - **displaySymbol** (string) - The display symbol for the trading pair. #### Response Example ```json [ { "symbol": "BTC/USDT", "baseCurrency": "BTC", "quoteCurrency": "USDT", "description": "Bitcoin / Tether", "displaySymbol": "BTC-USDT" }, { "symbol": "ETH/USDT", "baseCurrency": "ETH", "quoteCurrency": "USDT", "description": "Ethereum / Tether", "displaySymbol": "ETH-USDT" } ] ``` ``` -------------------------------- ### Fetch COVID-19 Data Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get global COVID-19 data. This endpoint does not require any parameters. ```javascript // Covid-19 finnhubClient.covid19((error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Price Metrics Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns various price-based metrics including beta, volatility, and 52-week range for a given stock symbol and date. ```APIDOC ## Get Price Metrics ### Description Returns various price-based metrics including beta, volatility, and 52-week range. ### Method GET ### Endpoint /api/v1/quote ### Parameters #### Query Parameters - **symbol** (string) - Required - Stock symbol - **date** (string) - Optional - Date in 'YYYY-MM-DD' format. Defaults to the current date if not provided. ### Request Example ```javascript finnhubClient.priceMetrics("AAPL", {'date': '2023-06-01'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` ### Response #### Success Response (200) - **beta** (float) - The beta value of the stock. - **volatility255** (float) - 255-day volatility. - **volatility52** (float) - 52-week volatility. - ** 52WeekRangeLow** (float) - The low end of the 52-week range. - ** 52WeekRangeHigh** (float) - The high end of the 52-week range. - ** 52WeekHighLowChange** (float) - Change from the 52-week high to the low. - ** 52WeekHighLowChangePercent** (float) - Percentage change from the 52-week high to the low. - ** 52WeekRange** (float) - The total 52-week range. #### Response Example ```json { "beta": 1.20, "volatility255": 0.25, "volatility52": 0.30, "52WeekRangeLow": 120.50, "52WeekRangeHigh": 180.00, "52WeekHighLowChange": 59.50, "52WeekHighLowChangePercent": 49.38, "52WeekRange": 59.50 } ``` ``` -------------------------------- ### Get Company Profile by ISIN Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves company profile data using its ISIN. Ensure the Finnhub client is properly configured. ```javascript finnhubClient.companyProfile({'isin': 'US0378331005'}, (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get ETF Allocation Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves the asset allocation breakdown for an ETF. Requires the ETF symbol. ```javascript finnhubClient.etfsAllocation({'symbol': 'SPY'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get IPO Calendar Data Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves upcoming and past Initial Public Offering (IPO) events within a specified date range. Logs IPO details. ```javascript finnhubClient.ipoCalendar("2020-01-01", "2020-06-15", (error, data, response) => { if (error) { console.error(error); return; } data.ipoCalendar.forEach(ipo => { console.log(`${ipo.name} (${ipo.symbol}): ${ipo.date}`); console.log(` Price Range: $${ipo.priceRangeLow} - $${ipo.priceRangeHigh}`); console.log(` Shares: ${ipo.numberOfShares}`); }); }); ``` -------------------------------- ### Get Pattern Recognition Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Identifies candlestick patterns in stock charts for a given symbol and resolution. ```APIDOC ## Get Pattern Recognition ### Description Identifies candlestick patterns in stock charts. ### Method GET ### Endpoint /api/v1/scan/pattern ### Parameters #### Query Parameters - **symbol** (string) - Required - Stock symbol - **resolution** (string) - Required - Calendar interval (e.g., D for daily, W for weekly, M for monthly) ### Request Example ```javascript finnhubClient.patternRecognition("AAPL", "D", (error, data, response) => { if (error) { console.error(error); return; } data.points.forEach(pattern => { console.log(`Pattern: ${pattern.patternname} (${pattern.patterntype})`); console.log(` Date: ${pattern.atime}, Price: $${pattern.aprice}`); }); }); ``` ### Response #### Success Response (200) - **points** (array) - An array of identified candlestick patterns. - **patternname** (string) - The name of the identified pattern. - **patterntype** (string) - The type of the pattern (e.g., "CDoubleBottom", "CDarkCloudCover"). - **atime** (integer) - Unix timestamp of the pattern occurrence. - **aprice** (float) - The price at the time of the pattern. #### Response Example ```json { "points": [ { "patternname": "CDoubleBottom", "patterntype": "CDoubleBottom", "atime": 1678886400, "aprice": 150.50 }, { "patternname": "CBullishEngulfing", "patterntype": "CBullishEngulfing", "atime": 1678799000, "aprice": 149.20 } ] } ``` ``` -------------------------------- ### Get Market Status Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves the current trading status (open/closed) for a specified exchange. Logs the exchange name, status, and current session. ```javascript finnhubClient.marketStatus("US", (error, data, response) => { if (error) { console.error(error); return; } console.log(`Exchange: ${data.exchange}`); console.log(`Is Open: ${data.isOpen}`); console.log(`Session: ${data.session}`); }); ``` -------------------------------- ### Get Support and Resistance Levels Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves calculated support and resistance price levels for a specified stock symbol and resolution. Logs the array of levels returned by the API. ```javascript finnhubClient.supportResistance("AAPL", "D", (error, data, response) => { if (error) { console.error(error); return; } console.log("Support/Resistance levels:", data.levels); // Output: [145.50, 150.25, 155.00, 160.75, 165.30] }); ``` -------------------------------- ### Get ETF Holdings Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch the holdings of a specific ETF. Requires an ETF symbol object. ```javascript finnhubClient.etfsHoldings({'symbol': 'ARKK'}, (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Fetch EBIT Estimates Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve EBIT (Earnings Before Interest and Taxes) estimates for a company. Can specify frequency (e.g., 'annual'). ```javascript // Ebit Estimates finnhubClient.companyEbitEstimates("AAPL", {"freq": "annual"}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Filings Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve SEC filings for a company. Requires a symbol object. ```javascript // Filings finnhubClient.filings({"symbol": "AAPL"}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Company Earnings Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get historical earnings data for a company. An optional limit can be specified. ```javascript // Company earnings finnhubClient.companyEarnings("AAPL", {'limit': 10}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Basic Financials API Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves key financial metrics including margins, growth rates, and valuation ratios. ```APIDOC ## Get Basic Financials ### Description Retrieves key financial metrics including margins, growth rates, and valuation ratios. ### Method GET ### Endpoint /api/v1/stock/metric ### Parameters #### Query Parameters - **symbol** (string) - Required - Company symbol (e.g., AAPL) - **metricType** (string) - Required - Type of metric (e.g., margin, growth, valuation) ### Response #### Success Response (200) - **metric** (object) - Object containing financial metrics - **grossMarginTTM** (number) - Trailing twelve months gross margin - **operatingMarginTTM** (number) - Trailing twelve months operating margin - **netProfitMarginTTM** (number) - Trailing twelve months net profit margin #### Response Example ```json { "metric": { "grossMarginTTM": 44.1, "operatingMarginTTM": 30.5, "netProfitMarginTTM": 25.2 } } ``` ``` -------------------------------- ### Get Stock Newsroom Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches news from a company's official newsroom within a specified date range. Requires the Finnhub client to be initialized. ```javascript finnhubClient.stockNewsroom("AAPL", "2023-01-01", "2023-12-31", (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Price Target Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Returns analyst price target consensus data for a given stock symbol. ```APIDOC ## Get Price Target ### Description Returns analyst price target consensus data. ### Method GET ### Endpoint /api/v1/price-target ### Parameters #### Query Parameters - **symbol** (string) - Required - Stock symbol ### Request Example ```javascript finnhubClient.priceTarget("AAPL", (error, data, response) => { if (error) { console.error(error); return; } console.log(`Target High: $${data.targetHigh}`); console.log(`Target Low: $${data.targetLow}`); console.log(`Target Mean: $${data.targetMean}`); console.log(`Target Median: $${data.targetMedian}`); }); ``` ### Response #### Success Response (200) - **targetHigh** (float) - The highest price target. - **targetLow** (float) - The lowest price target. - **targetMean** (float) - The average price target. - **targetMedian** (float) - The median price target. #### Response Example ```json { "targetHigh": 180.00, "targetLow": 140.00, "targetMean": 165.50, "targetMedian": 166.00 } ``` ``` -------------------------------- ### Fetch Basic Financials Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve basic financial statements (e.g., income statement, balance sheet, cash flow) for a company. Requires symbol and statement type. ```javascript // Basic financials finnhubClient.companyBasicFinancials("AAPL", "margin", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get Stock Price Metrics Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves various price-based metrics such as beta, volatility, and 52-week range for a stock symbol on a specific date. Logs the entire data object returned. ```javascript finnhubClient.priceMetrics("AAPL", {'date': '2023-06-01'}, (error, data, response) => { if (error) { console.error(error); return; } console.log(data); }); ``` -------------------------------- ### Get Insider Transactions Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve insider transaction data for a stock symbol. Requires the stock symbol. ```javascript finnhubClient.insiderTransactions('AAPL', (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get ETF Country Exposure Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch country exposure data for an ETF. Requires the ETF symbol. ```javascript finnhubClient.etfsCountryExposure('SPY', (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get ETF Sector Exposure Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve sector exposure data for an ETF. Requires the ETF symbol. ```javascript finnhubClient.etfsSectorExposure('SPY', (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get Historical Index Constituents Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Fetch historical constituents for a stock index. Requires the index symbol. ```javascript finnhubClient.indicesHistoricalConstituents("^GSPC", (error, data, response) => { console.log(data); }); ``` -------------------------------- ### Get Trading Pairs for a Crypto Exchange Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves available trading pairs for a specific cryptocurrency exchange. Logs the first 10 symbols, displaying their display symbol and description. ```javascript finnhubClient.cryptoSymbols("BINANCE", (error, data, response) => { if (error) { console.error(error); return; } data.slice(0, 10).forEach(symbol => { console.log(`${symbol.displaySymbol}: ${symbol.description}`); }); }); ``` -------------------------------- ### Fetch News Sentiment Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get news sentiment analysis for a stock symbol. Requires a stock symbol. ```javascript // News sentiment finnhubClient.newsSentiment("AAPL", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Press Releases Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Retrieve press releases for a company. Requires a symbol and an empty options object. ```javascript //Major development finnhubClient.pressReleases("AAPL", {}, (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Fetch Company Executive Information Source: https://github.com/finnhub-stock-api/finnhub-js/blob/master/README.md Get information about a company's executives. Requires a stock symbol. ```javascript // Company executive finnhubClient.companyExecutive("AAPL", (error, data, response) => { console.log(data) }); ``` -------------------------------- ### Get ESG Score Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches the Environmental, Social, and Governance (ESG) scores for a company. Requires a company symbol. ```javascript finnhubClient.companyEsgScore('AAPL', (error, data, response) => { if (error) { console.error(error); return; } console.log(`Total ESG Score: ${data.totalESGScore}`); console.log(`Environmental Score: ${data.environmentScore}`); console.log(`Social Score: ${data.socialScore}`); console.log(`Governance Score: ${data.governanceScore}`); }); ``` -------------------------------- ### Get SEC Filings Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches SEC filings for a company with optional filters for form type and date range. Ensure the Finnhub client is set up. ```javascript finnhubClient.filings({ "symbol": "AAPL", "form": "10-K", "from": "2020-01-01", "to": "2023-12-31" }, (error, data, response) => { if (error) { console.error(error); return; } data.forEach(filing => { console.log(`${filing.form}: ${filing.filedDate}`); console.log(` Access: ${filing.accessNumber}`); console.log(` URL: ${filing.reportUrl}`); }); }); ``` -------------------------------- ### Get Market News Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves general market news by category (general, forex, crypto, merger) with optional parameters. Ensure the Finnhub client is set up. ```javascript finnhubClient.marketNews("general", {'minId': 0}, (error, data, response) => { if (error) { console.error(error); return; } data.slice(0, 5).forEach(article => { console.log(`${article.headline}`); console.log(` Category: ${article.category}, Source: ${article.source}`); }); }); ``` -------------------------------- ### Get Forex Rates Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Fetches current exchange rates for all currency pairs against a specified base currency. Requires a base currency and optionally a date. ```javascript finnhubClient.forexRates({"base": "USD", "date": "2023-06-01"}, (error, data, response) => { if (error) { console.error(error); return; } console.log(`Base: ${data.base}`); console.log(`EUR: ${data.quote.EUR}`); console.log(`GBP: ${data.quote.GBP}`); console.log(`JPY: ${data.quote.JPY}`); }); ``` -------------------------------- ### Get Revenue Breakdown Source: https://context7.com/finnhub-stock-api/finnhub-js/llms.txt Retrieves revenue breakdown by segment or geography for a given symbol. Requires the company symbol. ```javascript finnhubClient.revenueBreakdown({'symbol': 'AAPL'}, (error, data, response) => { if (error) { console.error(error); return; } console.log("Revenue breakdown:", data); }); ```