Skip to content

frederickpek/px

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CEX <> DEX Arbitrage Bot (Binance & Uniswap)

Light-weight and performance-optimized arbitrage bot that monitors price discrepancies between Binance (CEX) and Uniswap V3 (DEX) for the ETH/USDT pair. It is designed for robust, low-latency execution and can be extended to other pairs or exchanges.

Features

  • Monitors real-time prices from Binance and Uniswap v3
  • Executes arbitrage trades when profitable opportunities are detected
  • Handles process management, shared memory, and event-driven execution
  • Includes mock mode for safe testing (no real trades)

Requirements

  • Python 3.10+

Setup

  1. Clone the repository
  2. Create a virtual environment:
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Configure environment variables:
    • Set your Binance and Ethereum credentials in your environment or .env file if running in real mode.
  5. (Optional) Disable mock mode:
    • By default, mock_mode=True in constants.py will mock CEX and DEX executions for safe testing.
  6. Run the bot:
    python main.py

Logical Flow

Logical Flow

Description:

  • The bot continuously polls both Binance and Uniswap for the latest ETH/USDT prices.
  • When a profitable arbitrage opportunity is detected (based on a configurable bps threshold), it triggers simultaneous order execution on both CEX and DEX.
  • The bot tracks the status and execution price of each leg, and logs all outcomes.
  • If one leg fails, the bot attempts to resolve by retrying or reversing the trade on CEX due to stability.
  • Note: Rebalancing (restoring inventory between CEX and DEX) is skipped in this implementation.

Sample Logs

The following logs were generated with mock_mode=true (no real trades executed):

Sample Logs


Note:

  • The default configuration is safe for testing. To enable real trading, set mock_mode=False in constants.py and provide valid API keys and wallet credentials.
  • For more details, see comments in the code and constants in constants.py.

About

CEX <> DEX Arbitrage Bot

Resources

Stars

Watchers

Forks

Languages