load_pair_data_for_single_exchange#

load_pair_data_for_single_exchange(client, execution_context, time_bucket, chain_id=None, exchange_slug=None, pair_tickers=None, universe_options=None, liquidity=False, stop_loss_time_bucket=None, required_history_period=None, start_time=None, end_time=None)[source]#

Load pair data for a single decentralised exchange.

If you are not trading the full trading universe, this function does a much smaller dataset download than load_all_data().

  • This function uses optimised JSONL loading via fetch_candles_by_pair_ids().

  • Backtest data is never reloaded. Furthermore, the data is stored in Client disk cache for the subsequent notebook and backtest runs.

  • Live trading purges old data fields and reloads data

Example:

… code-block:: python

TRADING_PAIR = (ChainId.avalanche, “trader-joe”, “WAVAX”, “USDC”)

dataset = load_pair_data_for_single_exchange(

client, pair=TRADING_PAIR, execution_context=execution_context, universe_options=universe_options,

)

Example (old):

# Time bucket for our candles
candle_time_bucket = TimeBucket.d1

# Which chain we are trading
chain_id = ChainId.bsc

# Which exchange we are trading on.
exchange_slug = "pancakeswap-v2"

# Which trading pair we are trading
trading_pairs = {
    ("WBNB", "BUSD"),
    ("Cake", "WBNB"),
}

# 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_pairs,
)
Parameters:
  • client (BaseClient) – Trading Strategy client instance

  • time_bucket (TimeBucket) – The candle time frame

  • chain_id (Optional[ChainId]) –

    Which blockchain hosts our exchange.

    Legacy. Give this or pair.

  • exchange_slug (Optional[str]) –

    Which exchange hosts our trading pairs

    Legacy. Give this or pair.

  • exchange_slug

    Which exchange hosts our trading pairs

    Legacy. Give this or pair.

  • pair_tickers (Optional[Union[Set[Tuple[str, str]], Collection[Union[Tuple[ChainId, str, str, str, float], Tuple[ChainId, str, str, str]]]]]) – List of trading pair tickers as base token quote token tuples. E.g. [(‘WBNB’, ‘BUSD’), (‘Cake’, ‘BUSD’)].

  • liquidity – Set true to load liquidity 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 (Optional[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_time (Optional[datetime]) – Timestamp when to start loding data (inclusive)

  • end_time (Optional[datetime]) – Timestamp when to end loding data (inclusive)

Return type:

Dataset