gmx.order

Documentation for eth_defi.gmx.order Python module.

GMX Order Module

This module provides classes for creating GMX trading and liquidity orders.

Trading Orders (inherit from BaseOrder):
  • IncreaseOrder: Open or increase positions

  • DecreaseOrder: Close or decrease positions

  • SwapOrder: Token swaps

  • SLTPOrder: Stop Loss and Take Profit orders

Liquidity Orders:
Base Classes:
  • Deposit: Base class for adding liquidity to markets

  • Withdraw: Base class for removing liquidity from markets

Convenience Wrappers:
  • DepositOrder: Simplified deposit interface

  • WithdrawOrder: Simplified withdrawal interface

All order classes return unsigned transactions for external signing, following the eth_defi library pattern.

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
  • 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
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 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 (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
  • transaction (web3.types.TxParams) –

  • execution_fee (int) –

  • acceptable_price (int) –

  • mark_price (float) –

  • gas_limit (int) –

  • estimated_price_impact (Optional[float]) –

  • price_sanity_check (Optional[PriceSanityCheckResult]) –

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 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 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

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 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
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=3.0)
Parameters
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 DecreaseAmounts

Bases: object

Core decrease order amounts - mirrors GMX DecreasePositionAmounts.

Used internally for contract-level decrease order parameters.

Parameters
  • size_delta_usd – Position size to close in 30 decimal precision

  • collateral_delta_amount – Collateral to withdraw (token decimals)

  • trigger_price – Price that activates the order (30 decimals)

  • acceptable_price – Worst acceptable execution price (30 decimals)

  • trigger_order_type – OrderType.LIMIT_DECREASE or OrderType.STOP_LOSS_DECREASE

  • is_full_close – Whether this closes the entire position

  • min_output_usd – Minimum output in USD (30 decimals)

  • decrease_swap_type – 0=NoSwap, 1=SwapPnlToCollateral, 2=SwapCollateralToPnl

__init__(size_delta_usd, collateral_delta_amount=0, trigger_price=None, acceptable_price=0, trigger_order_type=None, is_full_close=False, min_output_usd=0, decrease_swap_type=0)
Parameters
Return type

None

calculate_trigger_price(entry_price, trigger_percent, is_long, order_type)

Calculate absolute trigger price from percentage.

For Stop Loss:
  • Long: entry_price * (1 - trigger_percent) [price goes down]

  • Short: entry_price * (1 + trigger_percent) [price goes up]

For Take Profit:
  • Long: entry_price * (1 + trigger_percent) [price goes up]

  • Short: entry_price * (1 - trigger_percent) [price goes down]

Parameters
  • entry_price (float) – The position entry price

  • trigger_percent (float) – Percentage as decimal (0.05 = 5%)

  • is_long (bool) – Whether this is for a long position

  • order_type (eth_defi.gmx.constants.OrderType) – STOP_LOSS_DECREASE or LIMIT_DECREASE

Returns

Calculated trigger price

Return type

float

calculate_acceptable_price(trigger_price, is_long, order_type, slippage_percent, index_token_decimals)

Calculate acceptable price for contract.

For Stop Loss: Prioritize execution (0 for longs, MAX_UINT256 for shorts) For Take Profit: Apply slippage protection

Uses Decimal to avoid floating point precision errors.

Parameters
  • trigger_price (float) – The trigger price in USD

  • is_long (bool) – Whether this is for a long position

  • order_type (eth_defi.gmx.constants.OrderType) – STOP_LOSS_DECREASE or LIMIT_DECREASE

  • slippage_percent (float) – Slippage tolerance as decimal (0.003 = 0.3%)

  • index_token_decimals (int) – Decimals of the index token

Returns

Acceptable price in contract format (30 decimal precision)

Return type

int

get_trigger_threshold_type(order_type, is_long)

Determine if order triggers above or below price.

Take Profit (LimitDecrease): Long triggers ABOVE, Short triggers BELOW Stop Loss (StopLossDecrease): Long triggers BELOW, Short triggers ABOVE

Parameters
Returns

“>” if triggers above price, “<” if triggers below

Return type

str

Modules

eth_defi.gmx.order.base_order

GMX Base Order Implementation

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.sltp_order

GMX Stop Loss and Take Profit Order Implementation

eth_defi.gmx.order.swap_order

GMX Swap Order Implementation