gmx.order_tracking
Documentation for eth_defi.gmx.order_tracking Python module.
GMX order status tracking.
This module provides utilities for tracking GMX order execution status. GMX uses a two-phase order process:
Order Creation - User submits order, receives OrderCreated event
Keeper Execution - Keeper executes order (separate tx), receives OrderExecuted or OrderCancelled
The functions in this module help track when orders transition from pending to executed/cancelled by:
Primary method: Querying Subsquid GraphQL indexer (faster, more reliable)
Fallback method: Scanning EventEmitter logs via RPC (if Subsquid unavailable)
Example usage:
from eth_defi.gmx.order_tracking import check_order_status
# Check if order has been executed
result = check_order_status(web3, order_key, "arbitrum")
if result.is_pending:
print("Order still waiting for keeper execution")
elif result.execution_receipt:
print(f"Order executed in tx: {result.execution_tx_hash}")
Module Attributes
GMX DataStore ORDER_LIST key - keccak256("ORDER_LIST") Pending orders are stored in this list and removed after execution/cancellation |
Functions
|
Check if a GMX order is still pending or has been executed/cancelled. |
|
Quick check if an order is still pending in the DataStore. |
Classes
Result of checking order status in GMX DataStore. |
- ORDER_LIST_KEY = b'\x86\xf7\xcf\xd5\xd8\xf8@NQE\xc9\x1b\xeb\xb8HFWB\x01Y\xda\xbd\x07S\xd6\xa5\x9f=\xe3\xf7\xb8\xc1'
GMX DataStore ORDER_LIST key - keccak256(“ORDER_LIST”) Pending orders are stored in this list and removed after execution/cancellation
- class OrderStatusResult
Bases:
objectResult of checking order status in GMX DataStore.
- Variables
is_pending – Whether the order is still pending (waiting for keeper execution)
execution_tx_hash – Transaction hash of the keeper execution (if order is no longer pending)
execution_receipt – Full transaction receipt of the keeper execution
execution_block – Block number where the order was executed/cancelled
- check_order_status(web3, order_key, chain, search_blocks=1000, subsquid_timeout=10, subsquid_max_retries=5, subsquid_initial_delay=2.0, creation_block=None, wait_for_indexer=False, wait_for_indexer_timeout=60.0)
Check if a GMX order is still pending or has been executed/cancelled.
This function first checks the DataStore to see if the order exists in the pending orders list. If not, it queries Subsquid GraphQL indexer (primary) or falls back to scanning EventEmitter logs via RPC.
- Parameters
web3 (web3.main.Web3) – Web3 instance connected to the appropriate chain
order_key (bytes) – The 32-byte order key from the OrderCreated event
chain (str) – Chain name (“arbitrum”, “avalanche”, or “arbitrum_sepolia”)
search_blocks (int) – Number of recent blocks to search for execution events via RPC fallback. Only used if creation_block is not provided. (default: 1000)
subsquid_timeout (int) – Timeout in seconds for each Subsquid query attempt (default: 10)
subsquid_max_retries (int) – Maximum retry attempts for Subsquid queries (default: 5)
subsquid_initial_delay (float) – Initial delay between Subsquid retries in seconds (default: 2.0)
creation_block (int | None) – Block number where the order was created. If provided, log scanning will start from this block instead of (current_block - search_blocks). This enables accurate scanning after bot restarts.
wait_for_indexer (bool) – If True, keep polling Subsquid until indexer catches up (for fresh orders). Useful when checking status immediately after order creation.
wait_for_indexer_timeout (float) – Maximum time to wait for Subsquid indexer to catch up (default: 60s)
- Returns
OrderStatusResult with pending status and execution details if available
- Return type
Example:
from eth_defi.gmx.order_tracking import check_order_status from eth_defi.gmx.events import extract_order_key_from_receipt # After order creation order_key = extract_order_key_from_receipt(web3, creation_receipt) # Poll for execution while True: result = check_order_status(web3, order_key, "arbitrum") if not result.is_pending: break time.sleep(2) # Now verify the execution if result.execution_receipt: verification = verify_gmx_order_execution(web3, result.execution_receipt, order_key)
- is_order_pending(web3, order_key, chain)
Quick check if an order is still pending in the DataStore.
This is a lighter-weight alternative to check_order_status() when you only need to know if the order is still pending, without needing the execution receipt.