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:
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_default_chain_id()

Check that we are connected to the correct chain.

choose_single_chain()

Set the default chain we are connected to.

close()

Close all connections.

create_web3(configuration_line[, ...])

Create a new Web3.py connection.

get_connection(chain_id)

Get a connection to a specific network.

get_default()

Getst the default connection.

has_any_connection()

has_chain_configured()

Do we have one or more chains configured.

is_mainnet_fork()

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

Anvil backend we use for the transaction simuation

default_chain_id

Chain id for single chain strategies

gas_price_method

How do we price our txs

connections

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

default_chain_id: Optional[ChainId] = None#

Chain id for single chain strategies

anvil: Optional[AnvilLaunch] = None#

Anvil backend we use for the transaction simuation

static create_web3(configuration_line, gas_price_method=None, unit_testing=False, simulate=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.

Return type:

MultiProviderWeb3

close()[source]#

Close all connections.

has_chain_configured()[source]#

Do we have one or more chains configured.

Return type:

bool

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_connection(chain_id)[source]#

Get a connection to a specific network.

Parameters:

chain_id (ChainId) –

Return type:

Optional[Web3]

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, **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]) –

  • unit_testing (bool) –

  • simulate (bool) –

Return type:

Web3Config

is_mainnet_fork()[source]#

Is this connection a testing fork of a mainnet.

Return type:

bool

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:
Return type:

None