CreateTradingUniverseProtocol#

tradeexecutor.strategy.strategy_module.CreateTradingUniverseProtocol Python class in Trading Strategy framework.

class CreateTradingUniverseProtocol[source]#

Bases: Protocol

A call signature protocol for user’s create_trading_universe() functions.

This describes the create_trading_universe function in trading strategies using Python’s callback protocol feature.

See also Strategy examples.

Example create_trading_universe function:

def create_trading_universe(
        ts: datetime.datetime,
        client: Client,
        execution_context: ExecutionContext,
        candle_time_frame_override: Optional[TimeBucket]=None,
) -> TradingStrategyUniverse:

    # Load all datas we can get for our candle time bucket
    dataset = load_pair_data_for_single_exchange(
        client,
        execution_context,
        candle_time_bucket,
        chain_id,
        exchange_slug,
        [trading_pair_ticker],
        stop_loss_time_bucket=stop_loss_time_bucket,
        )

    # Filter down to the single pair we are interested in
    universe = TradingStrategyUniverse.create_single_pair_universe(
        dataset,
        chain_id,
        exchange_slug,
        trading_pair_ticker[0],
        trading_pair_ticker[1],
    )

    return universe
__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

__call__(timestamp, client, execution_context, universe_options)[source]#

Creates the trading universe where the strategy trades.

See also Strategy examples

If execution_context.live_trading is true then this function is called for every execution cycle. If we are backtesting, then this function is called only once at the start of backtesting and the decide_trades need to deal with new and deprecated trading pairs.

As we are only trading a single pair, load data for the single pair only.

Parameters:
  • ts – The timestamp of the trading cycle. For live trading, create_trading_universe is called on every cycle. For backtesting, it is only called at the start

  • client (Optional[Client]) – Trading Strategy Python client instance.

  • execution_context (ExecutionContext) – Information how the strategy is executed. E.g. if we are live trading or not.

  • options – Allow the backtest framework override what candle size is used to backtest the strategy without editing the strategy Python source code file.

  • timestamp (Timestamp) –

  • universe_options (UniverseOptions) –

Returns:

This function must return TradingStrategyUniverse instance filled with the data for exchanges, pairs and candles needed to decide trades. The trading universe also contains information about the reserve asset, usually stablecoin, we use for the strategy.

Return type:

TradingStrategyUniverse

__init__(*args, **kwargs)#