Skip to main content

Python client for Finnhub API

Project description

Python version PyPi version License Apache 2.0 Status contributions 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, at https://finnhub.io. For some data a premium account is necessary.

from fhub import Session
hub = 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.

from fhub import Subscription
from time import sleep

def price_monitor(ticker):
    # Callback function receive a ticker object
    # calculate the average of the last 30 ticks using the ticker history
    average = ticker.history.price.tail(30).mean().round(2)
    # display the price and the calculated average
    print (f'{ticker.symbol}. Price: {ticker.price} Average(30) : {average}')
    # show a message if price is over its average
    if ticker.price > average:
        print(f'{ticker.symbol} is over its average price')
    return

# Create a subscription and connect
subs = 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 received
subs.connect(["BINANCE:BTCUSDT", "IC MARKETS:1", "AAPL"],
             on_tick=price_monitor
            )

# Subscription is maintained for 20 seconds and then closed.
for f in range(20):
    sleep(1)
subs.close()

See more examples of use at quick_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhub-0.0.13.tar.gz (16.3 kB view details)

Uploaded Source

File details

Details for the file fhub-0.0.13.tar.gz.

File metadata

  • Download URL: fhub-0.0.13.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for fhub-0.0.13.tar.gz
Algorithm Hash digest
SHA256 1e4dbaea7562dbc5f15d1191aad29a50dfe7fca6339d403e27ee509ea2c53e60
MD5 4e2c1359cb0e484820885d52aed11ba4
BLAKE2b-256 ec503869ae181ef7dafc56e2e6e117d50250355ac88bd0b2030f2dfb652399ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page