Live Trading

Classes

Trade([use_mt5])

The Trade object contains functions used for Trade tab

Functions

bol(data_close, data_low, data_high[, …])

Calculates Bollinger Bands (BOL)

forecast_ewm(data[, alpha])

Forecasting with Exponential Weighted Moving Average

macd(data[, fast, slow, signal])

Calculates Moving Average Convergence Divergence (MACD)

rsi(data[, periods, ema])

Calculates Relative Strength Index (RSI)

sma(data, window)

Calculates Simple Moving Average (SMA)

class components.trade.Trade(use_mt5=False)

The Trade object contains functions used for Trade tab

Methods

get_candlestick_chart(symbol, n_points, …)

Get figure for plot

get_rates_data(symbol, timeframe, n_points)

Compute rate data (time, open, high, low, close, tick volume, spread)

get_symbol_names()

Get symbol names

static get_candlestick_chart(symbol, n_points, rates_df, indicators_ind, forecast_methods)

Get figure for plot

Adds plotly.graph_objects charts for candlestick plot, visualizing trade movement

Parameters
  • symbol (str) – symbol to plot for

  • n_points (int) – number of points on candlestick

  • rates_df (pd.DataFrame) – rate data (time, open, high, low, close, tick volume, spread)

  • indicators_ind (list) – list of indicators to plot

  • forecast_methods (list) – list of forecasting methods

Returns

graphical result of trade

Return type

(dict)

get_rates_data(symbol, timeframe, n_points)

Compute rate data (time, open, high, low, close, tick volume, spread)

Parameters
  • symbol (str) – symbol to plot for

  • timeframe (str) – frequency of candlestick

  • n_points (int) – number of points on candlestick

Returns

result of rate data

Return type

(pd.DataFrame)

get_symbol_names()

Get symbol names

Returns

(list)

components.trade.bol(data_close, data_low, data_high, periods=20, num_std=2)

Calculates Bollinger Bands (BOL)

BOL measures volatility of market and overbought and oversold conditions and made up of SMA and upper and lower band. The closer the price is to the upper band, the closer to overbought conditions, vice versa. If bands are very close (low volatility), this can be indication of potential future volatility, vice versa

Parameters
  • data_close (pd.Series) – input pandas Series for closing price

  • data_low (pd.Series) – input pandas Series for low price

  • data_high (pd.Series) – input pandas Series for high price

  • periods (int) – number of periods to smooth, defaults to 20

  • num_std (int) – number of standard deviation, defaults to 2

Returns

(pd.Series)

components.trade.forecast_ewm(data, alpha=0.8)

Forecasting with Exponential Weighted Moving Average

Parameters
  • data (pd.Series) – input pandas Series

  • alpha (float) – weight given to preceding EMA value

Returns

(float)

components.trade.macd(data, fast=12, slow=26, signal=9)

Calculates Moving Average Convergence Divergence (MACD)

MACD is a momentum indicator that signal shifts in market momentum and signal potential breakouts. MACD measures the relationship between fast and slow EMA (typically 12-day and 26-day respectively). Signal/Trigger measures EMA of period shorter than shortest period used in calculating MACD (typically 9-day). Difference between MACD and Trigger represent current selling pressures, positive represent bullish trend whereas negative indicate bearish one

Parameters
  • data (pd.Series) – input pandas Series

  • fast (int) – number of period to calculate fast EMA, defaults to 12

  • slow (int) – number of periods to calculate slow EMA, defaults to 26

  • signal (int) – number of periods to calculate signal, defaults to 9

Returns

MACD, MACD SIGNAL, MACD - Signal

Return type

(pd.Series, pd.Series, pd.Series)

components.trade.rsi(data, periods=14, ema=True)

Calculates Relative Strength Index (RSI)

RSI is a momentum indicator that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of an asset. RSI measures price change in relation to recent price highs and lows

Parameters
  • data (pd.Series) – input pandas Series

  • periods (int) – number of periods to calculate RSI, defaults to 14

  • ema (bool) – indicator to use exponential moving average, defaults to True

Returns

(pd.Series)

components.trade.sma(data, window)

Calculates Simple Moving Average (SMA)

SMA is a lagging indicator that smooths out price action and highlights direction of trend

Parameters
  • data (pd.Series) – input pandas Series

  • window (int) – number of historical periods to calculate SMA

Returns

(pd.Series)

Classes

TradeSocket()

The TradeSocket object contains functions used for Trade tab

class components.trade_socket.TradeSocket

The TradeSocket object contains functions used for Trade tab

Methods

get_candlestick_chart(symbol, n_points, …)

Get figure for plot

get_historical_data(ticker, granularity[, end])

Get historical data of stock symbol

get_rates_data(symbol, granularity, n_points)

Compute rate data (time, open, high, low, close)

get_symbol_names()

Get symbol names

on_message(ws, message, granularity)

Websocket callback object, called when received data

on_open(ws, symbol)

Websocket callback object, called when opening websocket

run_socket(ticker, granularity)

Connect to web socket

static get_candlestick_chart(symbol, n_points, rates_df, indicators_ind, forecast_methods)

Get figure for plot

Adds plotly.graph_objects charts for candlestick plot, visualizing trade movement

Parameters
  • symbol (str) – symbol to plot for

  • n_points (int) – number of points on candlestick

  • rates_df (pd.DataFrame) – rate data (time, open, high, low, close, tick volume, spread)

  • indicators_ind (list) – list of indicators to plot

  • forecast_methods (list) – list of forecasting methods

Returns

graphical result of trade

Return type

(dict)

get_historical_data(ticker, granularity, end=None)

Get historical data of stock symbol

Parameters
  • ticker (str) – symbol to display

  • granularity (str) – granularity of candlestick chart

  • end (str) – end datetime of historical data

Returns

(pd.DataFrame)

get_rates_data(symbol, granularity, n_points)

Compute rate data (time, open, high, low, close)

Parameters
  • symbol (str) – symbol to display

  • granularity (str) – granularity of candlestick chart

  • n_points (int) – number of points on candlestick

Returns

(pd.DataFrame)

static get_symbol_names()

Get symbol names

Returns

(list)

on_message(ws, message, granularity)

Websocket callback object, called when received data

Parameters
  • ws (WebSocketApp) – websocket class object

  • message (str) – utf-8 data received from server

  • granularity (str) – granularity of candlestick chart

Returns

(pd.DataFrame)

on_open(ws, symbol)

Websocket callback object, called when opening websocket

Parameters
  • ws (WebSocketApp) – websocket object

  • symbol (str) – symbol to display

run_socket(ticker, granularity)

Connect to web socket

Parameters
  • ticker (str) – symbol to display

  • granularity (str) – granularity of candlestick chart