Godex.ai Docs
Offical SiteTwitter/XTelegram
  • πŸ‘‹Welcome to Godex
  • Getting Started
    • πŸ‘οΈOverview
    • πŸ‹Whales Vaults
      • How to Start Follow Whales?
      • Functionalities and Settings
      • Whale Types of Strategies
      • Statistics
      • How trades are performed
    • GoBank
      • Market Overview
      • Gobank Whitepaper
      • Liquidity Protocol
      • Supply or Saving
      • Borrow
      • Repay
      • Withdraw
      • Health Factor
      • Gobank’s Cashback Program
      • FAQ
    • πŸ’±C2C Trading
    • 🐳Copy Trading on DEX Exchange
      • Trader Explorer
      • HOW TO WORK
  • Godex Trading Engine
    • Godex Router Asset (GRA)
    • Smart Order Router
    • GoDex Referral Codes
    • Godex Wzap
  • Shared Liquidity Layer
    • Fees Structure
    • Affiliate Program
    • Partnership Program
  • User Guide
    • C2C Trading
      • How do I buy crypto on C2C trading?
      • What's the C2C Bussiness Program?
      • C2C Trading Legal Disclaimer
    • Use Guideline
      • Create/Import Web3 Wallet
      • How to Follow Whale
      • Bridge/Swap across chains?
      • How to Start/Stop Order with Smart Contract
    • Brand Kit
    • Ecosystem
    • Roadmap
    • πŸ›‘οΈWallet security
    • *️Risk Warning & Liability Disclaimer
  • AML Policy
    • Privacy policy
    • Terms of Use
Powered by GitBook
On this page
  • 🧠 Objective:
  • βœ… Step 1: Understand the Trading Mechanism on GMX
  • βœ… Step 2: Select the Trader to Monitor
  • βœ… Step 3: Monitor Position Opening Transactions
  • βœ… Step 4: Extract Trade Order Details
  • βœ… Step 5: Copy the Trade to the User’s Wallet
  • βœ… Step 6: Add Advanced Features
  • βœ… Sample System Architecture
  • βœ… Resources Used
  1. Getting Started
  2. Copy Trading on DEX Exchange

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

  1. Dashboard:

    • Manage the list of trader wallets being monitored.

    • Display stats such as number of copied trades, total PnL, and remaining capital.

  2. Telegram/Discord Notifications:

    • Alert when a new trade is opened.

    • Notify when the bot successfully copies a trade.

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

+-------------------+
|     User Wallet   |
+-------------------+
        ↑
        |
        | Copy
        ↓
+-------------------+     Monitor      +----------------------+
|     BOT Engine    | <----------------|   Trader Wallet(s)   |
|  (Python/Node.js) |                  |     on GMX.io        |
+--------+----------+                  +----------------------+
         |
         | Trigger
         ↓
+--------------------------+
|     PositionRouter SC    |
| (createIncreasePosition) |
+--------------------------+

βœ… 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/

PreviousTrader ExplorerNextGodex Router Asset (GRA)

Last updated 7 days ago

🐳