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):
IncreaseOrder— open or increase a positionDecreaseOrder— close or decrease a positionSwapOrder— token swapSLTPOrder— bundled stop-loss / take-profit order
Cancel helpers:
CancelOrder— cancel a single or batch of pending ordersCancelOrderResult— result of a single cancellationBatchCancelOrderResult— result of a batch cancellation
SL/TP building blocks:
SLTPEntry— defines one SL or TP legSLTPParams— parameters for a full SL/TP bundleSLTPOrderResult— result returned after placing a SL/TP bundle
Pending order helpers:
PendingOrder— on-chain pending order data classfetch_pending_orders()— fetch all open orders for an accountfetch_pending_order_count()— count open orders for an account
Base / parameter types:
BaseOrder— abstract base for all trading ordersOrderParams— common order parameter containerOrderResult— result returned after placing an orderOrderArgumentParser— helper for resolving human-readable token/market arguments into on-chain parameters
- class BaseOrder
Bases:
objectBase 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
config (GMXConfig) – GMX configuration instance
price_sanity_config (PriceSanityCheckConfig | None) – Optional configuration for price sanity checks
- __init__(config, price_sanity_config=None)
Initialize the base order with GMX configuration.
- Parameters
config (GMXConfig) – GMX configuration instance
price_sanity_config (PriceSanityCheckConfig | None) – Optional configuration for price sanity checks
- 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
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
- Returns
OrderResult with unsigned transaction
- Return type
- 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
- class BatchCancelOrderResult
Bases:
objectResult of building a batch order cancellation transaction.
Multiple
cancelOrdercalls are batched into a singlemulticalltransaction for gas efficiency.The
transactionis an unsignedTxParamsdict that must be signed before submission.- transaction: web3.types.TxParams
Unsigned transaction ready for signing and submission
- class CancelOrder
Bases:
objectBuilds unsigned transactions to cancel pending GMX limit orders.
Does not extend
BaseOrderbecause 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 amulticallcall. No ETH value is sent.- Parameters
order_key (bytes) – The 32-byte key identifying the order to cancel. Obtain this from
order_keyor from a previous order creation receipt.execution_buffer (float) – Multiplier applied to
web3.eth.gas_priceto set the cancel transaction’smaxFeePerGas. Uses the same basis as open/close/sltp keeper fee calculations so gas costs are comparable. Defaults toDEFAULT_EXECUTION_BUFFER.
- Returns
CancelOrderResultwith the unsigned transaction.- Raises
ValueError – If no wallet address is configured in GMX config.
- Return type
- cancel_orders(order_keys, execution_buffer=2.2)
Build an unsigned transaction to cancel multiple pending orders at once.
Batches all
cancelOrdercalls into a singlemulticalltransaction for gas efficiency. Gas limit scales linearly with the number of orders.- Parameters
- Returns
BatchCancelOrderResultwith the unsigned multicall transaction.- Raises
ValueError – If
order_keysis empty or no wallet address is configured.- Return type
- class CancelOrderResult
Bases:
objectResult of building a single order cancellation transaction.
The
transactionis an unsignedTxParamsdict that must be signed before submission.- transaction: web3.types.TxParams
Unsigned transaction ready for signing and submission
- class DecreaseOrder
Bases:
eth_defi.gmx.order.base_order.BaseOrderGMX 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
- __init__(config, market_key, collateral_address, index_token_address, is_long)
Initialize decrease order with position identification.
- Parameters
- 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
- 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
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
- Returns
OrderResult with unsigned transaction
- Return type
- 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
- 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.BaseOrderGMX 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
- __init__(config, market_key, collateral_address, index_token_address, is_long)
Initialise increase order with position identification.
- Parameters
- 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
- 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
- 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
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
- Returns
OrderResult with unsigned transaction
- Return type
- 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
- 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:
objectParses 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.
- 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.
- static find_market_key_by_index_address(input_dict, index_token_address)
Find market key by index token address.
Normalises
index_token_addressto EIP-55 checksum form before comparing against stored market entries (which are already checksummed byMarkets).
- calculate_missing_position_size_info_keys()
Calculate missing parameters from size/collateral/leverage combinations.
- class OrderParams
Bases:
objectOrder 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
- Return type
None
- class OrderResult
Bases:
objectResult 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)
- class PendingOrder
Bases:
objectA 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_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
- 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 by10^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 wherePRECISION = 30. Use this method when working with tokens other than standard 18-decimal ERC-20s.
- 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
Trueiforder_typeisSTOP_LOSS_DECREASE.
- property is_take_profit: bool
Whether this order is a take profit order.
- Returns
Trueiforder_typeisLIMIT_DECREASE.
- property is_limit_increase: bool
Whether this order is a limit increase (entry) order.
- Returns
Trueiforder_typeisLIMIT_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
order_key (bytes) –
order_type (eth_defi.gmx.constants.OrderType) –
account (eth_typing.evm.HexAddress) –
receiver (eth_typing.evm.HexAddress) –
cancellation_receiver (eth_typing.evm.HexAddress) –
market (eth_typing.evm.HexAddress) –
initial_collateral_token (eth_typing.evm.HexAddress) –
size_delta_usd (int) –
initial_collateral_delta_amount (int) –
trigger_price (int) –
acceptable_price (int) –
execution_fee (int) –
is_long (bool) –
is_frozen (bool) –
auto_cancel (bool) –
updated_at_time (int) –
swap_path (list[eth_typing.evm.HexAddress]) –
- Return type
None
- class SLTPEntry
Bases:
objectUser-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)
- class SLTPOrder
Bases:
eth_defi.gmx.order.base_order.BaseOrderStop 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
config (eth_defi.gmx.config.GMXConfig) – GMX configuration instance
market_key (eth_typing.evm.ChecksumAddress) – Market contract address
collateral_address (eth_typing.evm.ChecksumAddress) – Collateral token address
index_token_address (eth_typing.evm.ChecksumAddress) – Index token address
is_long (bool) – True for long position, False for short
- 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
- 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
- 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
execution_buffer (float) – Multiplier for execution fees
auto_cancel (bool) – Auto-cancel main order if can’t execute
- Returns
SLTPOrderResult with bundled transaction
- Return type
- 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
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
- Returns
OrderResult with unsigned transaction
- Return type
- 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
- 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:
objectResult 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:
objectCombined 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
stop_loss (eth_defi.gmx.order.sltp_order.SLTPEntry | None) –
take_profit (eth_defi.gmx.order.sltp_order.SLTPEntry | None) –
execution_fee_buffer (float) –
- Return type
None
- class SwapOrder
Bases:
eth_defi.gmx.order.base_order.BaseOrderGMX 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
- 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
- Returns
Dictionary with estimated output and price impact
- Return type
- 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
- Returns
Transaction result
- Return type
- 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
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
- Returns
OrderResult with unsigned transaction
- Return type
- 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
- 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.getBytes32Countwithout fetching full order details. Useful as a quick pre-check before callingfetch_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
- 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 ordersLIMIT_DECREASE(5) — take profit ordersSTOP_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
PendingOrderinstances matching the filters.- Return type
Modules
|
GMX Base Order Implementation |
|
GMX order cancellation module. |
|
GMX DecreaseOrder class Implementation |
|
GMX Increase Order Implementation |
|
GMX Order Argument Parser |
|
GMX pending orders module. |
|
GMX Stop Loss and Take Profit Order Implementation |
|
GMX Swap Order Implementation |