get_positions

Documentation for eth_defi.gmx.utils.get_positions function.

get_positions(config, address=None)

Retrieve comprehensive position data with intelligent address resolution and error handling.

This function implements robust position retrieval logic that handles multiple address sources and provides clear error handling for common failure scenarios. It serves as a reliable foundation for all position-dependent operations throughout the trading system.

Address Resolution Strategy:

The function implements intelligent fallback logic for address determination. If an explicit address is provided, it takes precedence. If no address is provided, the function attempts to use the address from the configuration. This pattern provides flexibility for multi-wallet operations while ensuring safe defaults for single-wallet workflows.

Position Data Structure:

The returned data structure uses human-readable position keys (like “ETH_long”) that make position identification intuitive for both programmatic access and manual analysis. Each position entry contains comprehensive information about size, collateral, current performance, and risk metrics.

Error Handling Philosophy:

The function implements defensive programming principles by validating address availability before attempting position queries. Clear error messages help developers understand configuration requirements and debug common setup issues.

Parameters
  • config (GMXConfigManager) – GMX configuration object containing network settings and optional wallet information for position queries

  • address (str, optional) – Specific Ethereum address to query positions for. If None, attempts to use the address from the provided configuration object

Returns

Dictionary containing all open positions keyed by human-readable position identifiers (e.g., “ETH_long”, “BTC_short”) with comprehensive position data as values

Return type

dict[str, Any]

Raises

Exception – When no address is available from either parameter or configuration, making position queries impossible