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_RETRY_CONFIG

Default production retry configuration

Functions

make_gmx_api_request(chain, endpoint[, ...])

Make a GMX API request with full-cycle retry.

Classes

GMXRetryConfig

Configuration for GMX API retry and failover behaviour.

class GMXRetryConfig

Bases: object

Configuration 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()
max_retries: int

Maximum retry attempts per endpoint (primary, backup, fallback, fallback-2)

initial_delay: float

Initial delay in seconds between retries (grows with backoff)

max_delay: float

Maximum delay cap in seconds for exponential backoff

backoff_multiplier: float

Multiplier applied to delay after each failed attempt

full_cycle_retries: int

Number of full cycles through all endpoints before giving up

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

eth_defi.gmx.retry.GMXRetryConfig

__init__(max_retries=3, initial_delay=2.0, max_delay=30.0, backoff_multiplier=2.0, full_cycle_retries=2)
Parameters
  • max_retries (int) –

  • initial_delay (float) –

  • max_delay (float) –

  • backoff_multiplier (float) –

  • full_cycle_retries (int) –

Return type

None

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:

  1. Try primary API (max_retries attempts with exponential backoff)

  2. Try backup API (max_retries attempts with exponential backoff)

  3. Try fallback API (max_retries attempts with exponential backoff)

  4. Try fallback-2 API (max_retries attempts with exponential backoff)

  5. Wait initial_delay, then repeat full cycle

  6. 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”)

  • params (dict[str, Any] | None) – Optional query parameters

  • timeout (float) – HTTP request timeout in seconds

  • retry_config (eth_defi.gmx.retry.GMXRetryConfig | None) – Retry behaviour configuration. Uses DEFAULT_RETRY_CONFIG when None.

  • 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

dict[str, Any]