gmx.order

Documentation for eth_defi.gmx.order Python module.

GMX order module.

Provides all public order classes and result types for the GMX protocol.

Trading orders (inherit from BaseOrder):

Cancel helpers:

SL/TP building blocks:

Pending order helpers:

Base / parameter types:

  • BaseOrder — abstract base for all trading orders

  • OrderParams — common order parameter container

  • OrderResult — result returned after placing an order

  • OrderArgumentParser — helper for resolving human-readable token/market arguments into on-chain parameters

class BaseOrder

Bases: object

Base GMX Order class.

Creates unsigned transactions that can be signed later by the user. Compatible with CCXT trading interface patterns for easy migration.

Initialize the base order with GMX configuration.

Parameters
__init__(config, price_sanity_config=None)

Initialize the base order with GMX configuration.

Parameters
property markets: eth_defi.gmx.core.markets.Markets

Markets instance for retrieving market information.

Uses cached property pattern for efficiency.

property oracle_prices: eth_defi.gmx.core.oracle.OraclePrices

Oracle prices instance for retrieving current prices.

Uses cached property pattern for efficiency.

refresh_cache()

Refresh cached markets and oracle prices data.

Call this method to force a refresh of the cached data if you need the latest market information and prices.

Return type

None

create_order(params, is_open=False, is_close=False, is_swap=False)

Create an order (public interface).

This is the main public method for creating orders.

Parameters
Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

order_builder(params, is_open=False, is_close=False, is_swap=False, is_limit=False, trigger_price=None)

Build an order transaction.

Core method that constructs an unsigned transaction for GMX orders. This replaces the original SDK’s order_builder that submitted transactions.

Parameters
  • params (eth_defi.gmx.order.base_order.OrderParams) – Order parameters

  • is_open (bool) – Whether opening a position

  • is_close (bool) – Whether closing a position

  • is_swap (bool) – Whether performing a swap

  • is_limit (bool) – Whether this is a limit order (triggers at specified price)

  • trigger_price (float | None) – USD price at which order triggers (required for limit orders)

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

class BatchCancelOrderResult

Bases: object

Result of building a batch order cancellation transaction.

Multiple cancelOrder calls are batched into a single multicall transaction for gas efficiency.

The transaction is an unsigned TxParams dict that must be signed before submission.

transaction: web3.types.TxParams

Unsigned transaction ready for signing and submission

order_keys: list[bytes]

The 32-byte order keys that will be cancelled

gas_limit: int

Gas limit applied to the transaction

__init__(transaction, order_keys, gas_limit)
Parameters
  • transaction (web3.types.TxParams) –

  • order_keys (list[bytes]) –

  • gas_limit (int) –

Return type

None

class CancelOrder

Bases: object

Builds unsigned transactions to cancel pending GMX limit orders.

Does not extend BaseOrder because cancellation does not require the heavy initialisation that order creation needs (oracle prices, market data, gas limits from DataStore). Only the ExchangeRouter contract and wallet address are required.

Usage:

cancel = CancelOrder(config)

# Cancel a single order
result = cancel.cancel_order(order_key)

# Cancel multiple orders in one transaction
result = cancel.cancel_orders([key1, key2, key3])

# Sign and submit either result type:
tx = result.transaction.copy()
del tx["nonce"]
signed = wallet.sign_transaction_with_new_nonce(tx)
tx_hash = web3.eth.send_raw_transaction(signed.rawTransaction)

Initialise the cancel order builder.

Parameters

config – GMX configuration with Web3 connection and wallet address.

__init__(config)

Initialise the cancel order builder.

Parameters

config (eth_defi.gmx.config.GMXConfig) – GMX configuration with Web3 connection and wallet address.

Return type

None

cancel_order(order_key, execution_buffer=2.2)

Build an unsigned transaction to cancel a single pending order.

Encodes ExchangeRouter.cancelOrder(orderKey) and wraps it in a multicall call. No ETH value is sent.

Parameters
  • order_key (bytes) – The 32-byte key identifying the order to cancel. Obtain this from order_key or from a previous order creation receipt.

  • execution_buffer (float) – Multiplier applied to web3.eth.gas_price to set the cancel transaction’s maxFeePerGas. Uses the same basis as open/close/sltp keeper fee calculations so gas costs are comparable. Defaults to DEFAULT_EXECUTION_BUFFER.

Returns

CancelOrderResult with the unsigned transaction.

Raises

ValueError – If no wallet address is configured in GMX config.

Return type

eth_defi.gmx.order.cancel_order.CancelOrderResult

cancel_orders(order_keys, execution_buffer=2.2)

Build an unsigned transaction to cancel multiple pending orders at once.

Batches all cancelOrder calls into a single multicall transaction for gas efficiency. Gas limit scales linearly with the number of orders.

Parameters
  • order_keys (list[bytes]) – List of 32-byte keys identifying the orders to cancel.

  • execution_buffer (float) – Multiplier applied to web3.eth.gas_price to set maxFeePerGas. Defaults to DEFAULT_EXECUTION_BUFFER.

Returns

BatchCancelOrderResult with the unsigned multicall transaction.

Raises

ValueError – If order_keys is empty or no wallet address is configured.

Return type

eth_defi.gmx.order.cancel_order.BatchCancelOrderResult

class CancelOrderResult

Bases: object

Result of building a single order cancellation transaction.

The transaction is an unsigned TxParams dict that must be signed before submission.

transaction: web3.types.TxParams

Unsigned transaction ready for signing and submission

order_key: bytes

The 32-byte order key that will be cancelled

gas_limit: int

Gas limit applied to the transaction

__init__(transaction, order_key, gas_limit)
Parameters
  • transaction (web3.types.TxParams) –

  • order_key (bytes) –

  • gas_limit (int) –

Return type

None

class DecreaseOrder

Bases: eth_defi.gmx.order.base_order.BaseOrder

GMX Decrease Order class for closing or reducing positions.

Handles creation of decrease position transactions on GMX protocol, providing unsigned transaction generation for external signing.

Example:

TODO: Add example usage

Initialize decrease order with position identification.

Parameters
  • config (GMXConfig) – GMX configuration

  • market_key (ChecksumAddress) – Market contract address (hex)

  • collateral_address (ChecksumAddress) – Collateral token address (hex)

  • index_token_address (ChecksumAddress) – Index token address (hex)

  • is_long (bool) – True for long position, False for short

__init__(config, market_key, collateral_address, index_token_address, is_long)

Initialize decrease order with position identification.

Parameters
  • config (GMXConfig) – GMX configuration

  • market_key (ChecksumAddress) – Market contract address (hex)

  • collateral_address (ChecksumAddress) – Collateral token address (hex)

  • index_token_address (ChecksumAddress) – Index token address (hex)

  • is_long (bool) – True for long position, False for short

create_decrease_order(size_delta, initial_collateral_delta_amount, slippage_percent=0.003, swap_path=None, execution_buffer=2.2, auto_cancel=False, callback_gas_limit=0, min_output_amount=0, valid_from_time=0)

Create a decrease order transaction.

Creates an unsigned transaction for closing or reducing a position on GMX. The transaction needs to be signed and sent by the user.

Parameters
  • size_delta (float) – Position size to decrease in USD

  • initial_collateral_delta_amount (int | str) – Amount of collateral to remove (in token’s smallest unit)

  • slippage_percent (float) – Slippage tolerance as decimal (e.g., 0.003 = 0.3%)

  • swap_path (Optional[list[str]]) – Optional list of market addresses for swap routing

  • execution_buffer (float) – Gas buffer multiplier for execution fee

  • auto_cancel (bool) – Whether to auto-cancel the order if it can’t execute

  • callback_gas_limit (int) – Gas limit for callback execution

  • min_output_amount (int) – Minimum output amount for swaps

  • valid_from_time (int) – Timestamp when order becomes valid

Returns

OrderResult containing unsigned transaction and execution details

Return type

OrderResult

Raises

ValueError – If parameters are invalid or market doesn’t exist

create_order(params, is_open=False, is_close=False, is_swap=False)

Create an order (public interface).

This is the main public method for creating orders.

Parameters
Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

property markets: eth_defi.gmx.core.markets.Markets

Markets instance for retrieving market information.

Uses cached property pattern for efficiency.

property oracle_prices: eth_defi.gmx.core.oracle.OraclePrices

Oracle prices instance for retrieving current prices.

Uses cached property pattern for efficiency.

order_builder(params, is_open=False, is_close=False, is_swap=False, is_limit=False, trigger_price=None)

Build an order transaction.

Core method that constructs an unsigned transaction for GMX orders. This replaces the original SDK’s order_builder that submitted transactions.

Parameters
  • params (eth_defi.gmx.order.base_order.OrderParams) – Order parameters

  • is_open (bool) – Whether opening a position

  • is_close (bool) – Whether closing a position

  • is_swap (bool) – Whether performing a swap

  • is_limit (bool) – Whether this is a limit order (triggers at specified price)

  • trigger_price (float | None) – USD price at which order triggers (required for limit orders)

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

refresh_cache()

Refresh cached markets and oracle prices data.

Call this method to force a refresh of the cached data if you need the latest market information and prices.

Return type

None

class IncreaseOrder

Bases: eth_defi.gmx.order.base_order.BaseOrder

GMX Increase Order class for opening or increasing positions.

Handles creation of increase position transactions on GMX protocol, providing unsigned transaction generation for external signing.

Example:

TODO: Add example usage

Initialise increase order with position identification.

Parameters
  • config (GMXConfig) – GMX configuration

  • market_key (ChecksumAddress) – Market contract address (hex)

  • collateral_address (ChecksumAddress) – Collateral token address (hex)

  • index_token_address (ChecksumAddress) – Index token address (hex)

  • is_long (bool) – True for long position, False for short

__init__(config, market_key, collateral_address, index_token_address, is_long)

Initialise increase order with position identification.

Parameters
  • config (GMXConfig) – GMX configuration

  • market_key (ChecksumAddress) – Market contract address (hex)

  • collateral_address (ChecksumAddress) – Collateral token address (hex)

  • index_token_address (ChecksumAddress) – Index token address (hex)

  • is_long (bool) – True for long position, False for short

create_increase_order(size_delta, initial_collateral_delta_amount, slippage_percent=0.003, swap_path=None, execution_buffer=2.2, auto_cancel=False, data_list=None, callback_gas_limit=0, min_output_amount=0, valid_from_time=0)

Create an increase order transaction.

Creates an unsigned transaction for opening or increasing a position on GMX. The transaction needs to be signed and sent by the user.

Parameters
  • size_delta (float) – Position size to increase in USD

  • initial_collateral_delta_amount (int | str) – Amount of collateral to add (in token’s smallest unit)

  • slippage_percent (float) – Slippage tolerance as decimal (e.g., 0.003 = 0.3%)

  • swap_path (Optional[list[str]]) – Optional list of market addresses for swap routing

  • execution_buffer (float) – Gas buffer multiplier for execution fee

  • auto_cancel (bool) – Whether to auto-cancel the order if it can’t execute

  • data_list (list) –

  • callback_gas_limit (int) – Gas limit for callback execution

  • min_output_amount (int) – Minimum output amount for swaps

  • valid_from_time (int) – Timestamp when order becomes valid

Returns

OrderResult containing unsigned transaction and execution details

Return type

OrderResult

Raises

ValueError – If parameters are invalid or market doesn’t exist

create_limit_increase_order(trigger_price, size_delta, initial_collateral_delta_amount, slippage_percent=0.003, swap_path=None, execution_buffer=2.2, auto_cancel=True, data_list=None, callback_gas_limit=0, min_output_amount=0, valid_from_time=0)

Create a limit increase order that triggers at specified price.

Creates an unsigned transaction for a limit order that opens or increases a position when the market price reaches the trigger price. The order remains pending until price conditions are met.

Parameters
  • trigger_price (float) – USD price at which order triggers

  • size_delta (float) – Position size to increase in USD

  • initial_collateral_delta_amount (int | str) – Amount of collateral to add (in token’s smallest unit)

  • slippage_percent (float) – Slippage tolerance as decimal (e.g., 0.003 = 0.3%)

  • swap_path (Optional[list[str]]) – Optional list of market addresses for swap routing

  • execution_buffer (float) – Gas buffer multiplier for execution fee

  • auto_cancel (bool) – Whether to auto-cancel the order if it can’t execute (default True)

  • data_list (list) – Additional data for order

  • callback_gas_limit (int) – Gas limit for callback execution

  • min_output_amount (int) – Minimum output amount for swaps

  • valid_from_time (int) – Timestamp when order becomes valid

Returns

OrderResult containing unsigned transaction and execution details

Return type

OrderResult

Raises

ValueError – If parameters are invalid or market doesn’t exist

create_order(params, is_open=False, is_close=False, is_swap=False)

Create an order (public interface).

This is the main public method for creating orders.

Parameters
Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

property markets: eth_defi.gmx.core.markets.Markets

Markets instance for retrieving market information.

Uses cached property pattern for efficiency.

property oracle_prices: eth_defi.gmx.core.oracle.OraclePrices

Oracle prices instance for retrieving current prices.

Uses cached property pattern for efficiency.

order_builder(params, is_open=False, is_close=False, is_swap=False, is_limit=False, trigger_price=None)

Build an order transaction.

Core method that constructs an unsigned transaction for GMX orders. This replaces the original SDK’s order_builder that submitted transactions.

Parameters
  • params (eth_defi.gmx.order.base_order.OrderParams) – Order parameters

  • is_open (bool) – Whether opening a position

  • is_close (bool) – Whether closing a position

  • is_swap (bool) – Whether performing a swap

  • is_limit (bool) – Whether this is a limit order (triggers at specified price)

  • trigger_price (float | None) – USD price at which order triggers (required for limit orders)

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

refresh_cache()

Refresh cached markets and oracle prices data.

Call this method to force a refresh of the cached data if you need the latest market information and prices.

Return type

None

class OrderArgumentParser

Bases: object

Parses and validates order parameters for GMX protocol.

Converts user-friendly parameters into contract-ready format: - Symbol names → token addresses - USD amounts → wei amounts with proper decimals - Calculates missing parameters from leverage - Validates collateral compatibility - Determines optimal swap paths

Initialize parser for specific order type.

Parameters
  • config – GMXConfigManager with chain and network info

  • is_increase – True for opening/increasing positions

  • is_decrease – True for closing/decreasing positions

  • is_swap – True for token swaps

__init__(config, is_increase=False, is_decrease=False, is_swap=False)

Initialize parser for specific order type.

Parameters
  • config – GMXConfigManager with chain and network info

  • is_increase (bool) – True for opening/increasing positions

  • is_decrease (bool) – True for closing/decreasing positions

  • is_swap (bool) – True for token swaps

process_parameters_dictionary(parameters_dict)

Process and validate order parameters.

Parameters

parameters_dict – User-supplied parameters

Returns

Complete, validated parameters ready for contract interaction

static find_key_by_symbol(input_dict, search_symbol)

Find token address by symbol in metadata dict.

Parameters
  • input_dict (dict) –

  • search_symbol (str) –

static find_market_key_by_index_address(input_dict, index_token_address)

Find market key by index token address.

Normalises index_token_address to EIP-55 checksum form before comparing against stored market entries (which are already checksummed by Markets).

Parameters
  • input_dict (dict) –

  • index_token_address (str) –

calculate_missing_position_size_info_keys()

Calculate missing parameters from size/collateral/leverage combinations.

class OrderParams

Bases: object

Order parameters for GMX orders.

__init__(market_key, collateral_address, index_token_address, is_long, size_delta, initial_collateral_delta_amount, slippage_percent=0.005, swap_path=<factory>, max_fee_per_gas=None, auto_cancel=False, execution_buffer=2.2, data_list=<factory>, callback_gas_limit=0, min_output_amount=0, valid_from_time=0)
Parameters
  • market_key (str) –

  • collateral_address (str) –

  • index_token_address (str) –

  • is_long (bool) –

  • size_delta (int | float) –

  • initial_collateral_delta_amount (str) –

  • slippage_percent (float) –

  • swap_path (list[str]) –

  • max_fee_per_gas (Optional[int]) –

  • auto_cancel (bool) –

  • execution_buffer (float) –

  • data_list (Optional[list[str]]) –

  • callback_gas_limit (int) –

  • min_output_amount (int) –

  • valid_from_time (int) –

Return type

None

class OrderResult

Bases: object

Result of order creation containing unsigned transaction.

Parameters
  • transaction – Unsigned transaction ready for signing

  • execution_fee – Estimated execution fee in wei

  • acceptable_price – Acceptable price for execution

  • mark_price – Current mark price

  • gas_limit – Gas limit for transaction

  • estimated_price_impact – Optional estimated price impact in USD

  • price_sanity_check – Optional price sanity check result

__init__(transaction, execution_fee, acceptable_price, mark_price, gas_limit, estimated_price_impact=None, price_sanity_check=None)
Parameters
Return type

None

class PendingOrder

Bases: object

A pending GMX limit order waiting to be executed by a keeper.

Represents a limit order (stop loss, take profit, limit increase) stored in the DataStore pending trigger price conditions. These orders can be cancelled by the user before they are executed.

order_key: bytes

Unique 32-byte identifier for this order in the DataStore

order_type: eth_defi.gmx.constants.OrderType

GMX order type (LIMIT_INCREASE, LIMIT_DECREASE, STOP_LOSS_DECREASE)

account: eth_typing.evm.HexAddress

Address of the account that created this order

receiver: eth_typing.evm.HexAddress

Address that receives the output tokens when the order executes

cancellation_receiver: eth_typing.evm.HexAddress

Address that receives tokens if the order is cancelled

market: eth_typing.evm.HexAddress

Market contract address (index token + long/short collateral pair)

initial_collateral_token: eth_typing.evm.HexAddress

Address of the collateral token provided when the order was created

size_delta_usd: int

Position size delta in USD with 30-decimal precision ($1 = 10^30)

initial_collateral_delta_amount: int

Initial collateral delta amount in token-native decimals

trigger_price: int

Trigger price in 30-decimal precision at which keepers will execute

acceptable_price: int

Acceptable execution price in 30-decimal precision (slippage bound)

execution_fee: int

Execution fee in native token wei paid to the keeper on execution

is_long: bool

Whether this order is for a long position

is_frozen: bool

Whether this order is frozen and cannot be executed until unfrozen

auto_cancel: bool

Whether this order auto-cancels when the associated position is closed

updated_at_time: int

Block timestamp when this order was last updated

swap_path: list[eth_typing.evm.HexAddress]

Swap path as a list of market addresses for output token routing

property trigger_price_usd: float

Trigger price as a human-readable USD float.

GMX stores prices with 10^(30 - token_decimals) precision (PRECISION = 30). This property assumes an 18-decimal index token (ETH, most ERC-20 alts) and therefore divides by 10^12 (= 10^(30 - 18)).

Warning

For non-18-decimal index tokens (e.g. WBTC with 8 decimals) this property returns a value that is orders of magnitude too small. Use trigger_price_usd_for_decimals() with the correct token decimals in those cases.

Returns

Approximate trigger price in USD (accurate for 18-decimal tokens only).

trigger_price_usd_for_decimals(token_decimals)

Trigger price in USD for a token with token_decimals decimal places.

GMX stores prices with 10^(PRECISION - token_decimals) precision where PRECISION = 30. Use this method when working with tokens other than standard 18-decimal ERC-20s.

Parameters

token_decimals (int) – Decimal places of the index token (e.g. 8 for WBTC, 18 for ETH).

Returns

Trigger price in USD.

Return type

float

property size_delta_usd_human: float

Position size delta as a human-readable USD float.

GMX stores USD amounts with 30-decimal precision ($1 = 10^30).

Returns

Size delta in USD.

property is_stop_loss: bool

Whether this order is a stop loss order.

Returns

True if order_type is STOP_LOSS_DECREASE.

property is_take_profit: bool

Whether this order is a take profit order.

Returns

True if order_type is LIMIT_DECREASE.

property is_limit_increase: bool

Whether this order is a limit increase (entry) order.

Returns

True if order_type is LIMIT_INCREASE.

__init__(order_key, order_type, account, receiver, cancellation_receiver, market, initial_collateral_token, size_delta_usd, initial_collateral_delta_amount, trigger_price, acceptable_price, execution_fee, is_long, is_frozen, auto_cancel, updated_at_time, swap_path)
Parameters
Return type

None

class SLTPEntry

Bases: object

User-friendly SL/TP configuration.

Allows specifying trigger prices as absolute values or percentages, and close sizes as percentages or USD amounts.

Example:

# 5% stop loss, close 100% of position stop_loss = SLTPEntry(trigger_percent=0.05)

# Absolute $1850 stop, close half stop_loss = SLTPEntry(trigger_price=1850, close_percent=0.5)

# $75000 take profit, close $25000 worth take_profit = SLTPEntry(trigger_price=75000, close_size_usd=25000)

Parameters
  • trigger_price – Absolute trigger price in USD (specify ONE of price/percent)

  • trigger_percent – Percentage from entry price (0.05 = 5%)

  • close_percent – Fraction of position to close (0.5 = 50%, 1.0 = 100%)

  • close_size_usd – Absolute USD amount to close

  • auto_cancel – Whether to cancel if primary order fails

  • decrease_amounts – Internal computed amounts

__init__(trigger_price=None, trigger_percent=None, close_percent=1.0, close_size_usd=None, auto_cancel=True, decrease_amounts=None)
Parameters
  • trigger_price (float | None) –

  • trigger_percent (float | None) –

  • close_percent (float) –

  • close_size_usd (float | None) –

  • auto_cancel (bool) –

  • decrease_amounts (eth_defi.gmx.order.sltp_order.DecreaseAmounts | None) –

Return type

None

class SLTPOrder

Bases: eth_defi.gmx.order.base_order.BaseOrder

Stop Loss and Take Profit order management.

Provides methods for creating SL/TP orders both bundled with position opens and as standalone orders for existing positions.

Example:

sltp = SLTPOrder(config, market_key, collateral_address, index_token, is_long=True)

# Bundled: open + SL + TP in one transaction result = sltp.create_increase_order_with_sltp(

size_delta_usd=10000, collateral_amount=1.5, sltp_params=SLTPParams(

stop_loss=SLTPEntry(trigger_percent=0.05), take_profit=SLTPEntry(trigger_percent=0.15),

),

)

# Standalone: add SL to existing position result = sltp.create_stop_loss_order(

position_size_usd=10000, entry=SLTPEntry(trigger_price=1850), entry_price=2000,

)

Initialize SL/TP order with position identification.

Parameters
  • config – GMX configuration instance

  • market_key – Market contract address

  • collateral_address – Collateral token address

  • index_token_address – Index token address

  • is_long – True for long position, False for short

__init__(config, market_key, collateral_address, index_token_address, is_long)

Initialize SL/TP order with position identification.

Parameters
create_stop_loss_order(position_size_usd, entry, entry_price=None, slippage_percent=0.003, execution_buffer=2.2)

Create standalone stop loss for existing position.

Parameters
  • position_size_usd (float) – Total position size in USD

  • entry (eth_defi.gmx.order.sltp_order.SLTPEntry) – Stop loss configuration

  • entry_price (float | None) – Entry price (required if using trigger_percent)

  • slippage_percent (float) – Not used for SL (execution prioritized)

  • execution_buffer (float) – Multiplier for execution fee

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

create_take_profit_order(position_size_usd, entry, entry_price=None, slippage_percent=0.003, execution_buffer=2.2)

Create standalone take profit for existing position.

Parameters
  • position_size_usd (float) – Total position size in USD

  • entry (eth_defi.gmx.order.sltp_order.SLTPEntry) – Take profit configuration

  • entry_price (float | None) – Entry price (required if using trigger_percent)

  • slippage_percent (float) – Slippage tolerance for price protection

  • execution_buffer (float) – Multiplier for execution fee

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

create_increase_order_with_sltp(size_delta_usd, initial_collateral_delta_amount, sltp_params=None, slippage_percent=0.003, swap_path=None, execution_buffer=2.2, auto_cancel=False, data_list=None)

Open position + SL + TP in single atomic transaction.

Creates a bundled multicall transaction that atomically creates: 1. The main increase order 2. Optional stop loss order 3. Optional take profit order

Parameters
  • size_delta_usd (float) – Position size in USD

  • initial_collateral_delta_amount (int | str) – Collateral in token’s smallest unit

  • sltp_params (eth_defi.gmx.order.sltp_order.SLTPParams | None) – SL/TP configuration

  • slippage_percent (float) – Slippage tolerance

  • swap_path (list[str] | None) – Optional swap routing

  • execution_buffer (float) – Multiplier for execution fees

  • auto_cancel (bool) – Auto-cancel main order if can’t execute

  • data_list (list[str] | None) – Additional data for order

Returns

SLTPOrderResult with bundled transaction

Return type

eth_defi.gmx.order.sltp_order.SLTPOrderResult

create_order(params, is_open=False, is_close=False, is_swap=False)

Create an order (public interface).

This is the main public method for creating orders.

Parameters
Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

property markets: eth_defi.gmx.core.markets.Markets

Markets instance for retrieving market information.

Uses cached property pattern for efficiency.

property oracle_prices: eth_defi.gmx.core.oracle.OraclePrices

Oracle prices instance for retrieving current prices.

Uses cached property pattern for efficiency.

order_builder(params, is_open=False, is_close=False, is_swap=False, is_limit=False, trigger_price=None)

Build an order transaction.

Core method that constructs an unsigned transaction for GMX orders. This replaces the original SDK’s order_builder that submitted transactions.

Parameters
  • params (eth_defi.gmx.order.base_order.OrderParams) – Order parameters

  • is_open (bool) – Whether opening a position

  • is_close (bool) – Whether closing a position

  • is_swap (bool) – Whether performing a swap

  • is_limit (bool) – Whether this is a limit order (triggers at specified price)

  • trigger_price (float | None) – USD price at which order triggers (required for limit orders)

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

refresh_cache()

Refresh cached markets and oracle prices data.

Call this method to force a refresh of the cached data if you need the latest market information and prices.

Return type

None

class SLTPOrderResult

Bases: object

Result from creating orders with SL/TP.

Contains execution details and optional standalone transactions.

Parameters
  • transaction – Main bundled transaction (if bundled approach)

  • total_execution_fee – Sum of all execution fees in wei

  • main_order_fee – Execution fee for main order

  • stop_loss_fee – Execution fee for SL order

  • take_profit_fee – Execution fee for TP order

  • entry_price – Entry price used for calculations

  • stop_loss_trigger_price – Computed SL trigger price

  • take_profit_trigger_price – Computed TP trigger price

  • stop_loss_transaction – Standalone SL transaction

  • take_profit_transaction – Standalone TP transaction

__init__(transaction=None, total_execution_fee=0, main_order_fee=0, stop_loss_fee=0, take_profit_fee=0, entry_price=0.0, stop_loss_trigger_price=None, take_profit_trigger_price=None, stop_loss_transaction=None, take_profit_transaction=None)
Parameters
  • transaction (web3.types.TxParams | None) –

  • total_execution_fee (int) –

  • main_order_fee (int) –

  • stop_loss_fee (int) –

  • take_profit_fee (int) –

  • entry_price (float) –

  • stop_loss_trigger_price (float | None) –

  • take_profit_trigger_price (float | None) –

  • stop_loss_transaction (web3.types.TxParams | None) –

  • take_profit_transaction (web3.types.TxParams | None) –

Return type

None

class SLTPParams

Bases: object

Combined SL/TP parameters for bundled creation.

Parameters
  • stop_loss – Stop loss configuration

  • take_profit – Take profit configuration

  • execution_fee_buffer – Multiplier for execution fee

__init__(stop_loss=None, take_profit=None, execution_fee_buffer=1.0)
Parameters
Return type

None

class SwapOrder

Bases: eth_defi.gmx.order.base_order.BaseOrder

GMX Swap Order class for token-to-token swaps.

Handles creation of swap transactions on GMX protocol, providing estimation capabilities and unsigned transaction generation for external signing.

Example:

>TODO: Add example usage

Initialise swap order with token addresses.

Parameters
  • config (GMXConfig) – GMX configuration

  • start_token (ChecksumAddress) – Input token address (hex)

  • out_token (ChecksumAddress) – Output token address (hex)

__init__(config, start_token, out_token)

Initialise swap order with token addresses.

Parameters
  • config (GMXConfig) – GMX configuration

  • start_token (ChecksumAddress) – Input token address (hex)

  • out_token (ChecksumAddress) – Output token address (hex)

create_swap_order(amount_in, slippage_percent=0.005, min_output_amount=0, execution_buffer=2.2, auto_cancel=False)

Create a swap order transaction.

Creates an unsigned transaction for swapping tokens on GMX. The transaction needs to be signed and sent by the user.

Parameters
  • amount_in (int | float) – Amount of input tokens to swap (in token’s smallest unit, e.g., wei)

  • slippage_percent (float) – Maximum acceptable slippage (default 0.5%)

  • min_output_amount (int) – Minimum output amount (0 for auto-calculation)

  • execution_buffer (float) – Gas execution buffer multiplier (default 2.2)

  • auto_cancel (bool) – Whether to auto-cancel if execution fails

Returns

Transaction result with unsigned transaction

Return type

OrderResult

estimate_swap_output(amount_in, market_key=None)

Estimate the output amount and price impact for a swap.

Queries the GMX Reader contract to estimate swap output without executing the transaction.

Parameters
  • amount_in (int) – Amount of input tokens (in token’s smallest unit)

  • market_key (Optional[str]) – Specific market to use (auto-detected if None)

Returns

Dictionary with estimated output and price impact

Return type

dict[str, Any]

Example return value:
{

“out_token_amount”: 950000000, # Output amount in the smallest unit “price_impact_usd”: -0.0025, # Price impact in USD “estimated_output_formatted”: 950.0 # Formatted output amount

}

create_market_swap(amount_in, slippage_percent=0.005, execution_buffer=2.2)

Create a market swap order (CCXT-style method).

Convenience method that matches CCXT trading interface patterns.

Parameters
  • amount_in (int | float) – Amount of input tokens

  • slippage_percent (float) – Slippage tolerance

  • execution_buffer (float) – Gas execution buffer multiplier

Returns

Transaction result

Return type

OrderResult

create_order(params, is_open=False, is_close=False, is_swap=False)

Create an order (public interface).

This is the main public method for creating orders.

Parameters
Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

property markets: eth_defi.gmx.core.markets.Markets

Markets instance for retrieving market information.

Uses cached property pattern for efficiency.

property oracle_prices: eth_defi.gmx.core.oracle.OraclePrices

Oracle prices instance for retrieving current prices.

Uses cached property pattern for efficiency.

order_builder(params, is_open=False, is_close=False, is_swap=False, is_limit=False, trigger_price=None)

Build an order transaction.

Core method that constructs an unsigned transaction for GMX orders. This replaces the original SDK’s order_builder that submitted transactions.

Parameters
  • params (eth_defi.gmx.order.base_order.OrderParams) – Order parameters

  • is_open (bool) – Whether opening a position

  • is_close (bool) – Whether closing a position

  • is_swap (bool) – Whether performing a swap

  • is_limit (bool) – Whether this is a limit order (triggers at specified price)

  • trigger_price (float | None) – USD price at which order triggers (required for limit orders)

Returns

OrderResult with unsigned transaction

Return type

eth_defi.gmx.order.base_order.OrderResult

refresh_cache()

Refresh cached markets and oracle prices data.

Call this method to force a refresh of the cached data if you need the latest market information and prices.

Return type

None

fetch_pending_order_count(web3, chain, account)

Fetch the number of pending orders for an account from the DataStore.

Lightweight check that only calls DataStore.getBytes32Count without fetching full order details. Useful as a quick pre-check before calling fetch_pending_orders().

Parameters
  • web3 (web3.main.Web3) – Web3 instance connected to the target chain.

  • chain (str) – Network name (e.g. "arbitrum", "avalanche").

  • account (eth_typing.evm.HexAddress) – Wallet address to count pending orders for.

Returns

Number of pending orders stored in the DataStore for this account.

Return type

int

fetch_pending_orders(web3, chain, account, order_type_filter=None, market_filter=None, is_long_filter=None)

Fetch pending cancellable limit orders for an account from the GMX Reader.

Only yields cancellable order types:

  • LIMIT_INCREASE (3) — pending entry orders

  • LIMIT_DECREASE (5) — take profit orders

  • STOP_LOSS_DECREASE (6) — stop loss orders

Market orders execute immediately and are excluded from results.

Parameters
  • web3 (web3.main.Web3) – Web3 instance connected to the target chain.

  • chain (str) – Network name (e.g. "arbitrum", "avalanche").

  • account (eth_typing.evm.HexAddress) – Wallet address to query pending orders for.

  • order_type_filter (eth_defi.gmx.constants.OrderType | None) – If provided, only yield orders of this specific type.

  • market_filter (Optional[eth_typing.evm.HexAddress]) – If provided, only yield orders for this market contract address.

  • is_long_filter (bool | None) – If provided, only yield orders matching this direction.

Returns

Iterator of PendingOrder instances matching the filters.

Return type

Iterator[eth_defi.gmx.order.pending_orders.PendingOrder]

Modules

eth_defi.gmx.order.base_order

GMX Base Order Implementation

eth_defi.gmx.order.cancel_order

GMX order cancellation module.

eth_defi.gmx.order.decrease_order

GMX DecreaseOrder class Implementation

eth_defi.gmx.order.increase_order

GMX Increase Order Implementation

eth_defi.gmx.order.order_argument_parser

GMX Order Argument Parser

eth_defi.gmx.order.pending_orders

GMX pending orders module.

eth_defi.gmx.order.sltp_order

GMX Stop Loss and Take Profit Order Implementation

eth_defi.gmx.order.swap_order

GMX Swap Order Implementation