UniswapV2MockClient#

API documentation for tradingstrategy.testing.uniswap_v2_mock_client.UniswapV2MockClient Python class in Trading Strategy framework.

class UniswapV2MockClient[source]#

Bases: MockClient

A mock client that reads data from a single Uniswap v2 exchange directly from the chain.

Designed to run tests against test EVM backends where we cannot generate proper test data because of the backends being temporary. This way we can skip the ETL step and pretend that the data is just there, but still have meaningful interaction with trading strategies with pairs and trade execution and such.

Currently supported

  • Exchanges

  • Pairs data

Any data is read from the chain on construction, then cached for subsequent fetch calls.

Warning

This client is not suitable to iterate real on-chain data. Due to high amount of real pairs deployed, you will need to wait several hours for :py:methd:`read_onchain_data` to complete.

__init__(web3, factory_address, router_address, init_code_hash=None, fee=0.003)[source]#
Parameters:

Methods

__init__(web3, factory_address, router_address)

clear_caches([filename])

fetch_all_candles()

fetch_all_liquidity_samples(bucket)

fetch_candle_dataset(bucket)

fetch_candles_by_pair_ids()

fetch_exchange_universe()

fetch_pair_universe()

fetch_trading_data_availability()

get_default_quote_token_address([...])

Get the quote token address used in the generated pair map.

initialise_mock_data()

Set up mock data.

read_onchain_data(web3, factory_address, ...)

Reads Uniswap v2 data from EVM backend and creates tables for it.

__init__(web3, factory_address, router_address, init_code_hash=None, fee=0.003)[source]#
Parameters:
initialise_mock_data()[source]#

Set up mock data.

static read_onchain_data(web3, factory_address, router_address, init_code_hash=None, fee=0.003)[source]#

Reads Uniswap v2 data from EVM backend and creates tables for it.

  • Read data from a single Uniswap v2 compatible deployment

  • Read all PairCreated events and constructed Pandas DataFrame out of them

Parameters:
  • fee (float) –

    Uniswap v2 do not have fee information available on-chain, so we need to pass it.

    Default to 30 BPS.

  • web3 (Web3) –

  • factory_address (Union[HexAddress, str]) –

  • router_address (Union[HexAddress, str]) –

  • init_code_hash (Optional[Union[HexStr, str]]) –

Return type:

Tuple[ExchangeUniverse, Table]