AB

Cross-Exchange Arb

LIVE

Perpetual spread arbitrage between Bybit and MEXC. Passive anchor + market hedge strategy, FSM order lifecycle, inventory tracking. 10K+ LOC production system.

Key Numbers

At a Glance

10K+ LOC

Codebase

2

Venues

100%

State Recovery

Passive Anchor

Strategy

Overview

About This Project

A perpetual futures spread arbitrage system capturing price dislocations between Bybit and MEXC. The 10,000+ line production codebase implements a passive anchor strategy -- posting limit orders on one venue at favorable prices, then hedging with market orders on the other when filled -- to capture the spread while minimizing taker fees.

Every order passes through a finite state machine that manages the full lifecycle: creation, partial fill, full fill, cancellation, timeout, and error recovery. This deterministic state management ensures the system always knows its exact position across both venues, even through network failures and exchange outages.

SQLite persistence guarantees crash recovery: the bot can restart from any point and resume operations with zero position ambiguity. An Express.js dashboard provides real-time monitoring of spread dynamics, order state, inventory levels, and cumulative P&L.

Features

What It Does

Passive Anchor Strategy

Posts limit orders on one venue at favorable spread levels, then hedges with market orders on the other when filled. Captures the spread while paying only one side of taker fees.

FSM Order Lifecycle

Finite state machine manages each order through creation, partial fill, full fill, cancellation, and error states with automatic recovery and timeout handling.

Inventory Tracking & Rebalancing

Real-time net exposure tracking across venues with automatic rebalancing triggers prevents dangerous inventory accumulation during volatile periods.

Crash-Resistant Persistence

All positions, orders, and P&L stored in SQLite for guaranteed crash recovery. The bot resumes from exact state after restart with zero position ambiguity.

Real-Time Dashboard

Express.js monitoring dashboard displays live spread dynamics, order state, inventory levels, and cumulative performance metrics.

Architecture

How It Works

$

Challenges

What Made This Hard

The core risk in cross-exchange arbitrage is leg risk: one side fills but the hedge side's price moves away. The passive anchor approach reduces but doesn't eliminate this. Managing exchange-specific WebSocket quirks -- reconnection logic, message sequence gaps, rate limits, and different position denomination conventions -- while maintaining strict state consistency across two independent venues demanded rigorous testing and failure injection.

Stack

Tech Stack

Node.jsSQLiteWebSocketExpress