This repository contains a proof of concept arbitrage detector written in Rust. It demonstrates real time price evaluation between a decentralised exchange (Uniswap V3) and a centralised exchange (Binance), with explicit modelling of fees, slippage, and gas costs.
This project is not intended for production use. It exists to showcase Rust based system design, numerical correctness, and async IO integration in a financial context.
The detector compares DEX and CEX prices for the ETH/USDC pair and evaluates potential arbitrage opportunities in both directions.
It accounts for:
- CEX trading fees
- DEX LP fees
- Slippage using Uniswap V3 math
- Estimated gas costs
All calculations are performed with explicit assumptions and validated through unit tests.
This project demonstrates:
- Async Rust for real time WebSocket and RPC integration
- Strong type safety around financial and pricing logic
- Modular separation between IO, pricing, and evaluation layers
- Explicit fee, slippage, and gas modelling
- Structured logging for observability
- Unit tests validating core numerical invariants
- DEX pricing via on chain slot0 and Uniswap V3 math (sqrtPriceX96 to price)
- CEX top of book data via Binance WebSocket depth stream
- Arbitrage evaluation in both directions with fee and gas adjustments
- Structured logging of detected opportunities
- Unit tests for core pricing and evaluation logic
- Rust (stable)
- An Ethereum RPC endpoint (Infura or Alchemy free tier is sufficient)
Create a .env file in the project root:
RPC_URL="https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY" POOL_ADDRESS="0x88E6A0c2dDD26FEEb64F039a2c41296FcB3f5640" CEX_WS_URL="wss://stream.binance.com:9443/ws"
MIN_PNL_USDC="0" CEX_FEE_BPS="1.0" DEX_FEE_BPS="1.0" GAS_UNITS="200000" GAS_MULTIPLIER="1"
With Docker:
docker compose up --build
Stop with:
docker compose down
Run locally:
cargo run --release
Tests:
cargo test
-
CEX ingestion
Subscribes to the Binance depth stream and extracts the best bid and ask. -
DEX pricing
Fetches pool state from Ethereum RPC and derives spot price using Uniswap V3 math. -
Target price calculation
Given the CEX bid and ask, computes the required DEX trade size to match those prices, accounting for slippage and fees. -
Evaluation
Calculates potential profit after fees and gas, logging opportunities that exceed the configured threshold.
Order book depth is considered to cap the maximum executable trade size on the CEX side.
- If no opportunities are detected, try setting MIN_PNL_USDC=0
- Reduce DEX_FEE_BPS, CEX_FEE_BPS, or GAS_MULTIPLIER for testing
- Ensure RPC_URL is reachable and POOL_ADDRESS refers to a live pool
These are intentionally left out to keep the project focused:
- Reconnect and backoff logic for WebSocket failures
- Event driven evaluation instead of fixed interval polling
- Improved gas estimation and smoothing
- Multi pool and multi CEX support
- DEX WebSocket subscriptions
- Mempool based price prediction
- Multi tick Uniswap V3 price simulation
This code is provided for educational and demonstration purposes only. It is not audited, not optimised, and not suitable for use with real funds.