Web3Config#
API documentation for tradeexecutor.ethereum.web3config.Web3Config Python class in Trading Strategy framework.
- class Web3Config[source]#
Bases:
object
Advanced Web3 connection manager.
Supports multiple blockchain connections.
- __init__(connections=<factory>, gas_price_method=None, default_chain_id=None, anvil=None)#
- Parameters:
connections (Dict[ChainId, MultiProviderWeb3]) –
gas_price_method (Optional[GasPriceMethod]) –
anvil (Optional[AnvilLaunch]) –
- Return type:
None
Methods
__init__
([connections, gas_price_method, ...])add_hot_wallet_signing
(hot_wallet)Make web3.py native signing available in the console.
Check that we are connected to the correct chain.
Set the default chain we are connected to.
close
([log_level])Close all connections.
create_web3
(configuration_line[, ...])Create a new Web3.py connection.
get_connection
(chain_id)Get a connection to a specific network.
Getst the default connection.
has_any_connection
()Do we have one or more chains configured.
Is this connection a testing fork of a mainnet.
set_default_chain
(chain_id)Set the default chain our strategy runs on.
setup_from_environment
(gas_price_method[, ...])Setup connections based on given RPC URLs.
Attributes
Anvil backend we use for the transaction simuation
Chain id for single chain strategies
How do we price our txs
Is this mainnet fork for simulation deployment
Mapping of different connections for different chains
- connections: Dict[ChainId, MultiProviderWeb3]#
Mapping of different connections for different chains
- gas_price_method: Optional[GasPriceMethod] = None#
How do we price our txs
- anvil: Optional[AnvilLaunch] = None#
Anvil backend we use for the transaction simuation
- mainnet_fork_simulation = False#
Is this mainnet fork for simulation deployment
- static create_web3(configuration_line, gas_price_method=None, unit_testing=False, simulate=False, mev_endpoint_disabled=False)[source]#
Create a new Web3.py connection.
- Parameters:
configuration_line (str) –
JSON-RPC configuration line.
May contain several space separated entries.
gas_price_method (Optional[GasPriceMethod]) – How do we estimate gas for a transaction If not given autodetect the method.
unit_testing (bool) –
Are we executing against unit testing JSON-RPC endpoints.
If so set latency to zero.
simulate (bool) – Set up Anvil mainnet fork for transaction simulation.
mev_endpoint_disabled (bool) – MEV endpoints do not work when deploying contracts with Forge.
- Return type:
- close(log_level=None)[source]#
Close all connections.
- Parameters:
level – Logging level to copy Anvil stdout
log_level (int | None) –
- choose_single_chain()[source]#
Set the default chain we are connected to.
Ensure we have exactly 1 JSON-RPC endpoint configured.
- set_default_chain(chain_id)[source]#
Set the default chain our strategy runs on.
Most strategies are single chain strategies. Set the chain id we expect these strategies to run on.
- Parameters:
chain_id (ChainId) –
- get_default()[source]#
Getst the default connection.
Assumes exactly 1 node connection available.
- Return type:
Web3
- check_default_chain_id()[source]#
Check that we are connected to the correct chain.
The JSON-RPC node chain id should be the same as in the strategy module.
- classmethod setup_from_environment(gas_price_method, unit_testing=False, simulate=False, mev_endpoint_disabled=False, **kwargs)[source]#
Setup connections based on given RPC URLs.
Read JSON_RPC_BINANCE, JSON_RPC_POLYGON, etc. environment variables.
- Parameters:
mev_endpoint_disabled (bool) – MEV endpoints do not work when deploying contracts with Forge.
kwargs – {json_rpc_xxx: rpc URL} dict, as parsed by Typer.
gas_price_method (Optional[GasPriceMethod]) –
unit_testing (bool) –
simulate (bool) –
- Return type:
- add_hot_wallet_signing(hot_wallet)[source]#
Make web3.py native signing available in the console.
- Parameters:
hot_wallet (HotWallet) –
- __init__(connections=<factory>, gas_price_method=None, default_chain_id=None, anvil=None)#
- Parameters:
connections (Dict[ChainId, MultiProviderWeb3]) –
gas_price_method (Optional[GasPriceMethod]) –
anvil (Optional[AnvilLaunch]) –
- Return type:
None