finnhub-python

repository·master·Indexed 21 days ago

https://github.com/finnhub-stock-api/finnhub-python

A Python client library for the Finnhub Stock API providing programmatic access to real-time and historical financial data. It supports stocks, forex, crypto, and economic indicators, including features for retrieving stock candle data, company profiles, financial statements, earnings estimates, news sentiment, and technical indicators.

Tokens
2.6K
Snippets
16
Records
16
Agent score
27%

What's inside finnhub-python

  1. Get company news (Note on `_from` parameter)

    master

    When calling company_news, you must use the parameter name _from instead of from to avoid a Python syntax conflict with the reserved from keyword.

    # Use _from instead of from to avoid conflict
    print(finnhub_client.company_news('AAPL', _from="2020-06-01", to="2020-06-10'))
  2. Retrieve company profile information

    master

    You can look up company profiles using a symbol, isin, or cusip.

    print(finnhub_client.company_profile(symbol='AAPL'))
    print(finnhub_client.company_profile(isin='US0378331005'))
    print(finnhub_client.company_profile(cusip='037833100'))
    
    # Alternative profile method
    print(finnhub_client.company_profile2(symbol='AAPL'))
  3. Access ETF and Mutual Fund data

    master

    Retrieve information regarding ETFs and Mutual Funds:

    • etfs_profile(symbol/isin): Get ETF profile.
    • etfs_holdings(symbol/isin, skip, date): Get ETF holdings.
    • etfs_sector_exp(symbol): Get ETF sector exposure.
    • etfs_country_exp(symbol): Get ETF country exposure.
    • mutual_fund_profile(symbol/isin): Get Mutual Fund profile.
    • mutual_fund_holdings(symbol/isin, skip): Get Mutual Fund holdings.
    # ETFs
    print(finnhub_client.etfs_profile('SPY'))
    print(finnhub_client.etfs_holdings('SPY'))
    
    # Mutual Funds
    print(finnhub_client.mutual_fund_profile("VTSAX"))
    print(finnhub_client.mutual_fund_holdings("VTSAX"))
  4. Access financial and earnings data

    master

    The client provides various methods for financial analysis, including:

    • company_basic_financials(symbol, metric): Get basic financials.
    • company_earnings(symbol, limit): Get earnings surprises.
    • company_eps_estimates(symbol, freq): Get EPS estimates.
    • company_revenue_estimates(symbol, freq): Get revenue estimates.
    • financials(symbol, report_type, frequency): Get detailed financials (e.g., 'bs' for balance sheet).
    • financials_reported(symbol, freq): Get financials as reported.
    # Basic financials
    print(finnhub_client.company_basic_financials('AAPL', 'all'))
    
    # Earnings surprises
    print(finnhub_client.company_earnings('TSLA', limit=5))
    
    # EPS estimates
    print(finnhub_client.company_eps_estimates('AMZN', freq='quarterly'))
    
    # Financials
    print(finnhub_client.financials('AAPL', 'bs', 'annual'))
  5. Get crypto and forex data

    master

    The library supports cryptocurrency and forex markets:

    • crypto_exchanges(): List crypto exchanges.
    • crypto_symbols(exchange): List symbols for a specific exchange.
    • crypto_candles(symbol, resolution, from, to): Get crypto candle data.
    • forex_exchanges(): List forex exchanges.
    • forex_rates(base): Get forex rates for a base currency.
    • forex_symbols(exchange): List forex symbols.
    • forex_candles(symbol, resolution, from, to): Get forex candle data.
    # Crypto
    print(finnhub_client.crypto_exchanges())
    print(finnhub_client.crypto_symbols('BINANCE'))
    print(finnhub_client.crypto_candles('BINANCE:BTCUSDT', 'D', 1590988249, 1591852249))
    
    # Forex
    print(finnhub_client.forex_exchanges())
    print(finnhub_client.forex_rates(base='USD'))
    print(finnhub_client.forex_symbols('OANDA'))
  6. Get Technical Indicators and Patterns

    master

    Retrieve technical analysis data:

    • aggregate_indicator(symbol, resolution): Technical indicator data.
    • technical_indicator(symbol, resolution, _from, to, indicator, indicator_fields=None): Detailed technical indicator request.
    • pattern_recognition(symbol, resolution): Pattern recognition data.
    • support_resistance(symbol, resolution): Support and resistance levels.
    # Get support and resistance levels
    levels = client.support_resistance('AAPL', 'D')
  7. Get Company Earnings and Estimates

    master

    Retrieve earnings data and various analyst estimates:

    • company_earnings(symbol, limit=None): Historical earnings.
    • company_eps_estimates(symbol, freq=None): EPS estimates.
    • company_revenue_estimates(symbol, freq=None): Revenue estimates.
    • company_net_income_estimates(symbol, freq=None): Net income estimates.
    • company_ebitda_estimates(symbol, freq=None): EBITDA estimates.
    # Get EPS estimates
    eps_estimates = client.company_eps_estimates('AAPL', freq='quarterly')