Documentation

Everything you need to know

MEXC Manager

How Copy Trading Works

Understanding the technical architecture behind copy trading.

Architecture Overview

Copy trading uses a real-time WebSocket connection to MEXC to monitor the master account's positions:

  1. 1. Connection - MEXC Manager connects to MEXC's WebSocket using the master's API credentials
  2. 2. Subscription - Subscribes to position updates for the master account
  3. 3. Detection - Detects when positions open, close, or change
  4. 4. Execution - Replicates the action on all follower accounts
  5. 5. Logging - Records all activity for review
Master Account (via WebSocket)
↓ Position update detected
↓ "BTC Long opened, 10 contracts"
MEXC Manager
↓ Calculate follower volumes
↓ Execute on all followers
Follower 1: ✓Follower 2: ✓Follower 3: ✓

WebSocket Connection

The copy trading system maintains a persistent WebSocket connection to MEXC:

  • Endpoint - MEXC's contract WebSocket API
  • Authentication - Uses HMAC-SHA256 signature with your API credentials
  • Heartbeat - Ping/pong every 15 seconds to keep connection alive
  • Auto-reconnect - Automatically reconnects if connection drops
WebSocket API Keys

Copy trading requires special WebSocket API credentials from MEXC, which may be different from regular REST API keys. These credentials allow subscribing to private position updates.

Position Detection

The system tracks the following position events:

  • Position Opened - New position detected (volume goes from 0 to X)
  • Position Closed - Position fully closed (volume goes to 0)
  • Position Increased - Added to existing position (volume increased)
  • Position Decreased - Partial close (volume decreased but not to 0)

Execution Flow

When a position change is detected:

Opening Positions

  1. 1. Receive position open event from WebSocket
  2. 2. Extract: symbol, side, volume, leverage, entry price
  3. 3. For each enabled follower:
    • a. Calculate follower volume (master volume × copy ratio)
    • b. Apply max position size limits if configured
    • c. Execute market order on follower account
  4. 4. Record execution results in database
  5. 5. If SL/TP copying enabled, create stop orders
  6. 6. Log the activity

Closing Positions

  1. 1. Receive position close event from WebSocket
  2. 2. Look up corresponding follower positions
  3. 3. For each follower with an open position:
    • a. Close the position at market
    • b. Record P&L
  4. 4. Update position status in database
  5. 5. Log the activity

Parallel Execution

Follower trades execute in parallel for speed:

  • All follower orders are sent simultaneously
  • Independent execution - one failure doesn't affect others
  • Results collected and logged for each account

Connection Status

The copy trading group shows its connection status:

StatusMeaning
ConnectedWebSocket is connected and authenticated. Copying is active.
ConnectingEstablishing WebSocket connection...
ErrorConnection failed. Check credentials or try again.
DisconnectedCopy trading is disabled or stopped.

Reliability Features

  • Auto-reconnect - Reconnects automatically if connection drops
  • Exponential backoff - Increasing delays between reconnect attempts
  • Server restart recovery - Groups automatically restart when server restarts
  • Error logging - All errors are logged for troubleshooting
Internet Connectivity

Copy trading requires a stable internet connection. If the connection to MEXC drops, positions won't be copied until it reconnects. Open positions on followers will remain until the master closes and the connection is restored.

Next Steps