HOW TO WORK
π§ Objective:
Develop a BOT that monitors a traderβs wallet on GMX.io, detects when they open or close Long or Short positions, and automatically replicates those trades to the userβs wallet (copy trading).
β
Step 1: Understand the Trading Mechanism on GMX
GMX is a decentralized perpetual exchange (perpetual DEX) that operates without an order book, relying instead on smart contracts.
GMX uses the PositionRouter contract to open positions.
All trader transactions can be tracked on Arbiscan or via RPC/WS nodes.
Wallets typically interact with the PositionRouter contract to open and close positions.
β
Step 2: Select the Trader to Monitor
Identify a notable traderβs wallet (via communities, on-chain analysis, or tools like DeBank, Arkham, Lookonchain, etc.).
Record the wallet address to be monitored.
β
Step 3: Monitor Position Opening Transactions
Option 1: Use Arbiscan API (simpler but delayed)
Query getInternalTransactionsByAddress or getLogs to check for interactions with the PositionRouter contract.
Filter by the following function signatures:
createIncreasePosition
createDecreasePosition
executeIncreaseOrder
cancelIncreaseOrder
Option 2: Use Web3 WebSocket (real-time)
Use Web3.py or ethers.js to connect to an Arbitrum WebSocket (WS) node.
Subscribe to events emitted by the PositionRouter contract (such as order creation, cancellation, or execution).
β
Step 4: Extract Trade Order Details
Once a position opening event (IncreasePosition) is detected, extract the following data:
tokenIn: Token used for margin (e.g., USDC)
indexToken: The asset being traded (e.g., ETH, BTC)
isLong: True/False (indicating Long or Short)
sizeDelta: Trade size in USD
acceptablePrice: Target execution price
executionFee: Gas fee
leverage: Calculated from sizeDelta and collateralDelta
β
Step 5: Copy the Trade to the Userβs Wallet
Send a similar order using the PositionRouter contract by calling createIncreasePosition(...) from the userβs wallet.
Use Web3.py or ethers.js to interact with the contract, passing in the same parameters as the trader (optionally adjusted based on your own capital ratio).
β
Step 6: Add Advanced Features
Dashboard:
Manage the list of trader wallets being monitored.
Display stats such as number of copied trades, total PnL, and remaining capital.
Telegram/Discord Notifications:
Alert when a new trade is opened.
Notify when the bot successfully copies a trade.
Auto Capital Scaling:
Example: If the trader uses 10,000 USDC to open a Long position, the bot can replicate it with 1,000 USDC (10%).
β
Sample System Architecture
β
Resources Used
GMX Contracts: https://github.com/gmx-io/gmx-contracts
ABI of PositionRouter: Can be obtained from Arbiscan
GMX Documentation: https://gmxio.gitbook.io/gmx/
Last updated