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

load_trading_and_lending_data(client, execution_context, chain_id, time_bucket=TimeBucket.d1, universe_options=UniverseOptions(start_at=None, end_at=None, history_period=None, candle_time_bucket_override=None, stop_loss_time_bucket_override=None), *, exchange_slugs=None, lending_protocol=None, liquidity=False, stop_loss_time_bucket=None, asset_ids=None, reserve_assets=frozenset({'USDC'}), name=None, volatile_only=False, trading_fee=None, any_quote=False)[source]#

Load trading and lending market for a single chain for all long/short pairs.

  • A shortcut method for constructing trading universe for multipair long/short strategy

  • Gets all supported lending pairs on a chain

  • Discards trading pairs that do not have a matching lending reserve with a quote token reserve_assset_symbol

  • Will log output regarding the universe construction for diagnostics

More information

Example for historical data:

start_at = datetime.datetime(2023, 9, 1)
end_at = datetime.datetime(2023, 10, 1)

# Load all trading and lending data on Polygon
# for all lending markets on a relevant time period
dataset = load_trading_and_lending_data(
    universe_options=UniverseOptions(start_at=start_at, end_at=end_at),

strategy_universe = TradingStrategyUniverse.create_from_dataset(dataset)
data_universe = strategy_universe.data_universe

# Check one loaded reserve metadata
usdc_reserve = data_universe.lending_reserves.get_by_chain_and_symbol(ChainId.polygon, "USDC")

# Check the historical rates
lending_candles = data_universe.lending_candles.variable_borrow_apr
rates = lending_candles.get_rates_by_reserve(usdc_reserve)

assert rates["open"][pd.Timestamp("2023-09-01")] == pytest.approx(3.222019)
assert rates["open"][pd.Timestamp("2023-10-01")] == pytest.approx(3.446714)

Example for current data:

  • asset_ids (Optional[Set[str]]) –

    Load only these lending reserves.

    If not given load all lending reserves available on a chain.

  • trading_fee (Optional[float]) –

    Loan only trading pairs on a specific fee tier.

    For example set to 0.0005 to load only 5 BPS Uniswap pairs.

  • reserve_assets (Set[str]) –

    In which currency, the trading pairs must be quoted for the lending pool.

    The reserve asset data is read from the lending reserve universe.

    This will affect the shape of the trading universe.

    For trading, we need to have at least one trading pair with this quote token. The best fee is always picked.

  • volatile_only

    If set to False, ignore stablecoin-stablecoin trading pairs.

    TODO: Does not work correctly at the moment.

  • any_quote – Include ETH, MATIC, etc. quoted trading pairs and three-legged trades.

  • client (BaseClient) –

  • execution_context (ExecutionContext) –

  • chain_id (ChainId) –

  • time_bucket (TimeBucket) –

  • universe_options (UniverseOptions) –

  • exchange_slugs (Optional[Union[Set[str], str]]) –

  • lending_protocol (Optional[LendingProtocolType]) –

  • liquidity (bool) –

  • stop_loss_time_bucket (Optional[TimeBucket]) –

  • name (Optional[str]) –