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.
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.
Set up mock data.
read_onchain_data
(web3, factory_address, ...)Reads Uniswap v2 data from EVM backend and creates tables for it.
- 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:
- Return type:
Tuple[ExchangeUniverse, Table]