gmx.base

Documentation for eth_defi.gmx.base Python module.

GMX Core Module

This module provides the main GMXClient class that integrates all GMX functionality.

Classes

GMXClient

Main client for interacting with the GMX protocol.

class GMXClient

Bases: object

Main client for interacting with the GMX protocol.

This class serves as the primary entry point for all GMX protocol interactions, providing a unified interface that coordinates trading, market data access, liquidity management, and order handling. It follows a composition pattern where specialized managers handle different aspects of GMX functionality.

The client automatically initializes all sub-modules and provides convenient access to configuration and wallet information. It’s designed to be the single object developers need to interact with GMX across all supported networks.

Example:

# Initialize GMX client for Arbitrum with read-only access
config = GMXConfig(
    chain="arbitrum",
    rpc_url="https://arb1.arbitrum.io/rpc",
)

# Check configuration
print(f"Connected to {gmx.get_chain()}")
print(f"Write capability: {gmx.has_write_capability()}")

# Access market data
positions = gmx.market_data.get_positions()

# Place trades (requires wallet configuration)
if gmx.has_write_capability():
    trade_result = gmx.trading.open_position(
        market="ETH/USD",
        side="long",
        size_usd=1000,
    )
Variables
  • config (GMXConfig) – Configuration object containing network and wallet settings

  • market_data (GMXMarketData) – Market data access and analysis functionality

  • trading (GMXTrading) – Trading execution and position management

  • order_manager (GMXOrderManager) – Order creation, modification, and monitoring

  • liquidity_manager (GMXLiquidityManager) – Liquidity provision and LP token management

  • api (GMXAPI) – Direct access to GMX API endpoints

Initialize the GMX client with the provided configuration.

This constructor sets up all sub-modules and validates that the configuration provides sufficient information for the requested operations. Each sub-module is initialized with the same configuration to ensure consistent network and wallet settings across all operations.

Parameters

config (GMXConfig) – GMX configuration object containing network settings, RPC endpoints, wallet information, and other protocol-specific parameters

__init__(config)

Initialize the GMX client with the provided configuration.

This constructor sets up all sub-modules and validates that the configuration provides sufficient information for the requested operations. Each sub-module is initialized with the same configuration to ensure consistent network and wallet settings across all operations.

Parameters

config (GMXConfig) – GMX configuration object containing network settings, RPC endpoints, wallet information, and other protocol-specific parameters

get_chain()

Get the blockchain network currently configured for this client.

This method returns the network identifier (e.g., “arbitrum”, “avalanche”) that was specified during client initialization. This is useful for conditional logic based on network-specific features or parameters.

Returns

Network identifier string indicating which blockchain network this client is configured to use

Return type

str

get_wallet_address()

Get the wallet address associated with this client, if configured.

Returns the Ethereum address of the wallet that was configured for this client instance. This address will be used for all trading and liquidity operations. Returns None if the client was initialized without wallet credentials (read-only mode).

Returns

Ethereum wallet address as a hexadecimal string, or None if no wallet was configured during initialization

Return type

Optional[str]

has_write_capability()

Check whether this client can perform transactions that modify blockchain state.

Returns True if the client has been configured with wallet credentials and private keys necessary to sign and submit transactions. Returns False for read-only clients that can only query data without making changes.

This is essential to check before attempting trading operations, as write operations will fail if the client lacks proper wallet configuration.

Returns

True if the client can sign and submit transactions, False if the client is configured for read-only operations

Return type

bool

get_network_info()

Get comprehensive information about the configured blockchain network.

Returns detailed network information including RPC endpoints, contract addresses, block numbers, and other network-specific parameters. This information is useful for debugging connectivity issues or understanding the current network state.

Returns

Dictionary containing network configuration details such as RPC URLs, contract addresses, current block number, and network-specific parameters

Return type

dict[str, Any]