diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c7eec03..7ce61f25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Current + +- Allow passing `request_kwargs` to [create_multi_provider_web3](https://web3-ethereum-defi.readthedocs.io/api/provider/_autosummary_provider/eth_defi.provider.multi_provider.create_multi_provider_web3.html#eth_defi.provider.multi_provider.create_multi_provider_web3) + # 0.22.12 - Retry [nonce too low errors](https://github.com/tradingstrategy-ai/web3-ethereum-defi/pull/153), diff --git a/eth_defi/provider/multi_provider.py b/eth_defi/provider/multi_provider.py index 07493083..c867203f 100644 --- a/eth_defi/provider/multi_provider.py +++ b/eth_defi/provider/multi_provider.py @@ -4,7 +4,7 @@ """ import logging -from typing import List +from typing import List, Optional, Any from urllib3.util import parse_url, Url from web3 import Web3, HTTPProvider @@ -90,6 +90,7 @@ def create_multi_provider_web3( configuration_line: str, fallback_sleep=0.1, fallback_backoff=1.1, + request_kwargs: Optional[Any] = None, ) -> MultiProviderWeb3: """Create a Web3 instance with multi-provider support. @@ -133,6 +134,13 @@ def create_multi_provider_web3( :param fallback_backoff: Sleep increase multiplier. + :param request_kwargs: + Passed to HTTPProvider, arguments for ``request`` library when doing HTTP requests. + + See :py:class:`web3.HTTPProvider` for details. + + Example: ``request_kwargs={"timeout": 10.0}`` + :return: Configured Web3 instance with multiple providers """ @@ -170,7 +178,7 @@ def create_multi_provider_web3( if len(call_endpoints) < 0: raise MultiProviderConfigurationError(f"At least one call endpoint must be specified, configuration was {configuration_line}") - call_providers = [HTTPProvider(url) for url in call_endpoints] + call_providers = [HTTPProvider(url, request_kwargs=request_kwargs) for url in call_endpoints] # Do uJSON patching for p in call_providers: @@ -180,7 +188,7 @@ def create_multi_provider_web3( transact_provider = None if len(transact_endpoints) > 0: transact_endpoint = transact_endpoints[0] - transact_provider = HTTPProvider(transact_endpoint) + transact_provider = HTTPProvider(transact_endpoint, request_kwargs=request_kwargs) _fix_provider(transact_provider)