TradingStrategyUniverse#

tradeexecutor.strategy.trading_strategy_universe.TradingStrategyUniverse class.

class TradingStrategyUniverse[source]#

Bases: StrategyExecutionUniverse

A trading executor trading universe that using data from TradingStrategy.ai data feeds.

__init__(reserve_assets, universe=None, backtest_stop_loss_time_bucket=None, backtest_stop_loss_candles=None)#
Parameters
Return type

None

Methods

__init__(reserve_assets[, universe, ...])

create_limited_pair_universe(dataset, ...[, ...])

Filters down the dataset for couple trading pair.

create_multipair_universe(dataset, ...)

Create a trading universe where pairs match a filter conditions.

create_single_pair_universe(dataset, ...)

Filters down the dataset for a single trading pair.

get_pair_by_address(address)

Get a trading pair data by a smart contract address.

get_pair_count()

get_reserve_asset()

Get the default reserve asset.

get_single_pair()

Get the single trading pair in this universe.

has_stop_loss_data()

Do we have data available to determine trade stop losses.

is_empty()

This is an empty universe

is_single_pair_universe()

Is this trading universe made for a single pair trading.

validate()

Check that the created universe looks good.

Attributes

backtest_stop_loss_candles

backtest_stop_loss_time_bucket

universe

Trading universe datasets

universe: Optional[Universe] = None#

Trading universe datasets

is_empty()[source]#

This is an empty universe

  • without trading pairs

  • …or without candles

Return type

bool

is_single_pair_universe()[source]#

Is this trading universe made for a single pair trading.

Note that even a single pair universe may contain two trading pairs, if we need intermediate routing pairs. E.g. AAVE -> BNB -> BUSD/

Return type

bool

has_stop_loss_data()[source]#

Do we have data available to determine trade stop losses.

Note that this applies for backtesting only - when doing production trade execution, stop loss data is not part of the universe but real time pricing comes directly from the exchange using real-time side channels.

Return type

bool

validate()[source]#

Check that the created universe looks good.

Raises

TradingUniverseIssue – In the case of detected issues

static create_single_pair_universe(dataset, chain_id, exchange_slug, base_token, quote_token)[source]#

Filters down the dataset for a single trading pair.

This is ideal for strategies that only want to trade a single pair.

Parameters
  • reserve_currency – If set use this as a reserve currency, otherwise use quote_token.

  • dataset (Dataset) –

  • chain_id (ChainId) –

  • exchange_slug (str) –

  • base_token (str) –

  • quote_token (str) –

Return type

TradingStrategyUniverse

static create_limited_pair_universe(dataset, chain_id, exchange_slug, pairs, reserve_asset_pair_ticker=None)[source]#

Filters down the dataset for couple trading pair.

This is ideal for strategies that only want to trade few pairs, or a single pair using three-way trading on a single exchange.

The university reserve currency is set to the quote token of the first pair.

Parameters
  • dataset (Dataset) – Datasets downloaded from the server

  • pairs (Set[Tuple[str, str]]) – List of trading pairs as ticket tuples. E.g. [ (“WBNB, “BUSD”), (“Cake”, “WBNB”) ]

  • reserve_asset_pair_ticker (Optional[Tuple[str, str]]) – Choose the quote token of this trading pair as a reserve asset. This must be given if there are several pairs (Python set order is unstable).

  • chain_id (ChainId) –

  • exchange_slug (str) –

Return type

TradingStrategyUniverse

get_pair_by_address(address)[source]#

Get a trading pair data by a smart contract address.

Parameters

address (str) –

Return type

Optional[TradingPairIdentifier]

get_single_pair()[source]#

Get the single trading pair in this universe.

Return type

TradingPairIdentifier

static create_multipair_universe(dataset, chain_ids, exchange_slugs, quote_tokens, reserve_token, factory_router_map)[source]#

Create a trading universe where pairs match a filter conditions.

These universe may contain thousands of trading pairs. This is for strategies that trade across multiple pairs, like momentum strategies.

Parameters
  • dataset (Dataset) – Datasets downloaded from the oracle

  • chain_ids (Iterable[ChainId]) – Allowed blockchains

  • exchange_slugs (Iterable[str]) – Allowed exchanges

  • quote_tokens (Iterable[str]) – Allowed quote tokens as smart contract addresses

  • reserve_token (str) – The token addresses that are used as reserve assets.

  • factory_router_map (Dict[str, tuple]) – Ensure we have a router address for every exchange we are going to use. TODO: In the future this information is not needed.

Return type

TradingStrategyUniverse

__init__(reserve_assets, universe=None, backtest_stop_loss_time_bucket=None, backtest_stop_loss_candles=None)#
Parameters
Return type

None