Web3Config#
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)#
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
()Close all connections.
create_web3
(url[, gas_price_method])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
Chain id for single chain strategies
How do we price our txs
Mapping of different connections for different chains
- gas_price_method: Optional[GasPriceMethod] = None#
How do we price our txs
- static create_web3(url, gas_price_method=None)[source]#
Create a new Web3.py connection.
- Parameters:
url (str) – JSON-RPC node URL
gas_price_method (Optional[GasPriceMethod]) – How do we estimate gas for a transaction If not given autodetect the method.
- Return type:
Web3
- 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, **kwargs)[source]#
Setup connections based on given RPC URLs.
Read JSON_RPC_BINANCE, JSON_RPC_POLYGON, etc. environment variables.
- Parameters:
kwargs – {json_rpc_xxx: rpc URL} dict, as parsed by Typer.
gas_price_method (Optional[GasPriceMethod]) –
- Return type: