Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python client for Finnhub API

License

NotificationsYou must be signed in to change notification settings

paduel/fhub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python client for Finnhub API

Python versionPyPi versionLicense Apache 2.0Statuscontributions welcome

A pythonic way to use the Finnhub data API.

This package is still in a very early stage of development, so it is still incomplete and may contain bugs. It should only be used to test its functionality.

Installation

pip install fhub

Quick start

You need a Finnhub API Key, you can get free one, athttps://finnhub.io. For some data a premium account is necessary.

fromfhubimportSessionhub=Session("your_finnhub_api_key_here")# Download prices time serie of Tesla.tsla=hub.candle('TSLA')# Download prices for several tickers from a date.data=hub.candle(['AMZN','NFLX','DIS'],start="2018-01-01")# Download prices and bollinger bands indicator for several tickers.data=hub.indicator(['AAPL','MSFT'],start='2019-01-01',indicator='bbands',indicator_fields={'timeperiod':10})

Real-time subscription via Finnhub's websocket is easy using fhub, even using custom functions for each tick received.

fromfhubimportSubscriptionfromtimeimportsleepdefprice_monitor(ticker):# Callback function receive a ticker object# calculate the average of the last 30 ticks using the ticker historyaverage=ticker.history.price.tail(30).mean().round(2)# display the price and the calculated averageprint (f'{ticker.symbol}. Price:{ticker.price} Average(30) :{average}')# show a message if price is over its averageifticker.price>average:print(f'{ticker.symbol} is over its average price')return# Create a subscription and connectsubs=Subscription("your_finnhub_api_key_here")# A list of the symbols to which to subscribe is passed# Created function  is assigned as a callback when a new tick is receivedsubs.connect(["BINANCE:BTCUSDT","IC MARKETS:1","AAPL"],on_tick=price_monitor            )# Subscription is maintained for 20 seconds and then closed.forfinrange(20):sleep(1)subs.close()

See more examples of use atquick_start notebook

Documentation

Official documentation of the API REST of Finnhub:

https://finnhub.io/docs/api

Most of the functions available in the REST API have been implemented.


[8]ページ先頭

©2009-2025 Movatter.jp