### Get Economic Codes Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of available economic data codes. The example shows the first 5. ```python # Economic code print(finnhub_client.economic_code()[0:5]) ``` -------------------------------- ### Get Stock Symbols Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of stock symbols for a specified country. The example shows the first 5 for the US. ```python # Stock symbols print(finnhub_client.stock_symbols('US')[0:5]) ``` -------------------------------- ### Install and Initialize Finnhub Python Client Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Instructions for installing the library and initializing the client with an API key. Demonstrates basic, proxy-supported, and context-manager initialization, as well as runtime API key updates and error handling patterns. ```python # Install # pip install finnhub-python import finnhub from finnhub.exceptions import FinnhubAPIException, FinnhubRequestException # Basic initialization finnhub_client = finnhub.Client(api_key="YOUR_API_KEY") # With proxy support finnhub_client = finnhub.Client( api_key="YOUR_API_KEY", proxies={"https": "http://proxy.example.com:8080"} ) # As context manager (auto-closes session) with finnhub.Client(api_key="YOUR_API_KEY") as client: print(client.quote("AAPL")) # Update API key at runtime finnhub_client.api_key = "NEW_API_KEY" # Error handling pattern try: data = finnhub_client.quote("INVALID_SYMBOL") except FinnhubAPIException as e: print(f"API error {e.status_code}: {e.message}") except FinnhubRequestException as e: print(f"Request error: {e.message}") ``` -------------------------------- ### Install finnhub-python Package Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Use pip to install the finnhub-python library. This is the first step to using the API. ```sh pip install finnhub-python ``` -------------------------------- ### Initialize Finnhub Client and Get Stock Candles Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Setup the Finnhub client with your API key and retrieve historical stock price data. Requires a valid API key. ```python import finnhub # Setup client finnhub_client = finnhub.Client(api_key="YOUR API KEY") # Stock candles res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249) print(res) ``` ```python #Convert to Pandas Dataframe import pandas as pd print(pd.DataFrame(res)) ``` -------------------------------- ### Get Basic Financials Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch basic financial statements for a company. Use 'all' to get all available statements. ```python # Basic financials print(finnhub_client.company_basic_financials('AAPL', 'all')) ``` -------------------------------- ### Get Support/Resistance Levels Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch support and resistance levels for a stock symbol and resolution. ```python # Support resistance print(finnhub_client.support_resistance('AAPL', 'D')) ``` -------------------------------- ### Get Quote Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch real-time quote data for a stock symbol. ```python # Quote print(finnhub_client.quote('AAPL')) ``` -------------------------------- ### Get Forex Exchanges Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch a list of supported Forex exchanges. ```python # Forex exchanges print(finnhub_client.forex_exchanges()) ``` -------------------------------- ### Get Stock Investment Theme Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves investment theme data for a stock. Requires the theme name. ```python print(finnhub_client.stock_investment_theme('financialExchangesData')) ``` -------------------------------- ### Get Visa Application Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves visa application data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_visa_application("AAPL", "2021-01-01", "2022-06-15")) ``` -------------------------------- ### Get Crypto Exchanges Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch a list of supported cryptocurrency exchanges. ```python # Crypto Exchange print(finnhub_client.crypto_exchanges()) ``` -------------------------------- ### Get Revenue Estimates Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve revenue estimates for a company, with options for quarterly or annual frequency. ```python # Revenue Estimates print(finnhub_client.company_revenue_estimates('TSLA', freq='quarterly')) ``` -------------------------------- ### Client Initialization and Usage Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Demonstrates how to install the library, initialize the Finnhub client with an API key, handle proxies, use it as a context manager, update the API key at runtime, and implement error handling for API and request exceptions. ```APIDOC ## Installation and Client Setup Install the package and initialize the authenticated client. The client can also be used as a context manager to ensure the underlying HTTP session is properly closed. ```python # Install # pip install finnhub-python import finnhub from finnhub.exceptions import FinnhubAPIException, FinnhubRequestException # Basic initialization finnhub_client = finnhub.Client(api_key="YOUR_API_KEY") # With proxy support finnhub_client = finnhub.Client( api_key="YOUR_API_KEY", proxies={"https": "http://proxy.example.com:8080"} ) # As context manager (auto-closes session) with finnhub.Client(api_key="YOUR_API_KEY") as client: print(client.quote("AAPL")) # Update API key at runtime finnhub_client.api_key = "NEW_API_KEY" # Error handling pattern try: data = finnhub_client.quote("INVALID_SYMBOL") except FinnhubAPIException as e: print(f"API error {e.status_code}: {e.message}") except FinnhubRequestException as e: print(f"Request error: {e.message}") ``` ``` -------------------------------- ### Get Forex Rates Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve real-time Forex rates for a specified base currency. ```python # Forex all pairs print(finnhub_client.forex_rates(base='USD')) ``` -------------------------------- ### Get Financials Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch financial statements (balance sheet 'bs', income statement 'is', or cash flow 'cf') for a company on an annual or quarterly basis. ```python # Financials print(finnhub_client.financials('AAPL', 'bs', 'annual')) ``` -------------------------------- ### Get USPTO Patent Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves USPTO patent data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_uspto_patent("AAPL", "2021-01-01", "2021-12-31")) ``` -------------------------------- ### Get Pattern Recognition Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch pattern recognition data for a stock symbol and resolution. ```python # Pattern recognition print(finnhub_client.pattern_recognition('AAPL', 'D')) ``` -------------------------------- ### Get Forex Symbols Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of Forex symbols for a specific provider. ```python # Forex symbols print(finnhub_client.forex_symbols('OANDA')) ``` -------------------------------- ### Get 13-F Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves institutional profile, portfolio, or ownership data. Requires CIK and date range for portfolio/ownership. ```python print(finnhub_client.institutional_profile()) ``` ```python print(finnhub_client.institutional_portfolio(cik='1000097', _from='2022-01-01', to='2022-10-07')) ``` ```python print(finnhub_client.institutional_ownership('TSLA', '', _from='2022-01-01', to='2022-10-07')) ``` -------------------------------- ### Get Stock Basic Dividends Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve basic stock dividend information for a symbol. ```python # Stock dividends 2 print(finnhub_client.stock_basic_dividends("KO")) ``` -------------------------------- ### Retrieve Analyst Recommendations and Price Targets Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Get analyst buy/sell/hold recommendation trends and consensus price targets. Use date ranges for upgrade/downgrade history. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Recommendation trends recs = client.recommendation_trends("AAPL") print(recs) # [{'buy': 24, 'hold': 7, 'period': '2022-07-01', 'sell': 0, 'strongBuy': 11, 'strongSell': 0, 'symbol': 'AAPL'}] # Price target pt = client.price_target("AAPL") print(pt) # {'lastUpdated': '2020-07-20', 'symbol': 'AAPL', 'targetHigh': 220.0, # 'targetLow': 150.0, 'targetMean': 185.0, 'targetMedian': 185.0} # Upgrade/downgrade history print(client.upgrade_downgrade(symbol="AAPL", _from="2020-01-01", to="2020-06-30")) ``` -------------------------------- ### Get Price Metrics Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves price metrics for a stock symbol on a specific date. Requires symbol and date. ```python print(finnhub_client.price_metrics(symbol="AAPL", date="2022-01-01")) ``` -------------------------------- ### Get Crypto Profile Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves profile information for a cryptocurrency. Requires the crypto symbol. ```python print(finnhub_client.crypto_profile('BTC')) ``` -------------------------------- ### Get Upgrade/Downgrade Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch analyst upgrade and downgrade actions for a stock symbol within a date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # Upgrade downgrade print(finnhub_client.upgrade_downgrade(symbol='AAPL', _from='2020-01-01', to='2020-06-30')) ``` -------------------------------- ### Get EPS Estimates Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch Earnings Per Share (EPS) estimates for a company, with options for quarterly or annual frequency. ```python # EPS estimates print(finnhub_client.company_eps_estimates('AMZN', freq='quarterly')) ``` -------------------------------- ### Get Company Profile 2 Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch an alternative, more comprehensive company profile using the stock symbol. ```python # Company Profile 2 print(finnhub_client.company_profile2(symbol='AAPL')) ``` -------------------------------- ### Get IPO Calendar Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve upcoming Initial Public Offering (IPO) calendar data within a specified date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # IPO calendar print(finnhub_client.ipo_calendar(_from="2020-05-01", to="2020-06-01")) ``` -------------------------------- ### Get Economic Calendar Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch economic calendar data for a specified date range. ```python # Economic calendar print(finnhub_client.calendar_economic('2021-01-01', '2021-01-07')) ``` -------------------------------- ### Get Stock Revenue Breakdown Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves revenue breakdown for a stock symbol. Requires the stock symbol. ```python print(finnhub_client.stock_revenue_breakdown('AAPL')) ``` -------------------------------- ### Get Company Peers Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of peer companies for a given stock symbol. ```python # Company Peers print(finnhub_client.company_peers('AAPL')) ``` -------------------------------- ### Get International Filings Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves international filings for a given symbol or country. Can specify symbol or country. ```python print(finnhub_client.international_filings('RY.TO')) ``` ```python print(finnhub_client.international_filings(country='GB')) ``` -------------------------------- ### Get Filings Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of company filings within a specified date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # Filings print(finnhub_client.filings(symbol='AAPL', _from="2020-01-01", to="2020-06-11")) ``` -------------------------------- ### Get Press Releases Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch press releases for a company within a specified date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # Major developments print(finnhub_client.press_releases('AAPL', _from="2020-01-01", to="2020-12-31")) ``` -------------------------------- ### Get Recommendation Trends Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve analyst recommendation trends for a given stock symbol. ```python # Recommendation trends print(finnhub_client.recommendation_trends('AAPL')) ``` -------------------------------- ### Historical Market Cap, Stock Splits, Dividends Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Examples for retrieving historical market capitalization, stock splits, and dividend data for a given stock symbol. ```APIDOC ## Historical Market Cap ### Description Retrieves historical market capitalization data for a given stock symbol. ### Method `client.historical_market_cap(symbol, _from, to)` ### Parameters - **symbol** (string) - Required - The stock symbol (e.g., "AAPL"). - **_from** (string) - Required - The start date in 'YYYY-MM-DD' format. - **to** (string) - Required - The end date in 'YYYY-MM-DD' format. ## Stock Splits ### Description Retrieves stock split data for a given stock symbol within a specified date range. ### Method `client.stock_splits(symbol, _from, to)` ### Parameters - **symbol** (string) - Required - The stock symbol (e.g., "AAPL"). - **_from** (string) - Required - The start date in 'YYYY-MM-DD' format. - **to** (string) - Required - The end date in 'YYYY-MM-DD' format. ### Response Example ```json { "data": [ { "date": "2020-08-31", "fromFactor": 1, "symbol": "AAPL", "toFactor": 4 } ] } ``` ## Historical Dividends ### Description Retrieves historical dividend data for a given stock symbol within a specified date range. ### Method `client.stock_dividends(symbol, _from, to)` ### Parameters - **symbol** (string) - Required - The stock symbol (e.g., "KO"). - **_from** (string) - Required - The start date in 'YYYY-MM-DD' format. - **to** (string) - Required - The end date in 'YYYY-MM-DD' format. ### Response Example ```json { "amount": 0.4, "date": "2019-03-14", "symbol": "KO" } ``` ## Simplified Dividend Data (v2) ### Description Retrieves simplified dividend data for a given stock symbol. ### Method `client.stock_basic_dividends(symbol)` ### Parameters - **symbol** (string) - Required - The stock symbol (e.g., "KO"). ``` -------------------------------- ### Get Crypto Candles and Profile Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieve historical daily candles for a cryptocurrency pair and its profile information. Requires a valid API key. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Daily candles for BTC/USDT candles = client.crypto_candles("BINANCE:BTCUSDT", "D", 1590988249, 1591852249) print(candles) # {'c': [9650.0, 9800.0, ...], 's': 'ok', ...} # Crypto coin profile profile = client.crypto_profile("BTC") print(profile) # {'name': 'Bitcoin', 'description': '...', 'logo': '...', 'launchDate': '2009-01-03', ...} ``` -------------------------------- ### Get Transcripts List Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of available earnings call transcripts for a given stock symbol. ```python # Transcripts list print(finnhub_client.transcripts_list('AAPL')) ``` -------------------------------- ### Retrieve Calendar Data Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Get upcoming earnings reports, IPO listings, and economic event calendars. Specify date ranges and symbols as needed. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Earnings calendar earnings = client.earnings_calendar( _from="2020-06-10", to="2020-06-30", symbol="", international=False ) print(earnings["earningsCalendar"][0]) # {'date': '2020-06-11', 'epsActual': None, 'epsEstimate': 1.83, 'hour': 'bmo', # 'quarter': 2, 'revenueActual': None, 'revenueEstimate': 52900000000, 'symbol': 'AAPL', 'year': 2020} # Upcoming live earnings calls live_calls = client.earnings_call_live(_from="2023-01-01", to="2023-01-31", symbol="AAPL") # IPO calendar ipos = client.ipo_calendar(_from="2020-05-01", to="2020-06-01") print(ipos["ipoCalendar"][0]) # Economic calendar events eco = client.calendar_economic("2021-01-01", "2021-01-07") print(eco["economicCalendar"][0]) # Economic indicator data print(client.economic_code()[0:5]) # list available codes data = client.economic_data("MA-USA-656880") ``` -------------------------------- ### Get Forex Candles Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve historical Forex candlestick data for a specific currency pair and resolution. ```python # Forex candles print(finnhub_client.forex_candles('OANDA:EUR_USD', 'D', 1590988249, 1591852249)) ``` -------------------------------- ### Get Sector Metrics Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves sector metrics. Requires a sector name (e.g., 'NA' for North America). ```python print(finnhub_client.sector_metric('NA')) ``` -------------------------------- ### Get Financials Reported Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve reported financial statements for a company, specifying annual or quarterly frequency. ```python # Financials as reported print(finnhub_client.financials_reported(symbol='AAPL', freq='annual')) ``` -------------------------------- ### Get Market Holiday/Status Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves market holiday information or current market status for a specified exchange. Requires exchange code. ```python print(finnhub_client.market_holiday(exchange='US')) ``` ```python print(finnhub_client.market_status(exchange='US')) ``` -------------------------------- ### Get Mutual Fund Profile Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves profile information for a mutual fund. Can use fund symbol or ISIN. ```python print(finnhub_client.mutual_fund_profile("VTSAX")) ``` ```python print(finnhub_client.mutual_fund_profile(isin="US9229087286")) ``` -------------------------------- ### Get Crypto Candles Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve historical cryptocurrency candlestick data for a specific trading pair and resolution. ```python # Crypto Candles print(finnhub_client.crypto_candles('BINANCE:BTCUSDT', 'D', 1590988249, 1591852249)) ``` -------------------------------- ### Get Company Estimates Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves EBITDA or EBIT estimates for a company, specifying frequency. Requires company symbol and frequency. ```python print(finnhub_client.company_ebitda_estimates("TSLA", freq="quarterly")) ``` ```python print(finnhub_client.company_ebit_estimates("TSLA", freq="quarterly")) ``` -------------------------------- ### Get Bond Price Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves historical bond price data. Requires ISIN, start timestamp, and end timestamp. ```python print(finnhub_client.bond_price('US912810TD00', 1590988249, 1649099548)) ``` -------------------------------- ### Get Symbol & ISIN Change Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves changes in symbols or ISINs within a specified date range. Requires start and end dates. ```python print(finnhub_client.isin_change(_from='2022-10-01', to='2022-10-07')) ``` ```python print(finnhub_client.symbol_change(_from='2022-10-01', to='2022-10-07')) ``` -------------------------------- ### Get Earnings Calendar Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch earnings calendar data for a specified date range. Can filter by symbol and country. ```python # Earnings Calendar print(finnhub_client.earnings_calendar(_from="2020-06-10", to="2020-06-30", symbol="", international=False)) ``` -------------------------------- ### Get Lobbying Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves lobbying data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_lobbying("AAPL", "2021-01-01", "2022-06-15")) ``` -------------------------------- ### Get Fund Ownership Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch fund ownership data for a company. The limit parameter controls the number of results. ```python # Fund Ownership print(finnhub_client.fund_ownership('AMZN', limit=5)) ``` -------------------------------- ### Get SEC Similarity Index and International Filings Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Calculate the similarity index between annual SEC filings for a symbol. Fetch international filings by symbol or country. ```python sim = client.sec_similarity_index(symbol="AAPL", freq="annual") print(sim) ``` ```python print(client.international_filings("RY.TO")) ``` ```python print(client.international_filings(country="GB")) ``` -------------------------------- ### Get Fund's EET Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves EET data or EET PAI data for a mutual fund. Requires the fund's ISIN. ```python print(finnhub_client.mutual_fund_eet('LU2036931686')) ``` ```python print(finnhub_client.mutual_fund_eet_pai('LU2036931686')) ``` -------------------------------- ### Get Insider Sentiment Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves insider sentiment data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_insider_sentiment('AAPL', '2021-01-01', '2022-03-01')) ``` -------------------------------- ### Get Congressional Trading Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves congressional trading data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.congressional_trading('AAPL', '2020-01-01', '2023-03-31')) ``` -------------------------------- ### Fetch Company Basic Financials Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieves financial ratios and key metrics for a company. The `metric` parameter can be set to 'all' or specific metric groups. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") data = client.company_basic_financials("AAPL", "all") print(data["metric"]) # { ``` -------------------------------- ### Get Bank Branch Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves bank branch information for a given bank symbol. Requires the bank symbol. ```python print(finnhub_client.bank_branch("JPM")) ``` -------------------------------- ### Get Last Bid/Ask Price Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves the last bid and ask price for a stock symbol. Requires the stock symbol. ```python print(finnhub_client.last_bid_ask('AAPL')) ``` -------------------------------- ### Get USA Spending Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves USA spending data for a stock symbol within a date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_usa_spending("LMT", "2021-01-01", "2022-06-15")) ``` -------------------------------- ### Get ETFs Profile by Symbol or ISIN Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch profile information for an Exchange Traded Fund (ETF) using either its symbol or ISIN. ```python # ETFs Profile print(finnhub_client.etfs_profile('SPY')) print(finnhub_client.etfs_profile(isin="US78462F1030")) ``` -------------------------------- ### Get Mutual Fund Sector Exposure Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves sector exposure data for a mutual fund. Requires the fund symbol. ```python print(finnhub_client.mutual_fund_sector_exp("VTSAX")) ``` -------------------------------- ### Get Economic Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch economic data using a specific economic code. The format of the code is typically 'METRIC-COUNTRY-ID'. ```python # Economic data print(finnhub_client.economic_data('MA-USA-656880')) ``` -------------------------------- ### Get Company Profile by Symbol, ISIN, or CUSIP Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch detailed company profile information using either the stock symbol, ISIN, or CUSIP identifier. ```python # Company Profile print(finnhub_client.company_profile(symbol='AAPL')) print(finnhub_client.company_profile(isin='US0378331005')) print(finnhub_client.company_profile(cusip='037833100')) ``` -------------------------------- ### Get Company News Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch company-specific news articles within a date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # Company News # Need to use _from instead of from to avoid conflict print(finnhub_client.company_news('AAPL', _from="2020-06-01", to="2020-06-10")) ``` -------------------------------- ### Handle Finnhub API Exceptions Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Demonstrates how to catch and handle specific Finnhub API exceptions, such as invalid API keys or rate limits. Requires importing exception types. ```python import finnhub from finnhub.exceptions import FinnhubAPIException, FinnhubRequestException client = finnhub.Client(api_key="INVALID_KEY") try: data = client.quote("AAPL") except FinnhubAPIException as e: # e.status_code -> HTTP status (e.g., 401, 403, 429) # e.message -> error description from API # e.response -> raw requests.Response object print(f"API error {e.status_code}: {e.message}") if e.status_code == 429: print("Rate limit exceeded — consider throttling requests") elif e.status_code == 401: print("Invalid API key") except FinnhubRequestException as e: # Raised when the response body is not valid JSON or CSV print(f"Request error: {e.message}") ``` -------------------------------- ### Get Stock Insider Transactions Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves insider transaction data for a stock symbol within a specified date range. Requires symbol, start date, and end date. ```python print(finnhub_client.stock_insider_transactions('AAPL', '2021-01-01', '2021-03-01')) ``` -------------------------------- ### Retrieve Ownership Data Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Get institutional investor ownership, fund ownership, and 13-F institutional portfolio data for a given symbol. Institutional profile can be fetched without a symbol. ```python ownership = client.ownership("AAPL", limit=5) print(ownership["ownership"][0]) ``` ```python fund_own = client.fund_ownership("AMZN", limit=5) ``` ```python profile = client.institutional_profile() ``` ```python portfolio = client.institutional_portfolio(cik="1000097", _from="2022-01-01", to="2022-10-07") ``` ```python inst_own = client.institutional_ownership("TSLA", "", _from="2022-01-01", to="2022-10-07") print(portfolio["holdings"][0]) ``` -------------------------------- ### Get Stock Tick Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch tick data for a stock on a specific date. Parameters include symbol, date, and limit. ```python # Tick Data print(finnhub_client.stock_tick('AAPL', '2020-03-25', 500, 0)) ``` -------------------------------- ### Company Basic Financials Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Fetches financial ratios and key metrics for a company. The `metric` parameter can be set to 'all' or specific metric groups. ```APIDOC ## Company Basic Financials Retrieve financial ratios and key metrics for a company. The `metric` parameter accepts `"all"` or specific metric groups. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") data = client.company_basic_financials("AAPL", "all") print(data["metric"]) # { ``` -------------------------------- ### Get Covid-19 Data Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve global COVID-19 data. ```python # Covid-19 print(finnhub_client.covid19()) ``` -------------------------------- ### Access Earnings and Estimates Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieve earnings surprises, EPS, revenue, EBITDA, EBIT, net income, and DPS estimates. Use the 'limit' parameter for earnings surprises and 'freq' for estimates. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Earnings surprises (last 5 quarters) print(client.company_earnings("TSLA", limit=5)) # [{'actual': 2.27, 'estimate': 1.87, 'period': '2022-03-31', 'symbol': 'TSLA', 'surprise': 0.4, ...}] # Quarterly EPS estimates print(client.company_eps_estimates("AMZN", freq="quarterly")) # Revenue estimates print(client.company_revenue_estimates("TSLA", freq="quarterly")) # EBITDA estimates print(client.company_ebitda_estimates("TSLA", freq="quarterly")) # EBIT estimates print(client.company_ebit_estimates("TSLA", freq="quarterly")) # Net income estimates print(client.company_net_income_estimates("AAPL", freq="annual")) # DPS (dividend per share) estimates print(client.company_dps_estimates("AAPL", freq="annual")) # Earnings quality score print(client.company_earnings_quality_score("AAPL", "quarterly")) ``` -------------------------------- ### Get Stock Splits Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch historical stock split data for a symbol within a date range. Note: use '_from' to avoid conflict with Python's 'from' keyword. ```python # Stock splits print(finnhub_client.stock_splits('AAPL', _from='2000-01-01', to='2020-01-01')) ``` -------------------------------- ### Get FDA Calendar Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves FDA calendar events. No parameters are required. ```python print(finnhub_client.fda_calendar()) ``` -------------------------------- ### Upgrade Downgrade Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves stock upgrade and downgrade data. ```APIDOC ## upgrade_downgrade ### Description Retrieves stock upgrade and downgrade data. ### Method `finnhub_client.upgrade_downgrade(symbol, _from, to)` ### Parameters #### Path Parameters - **symbol** (string) - Required - Stock symbol (e.g., 'AAPL'). - **_from** (string) - Required - Start date in 'YYYY-MM-DD' format. - **to** (string) - Required - End date in 'YYYY-MM-DD' format. ### Request Example ```python print(finnhub_client.upgrade_downgrade(symbol='AAPL', _from='2020-01-01', to='2020-06-30')) ``` ``` -------------------------------- ### Get Crypto Symbols Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of cryptocurrency symbols for a specific exchange. ```python # Crypto symbols print(finnhub_client.crypto_symbols('BINANCE')) ``` -------------------------------- ### Get Index Constituents Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve the current constituents of a specified stock market index. ```python # Indices Constituents print(finnhub_client.indices_const(symbol = "^GSPC")) ``` -------------------------------- ### Retrieve Price Metrics, Splits, and Dividends Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Fetch point-in-time price metrics, historical stock splits, and dividend history for a given symbol. An API key is required. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Price metrics (valuation, growth, margins — point-in-time) metrics = client.price_metrics(symbol="AAPL", date="2022-01-01") print(metrics["metric"]) ``` -------------------------------- ### Get Price Target Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve analyst price targets for a given stock symbol. ```python # Price target print(finnhub_client.price_target('AAPL')) ``` -------------------------------- ### Retrieve SEC Filings Metadata Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Access SEC filing metadata. This snippet shows the initialization of the Finnhub client. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") ``` -------------------------------- ### Real-Time Quote Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Fetches the latest bid, ask, last price, open, high, low, and previous close for a given stock symbol. Also shows how to retrieve the last bid/ask price. ```APIDOC ## Real-Time Quote Fetch the latest bid, ask, last price, open, high, low, and previous close for a stock symbol. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") quote = client.quote("AAPL") print(quote) # { # 'c': 150.25, # current price # 'h': 151.00, # high # 'l': 149.50, # low # 'o': 150.00, # open # 'pc': 149.80, # previous close # 't': 1625000000 # } # Last bid/ask bid_ask = client.last_bid_ask("AAPL") print(bid_ask) # {'a': 150.30, 'b': 150.20, 'asize': 200, 'bsize': 300, 't': 1625000001} ``` ``` -------------------------------- ### Get News Sentiment Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve news sentiment analysis for a given stock symbol. ```python # News sentiment print(finnhub_client.news_sentiment('AAPL')) ``` -------------------------------- ### Get Company Executives Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of company executives for a given stock symbol. ```python # Company Executives print(finnhub_client.company_executive('AAPL')) ``` -------------------------------- ### Fetch Real-Time Stock Quote Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieves the latest bid, ask, last price, open, high, low, and previous close for a given stock symbol. Also shows how to fetch the last bid/ask price and size. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") quote = client.quote("AAPL") print(quote) # { # 'c': 150.25, # current price # 'h': 151.00, # high # 'l': 149.50, # low # 'o': 150.00, # open # 'pc': 149.80, # previous close # 't': 1625000000 # } # Last bid/ask bid_ask = client.last_bid_ask("AAPL") print(bid_ask) # {'a': 150.30, 'b': 150.20, 'asize': 200, 'bsize': 300, 't': 1625000001} ``` -------------------------------- ### Get Bond Profile Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves profile information for a bond. Requires the bond's ISIN. ```python print(finnhub_client.bond_profile(isin='US912810TD00')) ``` -------------------------------- ### Check Market Status, Holidays, and Symbol Lookup Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Query current market status, retrieve trading holidays for an exchange, and search for stock symbols. Requires an API key. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # Current market status status = client.market_status(exchange="US") print(status) # {'exchange': 'US', 'holiday': None, 'isOpen': True, 'session': 'regular', 't': 1625000000} # Market holidays holidays = client.market_holiday(exchange="US") print(holidays["data"][0]) # {'atDate': '2023-01-02', 'eventName': "New Year's Day"} # Symbol lookup / search results = client.symbol_lookup("apple") print(results["result"][0]) # {'description': 'APPLE INC', 'displaySymbol': 'AAPL', 'symbol': 'AAPL', 'type': 'Common Stock'} # All stock symbols on an exchange symbols = client.stock_symbols("US")[0:3] print(symbols) # Symbol and ISIN change notifications print(client.symbol_change(_from="2022-10-01", to="2022-10-07")) print(client.isin_change(_from="2022-10-01", to="2022-10-07")) ``` -------------------------------- ### Get Company ESG Score Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves the ESG score for a company. Requires the company symbol. ```python print(finnhub_client.company_esg_score("AAPL")) ``` -------------------------------- ### Bid Ask Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves the last bid and ask prices for a given symbol. ```APIDOC ## Bid Ask ### Description Retrieves the last bid and ask prices for a given symbol. ### Method `last_bid_ask(symbol: str)` ### Parameters #### Path Parameters - **symbol** (str) - Required - The stock symbol. ### Request Example ```python print(finnhub_client.last_bid_ask('AAPL')) ``` ``` -------------------------------- ### Retrieve Stock Splits Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Fetches stock split data for a symbol within a date range. The output includes date, symbol, and split factors. Requires a Finnhub client instance. ```python splits = client.stock_splits("AAPL", _from="2000-01-01", to="2020-01-01") print(splits) ``` -------------------------------- ### Retrieve Forex Data Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Access lists of available forex exchanges, symbols for a specific exchange, daily OHLCV candles for a currency pair, and live exchange rates relative to a base currency. ```python print(client.forex_exchanges()) ``` ```python symbols = client.forex_symbols("OANDA") print(symbols[0]) ``` ```python candles = client.forex_candles("OANDA:EUR_USD", "D", 1590988249, 1591852249) print(candles) ``` ```python rates = client.forex_rates(base="USD") print(rates["quote"]["EUR"]) ``` -------------------------------- ### Basic Financials Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves basic financial data for a company. ```APIDOC ## company_basic_financials ### Description Retrieves basic financial data for a company. ### Method `finnhub_client.company_basic_financials(symbol, _type)` ### Parameters #### Path Parameters - **symbol** (string) - Required - Stock symbol (e.g., 'AAPL'). - **_type** (string) - Required - Type of financial data (e.g., 'all', 'bs' for balance sheet, 'pl' for profit and loss, 'cf' for cash flow). ### Request Example ```python print(finnhub_client.company_basic_financials('AAPL', 'all')) ``` ``` -------------------------------- ### Retrieve Simplified Dividend Data Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Fetches simplified dividend data for a stock symbol. This is a v2 endpoint. Requires a Finnhub client instance. ```python print(client.stock_basic_dividends("KO")) ``` -------------------------------- ### List Available Earnings Transcripts Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieves a list of available earnings call transcripts for a given stock symbol. Requires a Finnhub client instance and an API key. ```python import finnhub client = finnhub.Client(api_key="YOUR_API_KEY") # List available transcripts for a symbol transcript_list = client.transcripts_list("AAPL") print(transcript_list["transcripts"][0]) ``` -------------------------------- ### Get Aggregate Indicators Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve aggregated technical indicator data for a given stock symbol and resolution. ```python # Aggregate Indicators print(finnhub_client.aggregate_indicator('AAPL', 'D')) ``` -------------------------------- ### IPO Calendar Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves upcoming Initial Public Offering (IPO) calendar data. ```APIDOC ## ipo_calendar ### Description Retrieves upcoming Initial Public Offering (IPO) calendar data. ### Method `finnhub_client.ipo_calendar(_from, to)` ### Parameters #### Path Parameters - **_from** (string) - Required - Start date in 'YYYY-MM-DD' format. - **to** (string) - Required - End date in 'YYYY-MM-DD' format. ### Request Example ```python print(finnhub_client.ipo_calendar(_from="2020-05-01", to="2020-06-01")) ``` ``` -------------------------------- ### Support Resistance Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves support and resistance levels for a stock symbol. ```APIDOC ## support_resistance ### Description Retrieves support and resistance levels for a stock symbol. ### Method `finnhub_client.support_resistance(symbol, resolution)` ### Parameters #### Path Parameters - **symbol** (string) - Required - Stock symbol (e.g., 'AAPL'). - **resolution** (string) - Required - Candlestick resolution (e.g., 'D' for daily, 'W' for weekly, 'M' for monthly). ### Request Example ```python print(finnhub_client.support_resistance('AAPL', 'D')) ``` ``` -------------------------------- ### Get Stock Social Sentiment Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves social sentiment data for a stock symbol. Requires the stock symbol. ```python print(finnhub_client.stock_social_sentiment('GME')) ``` -------------------------------- ### Forex Rates Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves real-time forex rates for a given base currency. ```APIDOC ## forex_rates ### Description Retrieves real-time forex rates for a given base currency. ### Method `finnhub_client.forex_rates(base)` ### Parameters #### Path Parameters - **base** (string) - Required - The base currency symbol (e.g., 'USD'). ### Request Example ```python print(finnhub_client.forex_rates(base='USD')) ``` ``` -------------------------------- ### Get Historical Index Constituents Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve historical constituents of a specified stock market index for a given date. ```python # Indices Historical Constituents print(finnhub_client.indices_hist_const(symbol = "^GSPC")) ``` -------------------------------- ### Get Transcripts Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch the full text of a company's earnings call transcript using its unique ID. ```python # Transcripts print(finnhub_client.transcripts('AAPL_162777')) ``` -------------------------------- ### Investment Themes Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieves investment themes data for a given theme. ```APIDOC ## Investment Themes ### Description Retrieves investment themes data for a given theme. ### Method `stock_investment_theme(theme: str)` ### Parameters #### Path Parameters - **theme** (str) - Required - The investment theme. ### Request Example ```python print(finnhub_client.stock_investment_theme('financialExchangesData')) ``` ``` -------------------------------- ### Get Investor Ownership Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Fetch investor ownership data for a company. The limit parameter controls the number of results. ```python # Investors ownership print(finnhub_client.ownership('AAPL', limit=5)) ``` -------------------------------- ### Price Metrics, Splits, and Dividends Source: https://context7.com/finnhub-stock-api/finnhub-python/llms.txt Retrieve historical price metrics, stock splits, and dividend history. ```APIDOC ## Price Metrics, Splits, and Dividends ### Price metrics (valuation, growth, margins — point-in-time) ```python # Price metrics (valuation, growth, margins — point-in-time) metrics = client.price_metrics(symbol="AAPL", date="2022-01-01") print(metrics["metric"]) ``` ``` -------------------------------- ### Get Company Earnings Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve earnings data for a specific company. The limit parameter controls the number of results. ```python # Earnings surprises print(finnhub_client.company_earnings('TSLA', limit=5)) ``` -------------------------------- ### List Countries Source: https://github.com/finnhub-stock-api/finnhub-python/blob/master/README.md Retrieve a list of supported countries from the API. ```python # List country print(finnhub_client.country()) ```