jackyu66git ab48e207a5 Fix 3 arbitrage logic issues from code review
Issue #1 (critical): reProfit false positive on price reversal
  executeEntry used CalcNetProfit which auto-swaps prices when
  hlP < bgP. If prices flipped between scan and execution, reProfit
  reported positive even when direction was now wrong.
  Fix: use netProfit() with explicit direction + verify spread
  direction hasn't flipped (hlP <= bgP prevents BG->HL when
  HL is no longer more expensive).

Issue #2 (medium): Scale-in was paper-only, didn't place orders
  Now actually places additional orders on both legs via new
  placeOrderAt(). Test mode uses mock fills. Live mode sends
  real API orders. AmountUSD properly tracks total deployed
  capital. Partial fill handled gracefully (don't close main leg).

Issue #3 (minor): closeLeg missing ExitTime on mock mode
2026-05-03 18:19:25 +08:00
2026-05-03 17:28:08 +08:00
2026-05-03 17:50:42 +08:00
2026-05-03 16:54:36 +08:00
2026-05-03 16:54:36 +08:00
2026-05-03 18:05:19 +08:00
2026-05-03 17:28:08 +08:00
2026-05-03 17:28:08 +08:00
2026-05-03 16:54:36 +08:00
2026-05-03 16:54:36 +08:00
2026-05-03 16:54:36 +08:00
2026-05-03 16:54:36 +08:00

Exchange Monitor Go

Cross-exchange perpetual futures arbitrage scanner and automated trading system. Monitors real-time prices from 4 exchanges via WebSocket, identifies arbitrage opportunities, and executes maker-fee trades between Bitget and HyperLiquid.

Architecture

                       ┌──────────────┐
        ┌──────────────┤   Binance    │◄──── bookTicker WS
        │              └──────────────┘
        │              ┌──────────────┐
        │──────────────┤   Bitget     │◄──── ticker WS (trading exchange)
        │              └──────────────┘
PriceStore (sync.Map) ─┼──────────────┤
        │              │ HyperLiquid  │◄──── webData2 WS (trading exchange)
        │              └──────────────┘
        │              ┌──────────────┐
        └──────────────┤    dYdX      │◄──── v4_markets WS
                       └──────────────┘
                              │
                    ┌─────────▼─────────┐
                    │   Scanner (500ms)  │
                    │  ScanArbWithFees() │
                    └─────────┬─────────┘
                              │
              ┌───────────────▼────────────────┐
              │  Trader: TryEntry / Tick / Exit │
              │  Maker fees, scale-in, stop     │
              └───────────────┬────────────────┘
                              │
                    ┌─────────▼─────────┐
                    │   Notifier: TG     │
                    └───────────────────┘

Tracked Coins

Coin Binance Bitget HyperLiquid dYdX
DOGE DOGEUSDT DOGEUSDT DOGE DOGE-USD
LINK LINKUSDT LINKUSDT LINK LINK-USD
ONDO ONDOUSDT ONDOUSDT ONDO ONDO-USD
OP OPUSDT OPUSDT OP OP-USD
WIF WIFUSDT WIFUSDT WIF WIF-USD
ARB ARBUSDT ARBUSDT ARB ARB-USD

Requirements

  • Go 1.21+
  • WebSocket connectivity to all 4 exchanges

Quick Start

# Build
cd exchange-monitor-go
go build -o exchange-monitor .

# Configure (copy and edit)
cp .env.example .env
# Set TRADE_THRESHOLD, TRADE_AMOUNT_USD, API keys, etc.

# Run (test mode, no real trades)
./exchange-monitor

# Run with Telegram notifications
TELEGRAM_BOT_TOKEN=xxx TELEGRAM_CHAT_ID=xxx ./exchange-monitor

Configuration (.env)

Variable Default Description
TRADE_ENABLED false Enable real trading (1 to enable)
TRADE_THRESHOLD 0.1 Min net profit % to enter (round trip after fees)
TRADE_AMOUNT_USD 5 USD per leg
TRADE_COOLDOWN_MS 30000 Cooldown between same-coin trades
TEST_MODE true Simulate orders (no real API calls)
MOCK_SLIPPAGE_PCT 0.005 Simulated slippage per leg (%)

Fee Model

Maker fees (limit orders), no rebate:

Exchange Maker Taker
Bitget 0.020% 0.040%
HyperLiquid 0.015% 0.035%
Binance 0.020% 0.040%

Round trip (2 legs entry + 2 legs exit): 0.07%

Trading Logic

  1. Scanner runs every 500ms, checks all 10 exchange pairs
  2. Entry when net profit ≥ TRADE_THRESHOLD (after full round-trip fees)
  3. Scale-in adds $5 per leg when spread widens another 0.10%
  4. Exit when spread converges to ≤0.02%, or 30 min timeout
  5. Only BG ↔ HL — other exchanges are price references only

Disclaimer

This software is for educational/research purposes. Use at your own risk. Cryptocurrency trading involves substantial risk of loss.

S
Description
No description provided
Readme
33 MiB
Languages
Go 73.6%
JavaScript 20.2%
CSS 4.6%
Shell 1.1%
HTML 0.5%