gmx.retry
Documentation for eth_defi.gmx.retry Python module.
GMX API Retry and Failover Logic
Centralised retry and backup failover handling for all GMX API calls.
Module Attributes
Default production retry configuration |
Functions
|
Make a GMX API request with full-cycle retry. |
Classes
Configuration for GMX API retry and failover behaviour. |
- class GMXRetryConfig
Bases:
objectConfiguration for GMX API retry and failover behaviour.
Controls how aggressively the GMX API client retries failed requests across multiple endpoints. Production defaults are tuned for reliability; tests should use
get_test_retry_config()for faster feedback.Example:
# Production (default) config = GMXRetryConfig() # Fast-fail for tests config = GMXRetryConfig.create_test_config()
- classmethod create_test_config()
Create a retry config tuned for fast test feedback.
Reduces retries and delays so tests fail quickly instead of burning minutes on unreachable API endpoints.
- Return type
- DEFAULT_RETRY_CONFIG = GMXRetryConfig(max_retries=3, initial_delay=2.0, max_delay=30.0, backoff_multiplier=2.0, full_cycle_retries=2)
Default production retry configuration
- make_gmx_api_request(chain, endpoint, params=None, timeout=10.0, retry_config=None, max_retries=None, retry_delay=None)
Make a GMX API request with full-cycle retry.
This is the SINGLE centralised function for all GMX API calls. It handles:
Retry with exponential backoff per endpoint
Automatic failover from primary to backup to fallback APIs
Full-cycle retry: primary → backup → fallback → fallback-2 → wait → repeat
Retry flow:
Try primary API (max_retries attempts with exponential backoff)
Try backup API (max_retries attempts with exponential backoff)
Try fallback API (max_retries attempts with exponential backoff)
Try fallback-2 API (max_retries attempts with exponential backoff)
Wait initial_delay, then repeat full cycle
After full_cycle_retries full cycles, raise RuntimeError
- Parameters
chain (str) – Chain name (e.g., “arbitrum”, “avalanche”)
endpoint (str) – API endpoint path (e.g., “/tokens”, “/signed_prices/latest”)
timeout (float) – HTTP request timeout in seconds
retry_config (eth_defi.gmx.retry.GMXRetryConfig | None) – Retry behaviour configuration. Uses
DEFAULT_RETRY_CONFIGwhenNone.max_retries (int | None) – Deprecated. Kept for backwards compatibility but ignored.
retry_delay (float | None) – Deprecated. Kept for backwards compatibility but ignored.
- Returns
Parsed JSON response
- Raises
RuntimeError – If all retries and backup attempts fail
- Return type