Giter Club home page Giter Club logo

fhub's Introduction

Fhub

Python client for Finnhub API

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.

fhub's People

Contributors

bukosabino avatar nicola-pesavento avatar paduel 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

Watchers

 avatar  avatar  avatar  avatar

fhub's Issues

[Errno 22] Invalid argument

Trying to obtain intraday data I obtain the following error:

data = hub.candle('AMZN', resolution='60', end="2020-05-22")
Traceback (most recent call last):

File "", line 1, in
data = hub.candle('AMZN', resolution='60', end="2020-05-22")

File "C:\Users\casa\Anaconda3\lib\site-packages\fhub\utils.py", line 143, in helper
return func(clase, *args, **kwargs)

File "C:\Users\casa\Anaconda3\lib\site-packages\fhub\utils.py", line 134, in helper
return func(clase, *args, **kwargs)

File "C:\Users\casa\Anaconda3\lib\site-packages\fhub\core.py", line 566, in candle
'from': _unixtime(start),

File "C:\Users\casa\Anaconda3\lib\site-packages\fhub\utils.py", line 169, in _unixtime
return int(datetime.strptime(_normalize_date(date), "%Y-%m-%d").timestamp())

OSError: [Errno 22] Invalid argument

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.