/fugle_realtime_RESTful_api

In this notebook, I will introduce how to build a real-time stock dashboard

Primary LanguagePython

fugle_realtime_RESTful_api

In this notebook, I will introduce how to build a real-time stock quote application.

For that purpose, we will use Fugle Realtime API and Dash.

Documentations

Environment

  • Python 3.6.9

Installation

pip install -r requirements.txt

Usage

from fugle_realtime_RESTful_api import *

chart_api

chart = chart_api(api_token = 'demo')

If you want to get your own api_token, please visit Fugle Realtime API for more information. Otherwise, you just can use api_token = 'demo' and query Symbol ID 2884 for trial.

get_chart_data:Get min K data from this function

df_ohlc = chart.get_chart_data(n = 5, symbol_id = '2884')

n represents the time interval of the min K data.
symbol_id represents the stock code of the Taiwan stock market.

plot_ohlc & plot_volume_bar:Plot cnadlestick chart from these functions

chart.plot_ohlc(df = df_ohlc, rise_color = 'red', down_color = 'green')
chart.plot_volume_bar(df = df_ohlc, rise_color = 'red', down_color = 'green')

When close price is larger than open price, rise_color will be in red.
On the other hands, when close price is less than open price, down_color will be in green.

plot_MA:Plot Moving Average(MA) line from this function

chart.plot_MA(df = df_ohlc, n = 5, line_color = 'blue', line_width = 2)

n represents the time interval of the MA line.

quote_api

quote = quote_api(api_token = 'demo')

update_quote_data:Update order book(最佳五檔) data from this function

df_quote, price_list, symbol = quote.update_quote_data(symbol_id = '2884')

plot_order_book:Plot order book as html table

quote.plot_order_book(df_quote, price_list, symbol)

df_quote represents an order book that records the historical price since the execution of the code.
price_list represents the current price of the order book.

line_notify

line = line_notify(api_token = 'demo', line_token = 'YOUR LINE NOTIFY TOKEN')

lineNotifyMessage:Send any message to the line notify bot

line.lineNotifyMessage(msg)

target_price_strategy:You can use this function to set the target price strategy in line notify bot.

line.target_price_strategy(symbol_id = '2884', rise_target_price = 30, drop_target_price = 20)

rise_target_price and drop_target_price represent the upper and lower bound of the price strategy.

target_change_strategy:You can use this function to set the target change strategy in line notify bot.

line.target_change_strategy(symbol_id = '2884', rise_target_change = 0.01, drop_target_change = 0.01)

rise_target_change and drop_target_change represent the upper and lower bound of the change strategy.

Dashboard Demo

We use Dash to build our real-time stock quote application.
Dash is a productive Python framework for building web applications.
It is really suited for everyone to bulid a dashboard with highly custom user interface in Python.

Demo At the end, we can see the results at http://127.0.0.1:8050
If you want to get more informations, you can check demo.ipynb.