2. Modules

TradingBot is composed by different modules organised by their nature. Each section of this document provide a description of the module meaning along with the documentation of its internal members.

2.1. TradingBot

2.2. Components

The Components module contains the components that provides services used by TradingBot. The Broker class is the wrapper of all the trading services and provides the main interface for the strategies to access market data and perform trades.

2.2.1. IGInterface

2.2.1.1. Enums

2.2.2. AVInterface

2.2.2.1. Enums

2.2.3. Broker

2.2.3.1. Enums

2.2.4. MarketProvider

class Components.MarketProvider.MarketProvider(config, broker)[source]

Provide markets from different sources based on configuration. Supports market lists, dynamic market exploration or watchlists

get_market_from_epic(epic)[source]

Given a market epic id returns the related market snapshot

next()[source]

Return the next market from the configured source

reset()[source]

Reset internal market pointer to the beginning

search_market(search)[source]

Tries to find the market which id matches the given search string. If successful return the market snapshot. Raise an exception when multiple markets match the search string

2.2.4.1. Enums

class Components.MarketProvider.MarketSource[source]

Available market sources: local file list, watch list, market navigation through API, etc.

2.2.5. TimeProvider

2.2.5.1. Enums

2.3. Interfaces

The Interfaces module contains all the interfaces used to exchange information between different TradingBot components. The purpose of this module is have clear internal API and avoid integration errors.

2.3.1. Market

class Interfaces.Market.Market[source]

Represent a tradable market with latest price information

2.4. Strategies

The Strategies module contains the strategies used by TradingBot to analyse the markets. The Strategy class is the parent from where any custom strategy must inherit from. The other modules described here are strategies available in TradingBot.

2.4.1. Strategy

class Strategies.Strategy.Strategy(config, broker)[source]

Generic strategy template to use as a parent class for custom strategies.

backtest(market, start_date, end_date)[source]

Must override

fetch_datapoints(market)[source]

Must override

find_trade_signal(epic_id, prices)[source]

Must override

initialise()[source]

Must override

read_configuration(config)[source]

Must override

run(market)[source]

Run the strategy against the specified market

set_open_positions(positions)[source]

Set the account open positions

2.4.2. StrategyFactory

2.4.3. SimpleMACD

2.4.4. Weighted Average Peak Detection

2.5. Utils

Common utility classes and methods

2.5.1. Utils

class Utility.Utils.Utils[source]

Utility class containing static methods to perform simple general actions

static humanize_time(secs)[source]

Convert the given time (in seconds) into a readable format hh:mm:ss

static is_between(time, time_range)[source]

Return True if time is between the time_range. time must be a string. time_range must be a tuple (a,b) where a and b are strings in format ‘HH:MM’

static midpoint(p1, p2)[source]

Return the midpoint

static percentage(part, whole)[source]

Return the percentage value of the part on the whole

static percentage_of(percent, whole)[source]

Return the value of the percentage on the whole

2.5.2. Enums

class Utility.Utils.TradeDirection[source]

Enumeration that represents the trade direction in the market: NONE means no action to take.

2.5.3. Exceptions

class Utility.Utils.MarketClosedException[source]

Error to notify that the market is currently closed

class Utility.Utils.NotSafeToTradeException[source]

Error to notify that it is not safe to trade