Git Product home page Git Product logo

finnhub-stock-api / finnhub-python Goto Github PK

View Code? Open in Web Editor NEW
498.0 20.0 93.0 296 KB

Finnhub Python API Client. Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals, global ETFs holdings and alternative data. https://finnhub.io/docs/api

Home Page: https://finnhub.io/

License: Apache License 2.0

Shell 6.53% Python 93.47%
finnhub stock api

finnhub-python's Introduction

finnhub-python

Installation

Install package

pip install finnhub-python

Getting Started

Refer to CHANGELOG If you are coming from version 1

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)

#Convert to Pandas Dataframe
import pandas as pd
print(pd.DataFrame(res))

# Aggregate Indicators
print(finnhub_client.aggregate_indicator('AAPL', 'D'))

# 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'))

# Company Executives
print(finnhub_client.company_executive('AAPL'))

# 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"))

# Company Peers
print(finnhub_client.company_peers('AAPL'))

# Company Profile
print(finnhub_client.company_profile(symbol='AAPL'))
print(finnhub_client.company_profile(isin='US0378331005'))
print(finnhub_client.company_profile(cusip='037833100'))

# Company Profile 2
print(finnhub_client.company_profile2(symbol='AAPL'))

# Revenue Estimates
print(finnhub_client.company_revenue_estimates('TSLA', freq='quarterly'))

# List country
print(finnhub_client.country())

# Crypto Exchange
print(finnhub_client.crypto_exchanges())

# Crypto symbols
print(finnhub_client.crypto_symbols('BINANCE'))

# Economic data
print(finnhub_client.economic_data('MA-USA-656880'))

# Filings
print(finnhub_client.filings(symbol='AAPL', _from="2020-01-01", to="2020-06-11"))

# Financials
print(finnhub_client.financials('AAPL', 'bs', 'annual'))

# Financials as reported
print(finnhub_client.financials_reported(symbol='AAPL', freq='annual'))

# Forex exchanges
print(finnhub_client.forex_exchanges())

# Forex all pairs
print(finnhub_client.forex_rates(base='USD'))

# Forex symbols
print(finnhub_client.forex_symbols('OANDA'))

# Fund Ownership
print(finnhub_client.fund_ownership('AMZN', limit=5))

# General news
print(finnhub_client.general_news('forex', min_id=0))

# Investors ownership
print(finnhub_client.ownership('AAPL', limit=5))

# IPO calendar
print(finnhub_client.ipo_calendar(_from="2020-05-01", to="2020-06-01"))

# Major developments
print(finnhub_client.press_releases('AAPL', _from="2020-01-01", to="2020-12-31"))

# News sentiment
print(finnhub_client.news_sentiment('AAPL'))

# Pattern recognition
print(finnhub_client.pattern_recognition('AAPL', 'D'))

# Price target
print(finnhub_client.price_target('AAPL'))

# Quote
print(finnhub_client.quote('AAPL'))

# Recommendation trends
print(finnhub_client.recommendation_trends('AAPL'))

# Stock dividends
print(finnhub_client.stock_dividends('KO', _from='2019-01-01', to='2020-01-01'))

# Stock dividends 2
print(finnhub_client.stock_basic_dividends("KO"))

# Stock symbols
print(finnhub_client.stock_symbols('US')[0:5])

# Transcripts
print(finnhub_client.transcripts('AAPL_162777'))

# Transcripts list
print(finnhub_client.transcripts_list('AAPL'))

# Earnings Calendar
print(finnhub_client.earnings_calendar(_from="2020-06-10", to="2020-06-30", symbol="", international=False))

# Covid-19
print(finnhub_client.covid19())

# Upgrade downgrade
print(finnhub_client.upgrade_downgrade(symbol='AAPL', _from='2020-01-01', to='2020-06-30'))

# Economic code
print(finnhub_client.economic_code()[0:5])

# Economic calendar
print(finnhub_client.calendar_economic('2021-01-01', '2021-01-07'))

# Support resistance
print(finnhub_client.support_resistance('AAPL', 'D'))

# Technical Indicator
print(finnhub_client.technical_indicator(symbol="AAPL", resolution='D', _from=1583098857, to=1584308457, indicator='rsi', indicator_fields={"timeperiod": 3}))

# Stock splits
print(finnhub_client.stock_splits('AAPL', _from='2000-01-01', to='2020-01-01'))

# Forex candles
print(finnhub_client.forex_candles('OANDA:EUR_USD', 'D', 1590988249, 1591852249))

# Crypto Candles
print(finnhub_client.crypto_candles('BINANCE:BTCUSDT', 'D', 1590988249, 1591852249))

# Tick Data
print(finnhub_client.stock_tick('AAPL', '2020-03-25', 500, 0))

# BBO Data
print(finnhub_client.stock_nbbo("AAPL", "2020-03-25", 500, 0))

# Indices Constituents
print(finnhub_client.indices_const(symbol = "^GSPC"))

# Indices Historical Constituents
print(finnhub_client.indices_hist_const(symbol = "^GSPC"))

# ETFs Profile
print(finnhub_client.etfs_profile('SPY'))
print(finnhub_client.etfs_profile(isin="US78462F1030"))

# ETFs Holdings
print(finnhub_client.etfs_holdings('SPY'))
print(finnhub_client.etfs_holdings(isin="US00214Q1040", skip=2))
print(finnhub_client.etfs_holdings("IPO", date='2022-03-10'))

# ETFs Sector Exposure
print(finnhub_client.etfs_sector_exp('SPY'))

# ETFs Country Exposure
print(finnhub_client.etfs_country_exp('SPY'))

# International Filings
print(finnhub_client.international_filings('RY.TO'))
print(finnhub_client.international_filings(country='GB'))

# SEC Sentiment Analysis
print(finnhub_client.sec_sentiment_analysis('0000320193-20-000052'))

# SEC similarity index
print(finnhub_client.sec_similarity_index('AAPL'))

# Bid Ask
print(finnhub_client.last_bid_ask('AAPL'))

# FDA Calendar
print(finnhub_client.fda_calendar())

# Symbol lookup
print(finnhub_client.symbol_lookup('apple'))

# Insider transactions
print(finnhub_client.stock_insider_transactions('AAPL', '2021-01-01', '2021-03-01'))

# Mutual Funds Profile
print(finnhub_client.mutual_fund_profile("VTSAX"))
print(finnhub_client.mutual_fund_profile(isin="US9229087286"))

# Mutual Funds Holdings
print(finnhub_client.mutual_fund_holdings("VTSAX"))
print(finnhub_client.mutual_fund_holdings(isin="US9229087286", skip=2))

# Mutual Funds Sector Exposure
print(finnhub_client.mutual_fund_sector_exp("VTSAX"))

# Mutual Funds Country Exposure
print(finnhub_client.mutual_fund_country_exp("VTSAX"))

# Revenue breakdown
print(finnhub_client.stock_revenue_breakdown('AAPL'))

# Social sentiment
print(finnhub_client.stock_social_sentiment('GME'))

# Investment Themes
print(finnhub_client.stock_investment_theme('financialExchangesData'))

# Supply chain
print(finnhub_client.stock_supply_chain('AAPL'))

# Company ESG
print(finnhub_client.company_esg_score("AAPL"))

# Earnings Quality Score
print(finnhub_client.company_earnings_quality_score('AAPL', 'quarterly'))

# Crypto Profile
print(finnhub_client.crypto_profile('BTC'))

# EBITDA Estimates
print(finnhub_client.company_ebitda_estimates("TSLA", freq="quarterly"))

# EBIT Estimates
print(finnhub_client.company_ebit_estimates("TSLA", freq="quarterly"))

# USPTO Patent
print(finnhub_client.stock_uspto_patent("AAPL", "2021-01-01", "2021-12-31"))

# Visa application
print(finnhub_client.stock_visa_application("AAPL", "2021-01-01", "2022-06-15"))

# Insider sentiment
print(finnhub_client.stock_insider_sentiment('AAPL', '2021-01-01', '2022-03-01'))

# Bond Profile
print(finnhub_client.bond_profile(isin='US912810TD00'))

# Bond price
print(finnhub_client.bond_price('US912810TD00', 1590988249, 1649099548))

# Lobbying
print(finnhub_client.stock_lobbying("AAPL", "2021-01-01", "2022-06-15"))

# USA Spending
print(finnhub_client.stock_usa_spending("LMT", "2021-01-01", "2022-06-15"))

# Sector metrics
print(finnhub_client.sector_metric('NA'))

## Fund's EET data
print(finnhub_client.mutual_fund_eet('LU2036931686'))
print(finnhub_client.mutual_fund_eet_pai('LU2036931686'))

# Symbol & ISIN change
print(finnhub_client.isin_change(_from='2022-10-01', to='2022-10-07'))
print(finnhub_client.symbol_change(_from='2022-10-01', to='2022-10-07'))

# 13-F data
print(finnhub_client.institutional_profile())
print(finnhub_client.institutional_portfolio(cik='1000097', _from='2022-01-01', to='2022-10-07'))
print(finnhub_client.institutional_ownership('TSLA', '', _from='2022-01-01', to='2022-10-07'))

# Bond yield and FINRA Trace tick
print(finnhub_client.bond_yield_curve('10y'))
print(finnhub_client.bond_tick('US693475BF18', '2022-08-19', 500, 0, 'trace'))

# Congressional Trading
print(finnhub_client.congressional_trading('AAPL', '2020-01-01', '2023-03-31'))

# Price metrics with historical data
print(finnhub_client.price_metrics(symbol="AAPL", date="2022-01-01"))

## Market Holday / Status
print(finnhub_client.market_holiday(exchange='US'))
print(finnhub_client.market_status(exchange='US'))

License

Apache License

finnhub-python's People

Contributors

bl4ckst0ne avatar finnhubio avatar ichoyjx avatar nongdenchet avatar shahoob avatar tq-o avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finnhub-python's Issues

[Enhance] Add peers to TS

Problem:
The symbol TS does not have valid peers, it only shows TEN.MI

Solution 1:
Please add the following peers to TS:

HAL
BKR
WFRD
NOV

Solution 2:
Please tell me the file containing the peers, so I can create a PR to add them.

Comments:
There are other symbols with the same problem, I can help to add them as well

No attribute called configuration

Hello, i get an error when I try to initialize my api Key. What am I doung wrong?

configuration = finnhub.Configuration( api_key={ 'token': 'brv2v2frh5r9k3fgpqug' } )

Error that I get is: AttributeError: 'module' object has no attribute 'Configuration'

list to json from response object

HI this is a bit of a newbie question.

@app.route('/fn_earnings')
def finnhub_earnings():
    response = fc.company_earnings('TSLA', limit=5)
    return { 'data': response }

I'm trying to return the response object from a flask query as json. I've tried multiple combinations but I can't seem to figure out the solution. All the examples are using print.

Would you please be able to give me some idea of how to coerce the object into an json format.

Many thanks...

#stock_candle not clear

I admit I am not a sharp python user, but could someone elucidate me what the bold text in the following line of code stands for ? Time range ? Idk.
Code :
res = finnhub_client.stock_candles('AAPL', 'D', **1590988249**, **1591852249**)

I honestly have no idea how to tackle this, if someone could be so kind to explain how to deal with it would be great.

EMA

for the technical indicator, what shld the from and to be? I would like to get the current EMA10 in a 15min resolution. Thanks in advance

Code 400 on all Request

Hello,

I am experiencing 400 in all endpoint, but using standard request.get(), i am able to fetch data.
Anyone experiencing the same thing?

ubuntu@ip-172-31-54-235:~$ python example.py
Traceback (most recent call last):
File "example.py", line 7, in
print(finnhub_client.stock_candles("AAPL", "D", 1590988249, 1591852249))
File "/home/ubuntu/.local/lib/python3.8/site-packages/finnhub/client.py", line 206, in stock_candles
return self._get("/stock/candle", params=params)
File "/home/ubuntu/.local/lib/python3.8/site-packages/finnhub/client.py", line 69, in _get
return self._request("get", path, **kwargs)
File "/home/ubuntu/.local/lib/python3.8/site-packages/finnhub/client.py", line 39, in _request
return self._handle_response(response)
File "/home/ubuntu/.local/lib/python3.8/site-packages/finnhub/client.py", line 44, in _handle_response
raise FinnhubAPIException(response)
finnhub.exceptions.FinnhubAPIException: FinnhubAPIException(status_code: 400): Malformed URL.

marketcap

Is it possible to get a timeseries of market capitalization or outstanding shares using this library or rest service?

ETFs and Mutual Funds missing dividends since 2019-01-01

MWE:

import finnhub
from datetime import date
stock = 'VTI'
print(finnhub_client.stock_dividends(stock, _from="2019-01-01", to=date.today()))

returns []

print(finnhub_client.stock_dividends(stock, _from="2018-01-01", to=date.today()))

returns [{'symbol': 'VTI', 'date': '2018-06-22', 'amount': 0.6034, 'adjustedAmount': 0.6034, 'payDate': '2018-06-27', 'recordDate': '2018-06-25', 'declarationDate': '2018-06-20', 'currency': 'USD'}, {'symbol': 'VTI', 'date': '2018-03-22', 'amount': 0.5661, 'adjustedAmount': 0.5661, 'payDate': '2018-03-27', 'recordDate': '2018-03-23', 'declarationDate': '2018-03-20', 'currency': 'USD'}]

Is there a different API call to obtain recent dividend information for ETFs and Mutual Funds?

TypeError: 'StockCandles' object is not subscriptable

Hi,

At first a big thanks for building a Finnhub API wrapper. However, I can't get around how to transform the output of stock_candles to a Dataframe. Can someone help me how to transform the data to a Dataframe format?

Thanks in advance!

technical_indicator: indicator_specific_fields

Hey,

It seems to me that the indicator_specific_fields param doesn't work for the technical_indicator method. The only way I could make it compile and have the request sent was calling it like this:
rsiResult = finn.technical_indicator( symbol=STOCK, resolution=CANDLE_SIZE, _from=UNTIL - TIME_FRAME, to=UNTIL, indicator='rsi', indicator_specific_fields={'timeperiod': 14})

However, this ends up by sending a request to the url which looks like this:
'https://finnhub.io/api/v1/indicator?symbol=AAPL&resolution=15&from=1592163900&to=1592595900&indicator=rsi&Indicator+specific+fields=%7B%27timeperiod%27%3A+14%7D&token=brmfkpvrh5re15om42ag'

Which is different than the one that the back-end expects:
r = requests.get('https://finnhub.io/api/v1/indicator?symbol=AAPL&resolution=D&from=1583098857&to=1584308457&indicator=sma&timeperiod=3&token=brmfkpvrh5re15om42ag')

Full disclosure: my Python skills are close to none, however I spent almost a day on this and could not make it work ๐Ÿ˜

Any sort of help would be appreciated.

Kind regards,
Vlad

Client

Hi. I just did a pip install on pip install finnhub-python. While I can run

import finnhub

When calling finnhub_client = finnhub.Client(api_key="bs5dfjvrh5rfj3oth1ag")

complains AttributeError: module 'finnhub' has no attribute 'Client'

Has something changed in the call?

Could I use this API to get daily stock price everyday?

As title, I've found quote endpoints which could get the close price/high price/low price/etc... data, but it remains the same value after I keep calling the API for a while.

Does this API provide endpoints that allow fetching update stock price values when the real-time stock data changes?

Date Format

Hello,

For the following example, how did you format the dates in the 'from' 'to' arguments like this?

Stock candles

res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249)
print(res)

Thank you!

ValueError: invalid literal for int() with base 10: 'B616C79'

When calling method 'company_profile()' for symbols 'SFIX' and 'TSLA' (possibly there are more) I get this: ValueError: invalid literal for int() with base 10: 'B616C79'. However, when I use the same method with simple get request everything works fine.

Permissions required for using API?

Do we require any kind of permissions if we use these APIs in an office project.
Suppose if I need to get data from bse /nse or nyse on a daily basis for just viewing the current values of a company.
So can this be used for such an office project or would we require any legal permissions????

"goodwill" missing from financials endpoint?

I just noticed that the "goodwill" field seems to have been removed from the financials endpoint over the last month or so. Is this by design? If so, is this something I can reliably derive from the "tangibleBookValueperShare", "sharesOutstanding", and "totalEquity" fields?

Best,
Mike.

Return a timezone feild

Is there a way to add a timezone field in the JSON responses?

I would like to be certain that I am pulling prices in gmt-0 and can't find that info anywhere.

Error quote with CFD indices data

Trying to acquire some quotes ( print(finnhub_client.quote('^GDAXI')) )
I have this error: {'error': 'Market data subscription required for CFD indices.'}.

Same with other indices like [^FCHI', '^IBEX', '^FTSE', '^N225', '^DJI'].

Incorrect limitation for call transcripts

I have a premium plan that should limit me to 150 requests per minute for the call transcripts endpoint.
The response headers send back the correct amount of requests, but using the transcripts() method results in a 429 response:

Here is my code:

for k in call_ids: r = finnhub_client.transcripts(k) all_spx_call_transcripts.append(r) time.sleep(0.5)

I get the following response after 60 requests:

`C:\Anaconda\envs\leap\lib\site-packages\finnhub\client.py in _handle_response(response)
42 def _handle_response(response):
43 if not response.ok:
---> 44 raise FinnhubAPIException(response)
45
46 try:

FinnhubAPIException: FinnhubAPIException(status_code: 429): JSON error message from Finnhub: API limit reached. Please try again later.`

Time out?

New to Finnhub. I am running the following simple code and getting an error message. What is causing this?

CODE
import finnhub
import time
import datetime
import pandas as pd

Setup client
finnhub_client = finnhub.Client(api_key="XXXXXXXXXXXXX")

Stock candles
res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249)
print(res)

ERROR MESSAGE
Traceback (most recent call last):
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 426, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 421, in _make_request
httplib_response = conn.getresponse()
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 1332, in getresponse
response.begin()
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 303, in begin
version, status, reason = self._read_status()
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/util/retry.py", line 403, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 428, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 335, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='finnhub.io', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "timeout-test.py", line 11, in
res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 206, in stock_candles
return self._get("/stock/candle", params=params)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 69, in _get
return self._request("get", path, **kwargs)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 38, in _request
response = getattr(self._session, method)(uri, **kwargs)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='finnhub.io', port=443): Read timed out. (read timeout=10)

Add Short Interest

Short interest is available in the API now. please also add it to this library!

crypto_candles is giving data of wrong length and dates

Hello, I just started working with finnhub moving from yfinance. It's returning the wrong data, the data I ask for is today and up to 200 days back, but instead I get odd numbers like 128 days back or 228 days back, and the start and end times are completely wrong. Here's my "hello world", it has a unfinished function in the middle (functionmovingaverage), but it's just a rough unfinished program. I have a long list of crpytocurrencies reading out of a text file (CryptoList.txt)

#!/usr/bin/python

import finnhub
import pandas as pd
import datetime
import time

starttime = datetime.datetime.now() - datetime.timedelta(days = 200)
currenttime = datetime.datetime.now() - datetime.timedelta()
starttimestamp = int(starttime.timestamp())
currenttimestamp = int(currenttime.timestamp())

print(starttimestamp)
print(currenttimestamp)
cryptolist = open("CryptoList.txt")

fc = finnhub.Client(api_key="cjsjv99r01qm5ielfq1gcjsjv99r01qm5ielfq20")

def functionmovingaverage(pandasdata):
count = 199
sum200 = 0
sum50 = 0
sum20 = 0
sum10 = 0
sum5 = 0
lastval = 0
datalength = len(pandasdata)
print(datalength)
if datalength > 200:
print(datalength)
if datalength < 200:
return -333
for k in pandasdata.itertuples():
print(k)

for i in cryptolist.readlines():
fixedi = i.split('\n')[0]
name = fixedi
print(name)
res = fc.crypto_candles(name, 'D', starttimestamp, currenttimestamp)
dataframe = pd.DataFrame(res)
functionmovingaverage(dataframe)
time.sleep(1)

Earning Calendar

Hi,

I am trying to fetch the earning calendar using the "Earning Calendar" endpoint. In my example, I am fetching earning calendar for 26th Oct 2021.

https://finnhub.io/api/v1/calendar/earnings?from=2021-10-26&to=2021-10-26&token=XXX

image

It is returning me 151 symbols. However, when I check on Earning's Whisper website they have only 135 symbols for 26th Oct.
https://www.earningswhispers.com/calendar?sb=c&d=1&t=all&v=t

My question is: Why is there a difference between Finnhub and Earning's Whisper. Is there anything I should know?

Thanks.

Latest version on PyPi doesn't fetch stock candles

I recently discovered that the library that I was using previously is no longer being served by PyPi, and the project has been archived on Github (https://github.com/s0h3ck/finnhub-api-python-client). So, I switched to this client library.

Unfortunately, however, it doesn't appear to be working properly. When fetching data using the stock_candles method (for any stock that actually has data), the following result is returned:

{'c': None, 'h': None, 'l': None, 'o': None, 's': None, 't': None, 'v': None}

So, I'm currently just using the python requests library and hitting the REST endpoints directly, which obviously isn't as convenient.

Any thoughts would be appreciated.

symbol lookup is not returning useful results

the API docs show the following example:

import finnhub
finnhub_client = finnhub.Client(api_key="")

print(finnhub_client.symbol_lookup('apple'))

with a sample response:

{
  "count": 4,
  "result": [
    {
      "description": "APPLE INC",
      "displaySymbol": "AAPL",
      "symbol": "AAPL",
      "type": "Common Stock"
    },
    {
      "description": "APPLE INC",
      "displaySymbol": "AAPL.SW",
      "symbol": "AAPL.SW",
      "type": "Common Stock"
    },
    {
      "description": "APPLE INC",
      "displaySymbol": "APC.BE",
      "symbol": "APC.BE",
      "type": "Common Stock"
    },
    {
      "description": "APPLE INC",
      "displaySymbol": "APC.DE",
      "symbol": "APC.DE",
      "type": "Common Stock"
    }
  ]
}

but I am currently getting wildly different results, and AAPL is not among them:

{'count': 22,
 'result': [{'description': 'Apple',
   'displaySymbol': 'A19C0M.DU',
   'symbol': 'A19C0M.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APC5.BE',
   'symbol': 'APC5.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A2R7JV.BE',
   'symbol': 'A2R7JV.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT4.BE',
   'symbol': 'A3KUT4.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A1HKKY.HA',
   'symbol': 'A1HKKY.HA',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT3.DU',
   'symbol': 'A3KUT3.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCU.HM',
   'symbol': 'APCU.HM',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A2R7JV.MU',
   'symbol': 'A2R7JV.MU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT6.DU',
   'symbol': 'A3KUT6.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCU.MU',
   'symbol': 'APCU.MU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT6.MU',
   'symbol': 'A3KUT6.MU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A2R7JT.BE',
   'symbol': 'A2R7JT.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT5.DU',
   'symbol': 'A3KUT5.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCL.HM',
   'symbol': 'APCL.HM',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT5.MU',
   'symbol': 'A3KUT5.MU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A3KUT3.MU',
   'symbol': 'A3KUT3.MU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APC5.DU',
   'symbol': 'APC5.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCU.DU',
   'symbol': 'APCU.DU',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCA.HM',
   'symbol': 'APCA.HM',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A1HKKY.BE',
   'symbol': 'A1HKKY.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'APCT.BE',
   'symbol': 'APCT.BE',
   'type': ''},
  {'description': 'Apple',
   'displaySymbol': 'A1HKKY.MU',
   'symbol': 'A1HKKY.MU',
   'type': ''}]}

I don't have access to any of these symbols under my current plan, and even if I did, none of these results are expected

individual economic data series download

Hi,
I am having some trouble downloading economic data. For example,

print(finnhub_client.economic_code('MA-ABW-667984'))

gives

TypeError: economic_code() takes 1 positional argument but 2 were given

What am I missing?

Thanks,

Options Chain command (options_chain) errors out while retrieving information

while using the options.chain command in jupyter notebook, the code block displayed at the end of this issue errors out. In the error description, I can read the following

FinnhubRequestException: FinnhubRequestException: Invalid Response:

followed by the actual information I was requesting which is too lengthy to show here.
The code producing this error is this:

import finnhub
import os
finnhub_client = finnhub.Client(api_key=os.environ['FINNHUB_KEY'])

test = finnhub_client.option_chain(symbol='TSLA')

github finnhub-python getting started code example times out

Running python 2.7.18 64 bit.
installed finnhub-python 2.2.0 via pip
copied and saved github finnhub-python getting started code example
ran it. with my API-key
Got:

{u'c': [80.834999084473, 81.279998779297, 80.580001831055, 82.875, 83.36499786377, 85.997497558594, 88.209999084473, 83.974998474121], u'h': [80.860000610352, 81.550003051758, 81.404998779297, 82.9375, 83.400001525879, 86.402496337891, 88.692497253418, 87.764999389648], u'l': [79.732498168945, 80.574996948242, 80.194999694824, 80.807502746582, 81.830001831055, 83.002502441406, 86.522499084473, 83.870002746582], u'o': [80.186248779297, 81.165000915527, 81.097503662109, 80.837501525879, 82.5625, 83.035003662109, 86.974998474121, 87.327499389648], u's': u'ok', u't': [1591056000, 1591142400, 1591228800, 1591315200, 1591574400, 1591660800, 1591747200, 1591833600], u'v': [87643000, 104491000, 87560000, 137250000, 95655000, 147712000, 166652000, 201662000]}
c h l o s t v
0 80.834999 80.860001 79.732498 80.186249 ok 1591056000 87643000
1 81.279999 81.550003 80.574997 81.165001 ok 1591142400 104491000
2 80.580002 81.404999 80.195000 81.097504 ok 1591228800 87560000
3 82.875000 82.937500 80.807503 80.837502 ok 1591315200 137250000
4 83.364998 83.400002 81.830002 82.562500 ok 1591574400 95655000
5 85.997498 86.402496 83.002502 83.035004 ok 1591660800 147712000
6 88.209999 88.692497 86.522499 86.974998 ok 1591747200 166652000
7 83.974998 87.764999 83.870003 87.327499 ok 1591833600 201662000
Traceback (most recent call last):
File "C:\Users\admin\Documents\fh-examle1.py", line 15, in
print(finnhub_client.aggregate_indicator('AAPL', 'D'))
File "C:\Python27\lib\site-packages\finnhub\client.py", line 89, in aggregate_indicator
"resolution": resolution,
File "C:\Python27\lib\site-packages\finnhub\client.py", line 67, in _get
return self._request("get", path, **kwargs)
File "C:\Python27\lib\site-packages\finnhub\client.py", line 38, in _request
response = getattr(self._session, method)(uri, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='finnhub.io', port=443): Read timed out. (read timeout=10)

Advise?

How to fetch OHLC daily data of NSE?

I have tried but I'm I couldn't make it. I want fetch daily open, high, low, close data and volume of the stock at the end of the day. Can I do it. If I can fetch please show an example. Thank you

Just curious...

why is the stock_candles function's start date parameter named '_from'. in some editors, prevent context sensitive lookup.

Units of indicators

In which units is the data when calling the finnhub API?
e.g.:
requests.get(apiUrl, data)
apiUrl= "https://finnhub.io/api/v1/stock/metric?"
with data = { "symbol": AAPL, "metric": "all", "token": apiKey}

Output:
{
"metric": {
"10DayAverageTradingVolume": 129.38557,
"13WeekPriceReturnDaily": 6.81966,
"26WeekPriceReturnDaily": 53.08419,
"3MonthAverageTradingVolume": 3486.044,
"52WeekHigh": 137.98,
"52WeekHighDate": "2020-09-02",
"52WeekLow": 53.1525,
"52WeekLowDate": "2020-03-23",
"52WeekPriceReturnDaily": 83.00119,
"5DayPriceReturnDaily": 9.02995,
"assetTurnoverAnnual": 0.82884,
"assetTurnoverTTM": 0.82884,
"beta": 1.33989,
"bookValuePerShareAnnual": 3.84873,
.......}

}

Thanks in advance!

Missing data

Hi,
I am using python version of finnhub. And trying to get financial data from financials_reported api, but for some companies, data looks missing.

For example, PFE, this api returns data for 8 years. (No recent data, from 2011 to 2018).
It has 8 years of Cash Flow data, but 7 years of Income Statement and 1 year of Balance Sheet. I don't know why there is these difference between CF, IC and BS?

Please take a look at this gap.
Regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.