load_partial_data#

API documentation for tradeexecutor.strategy.trading_strategy_universe.load_partial_data Python function.

load_partial_data(client, execution_context, time_bucket, pairs, universe_options, liquidity=False, stop_loss_time_bucket=None, required_history_period=None, lending_reserves=None, lending_candle_types=(<LendingCandleType.supply_apr: 'supply_apr'>, <LendingCandleType.variable_borrow_apr: 'variable_borrow_apr'>), start_at=None, end_at=None, name=None, candle_progress_bar_desc=None, lending_candle_progress_bar_desc=None)[source]#

Load pair data for given trading pairs.

A loading function designed to load data for 2-20 pairs. Instead of loading all pair data over Parquet datasets, load only specific pair data from their corresponding JSONL endpoints.

This function works in low memory environments unlike tradeexecutor.strategy.trading_strategy_universe.load_all_data().

Example:

… code-block:: python

TRADING_PAIRS = [

(ChainId.avalanche, “trader-joe”, “WAVAX”, “USDC”), # Avax (ChainId.polygon, “quickswap”, “WMATIC”, “USDC”), # Matic (ChainId.ethereum, “uniswap-v2”, “WETH”, “USDC”), # Eth (ChainId.ethereum, “uniswap-v2”, “WBTC”, “USDC”), # Btc

]

def create_trading_universe(

ts: datetime.datetime, client: Client, execution_context: ExecutionContext, universe_options: UniverseOptions,

) -> TradingStrategyUniverse:

assert not execution_context.mode.is_live_trading(), f”Only strategy backtesting supported, got {execution_context.mode}”

# Load data for our trading pair whitelist dataset = load_partial_data(

client=client, time_bucket=CANDLE_TIME_BUCKET, pairs=TRADING_PAIRS, execution_context=execution_context, universe_options=universe_options, stop_loss_time_bucket=STOP_LOSS_TIME_BUCKET, start_at=START_AT, end_at=END_AT,

)

# Filter down the dataset to the pairs we specified universe = TradingStrategyUniverse.create_multichain_universe_by_pair_descriptions(

dataset, TRADING_PAIRS, reserve_token_symbol=”USDC” # Pick any USDC - does not matter as we do not route

)

return universe

Parameters:
  • client (BaseClient) – Trading Strategy client instance

  • time_bucket (TimeBucket) – The candle time frame.

  • chain_id – Which blockchain hosts our exchange

  • exchange_slug – Which exchange hosts our trading pairs

  • exchange_slug – Which exchange hosts our trading pairs

  • pairs (Union[Collection[Union[Tuple[ChainId, str | None, str, str, float], Tuple[ChainId, str | None, str, str]]], DataFrame]) –

    List of trading pair tickers.

    Can be

    • Human-readable descriptions, see tradingstrategy.pair.HumanReadableTradingPairDescription.

    • Direct pandas.DataFrame of pairs.

  • lending_reserves (Optional[Union[LendingReserveUniverse, Collection[Union[Tuple[ChainId, LendingProtocolType, str], Tuple[ChainId, LendingProtocolType, str, str]]]]]) –

    Lending reserves for which you want to download the data.

    Either list of lending pool descriptions or preloaded lending universe.

  • liquidity – Set true to load liquidity data as well

  • lending_reverses – Set true to load lending reserve data as well

  • stop_loss_time_bucket (Optional[TimeBucket]) – If set load stop loss trigger data using this candle granularity.

  • execution_context (ExecutionContext) – Defines if we are live or backtesting

  • universe_options (UniverseOptions) – Override values given the strategy file. Used in testing the framework.

  • required_history_period (Optional[timedelta]) –

    How much historical data we need to load.

    Depends on the strategy. Defaults to load all data.

  • start_at (Optional[datetime]) –

    Load data for a specific backtesting data range.

    TODO: Going to be deprecatd. Please use universe_options.start_at instead.

  • end_at (Optional[datetime]) –

    Load data for a specific backtesting data range.

    TODO: Going to be deprecatd. Please use universe_options.end_at instead.

  • name (Optional[str]) – The loading operation name used in progress bars

  • candle_progress_bar_desc (Optional[str]) – Override the default progress bar message

  • lending_candle_progress_bar_desc (Optional[str]) – Override the default progress bar message

  • lending_candle_types (Collection[LendingCandleType]) –

Returns:

Datataset containing the requested data

Return type:

Dataset