Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

My First Manually Developped Working Arbitrage System

Cross-Exchange Crypto Arbitrage Scanner

A real-time arbitrage opportunity scanner that monitors spot prices across multiple cryptocurrency exchanges simultaneously and logs price discrepancies that meet a configurable profit threshold.

Note: This bot is a logging/detection tool only. It does not place any orders or move any funds.


What It Does

  • Fetches live bid/ask prices from 4 exchanges concurrently using asyncio
  • Normalizes ticker symbols across exchanges into a unified format
  • Identifies pairs available on more than one exchange
  • Detects when the ask price on one exchange is lower than the bid price on another
  • Logs every opportunity with the buy exchange, sell exchange, prices, and spread percentage
  • Repeats every configurable interval (default: 5 seconds)

Exchanges Supported

Exchange Method
Bybit Official SDK (pybit)
MEXC REST API
Gate.io REST API
BingX REST API

How It Works

1. Pair Discovery (load_pairs)

On startup, the bot fetches all available spot pairs from every exchange and finds the intersection — pairs listed on at least two exchanges. This becomes the working list to monitor.

2. Data Fetching (get_bid_ask)

Every cycle, all four exchanges are queried simultaneously using asyncio.gather. Each exchange returns normalized dicts:

{"exchange": "bybit", "symbol": "BTCUSDT", "bid_price": 67200.0, "ask_price": 67205.0}

3. Structuring & Sorting (structure_by_pairs_and_sort)

Data is grouped by symbol. For each symbol, exchanges are sorted by:

  • Best ask (lowest) — cheapest place to buy
  • Best bid (highest) — most expensive place to sell

4. Opportunity Detection (check_for_opportunity)

For each symbol, the spread is calculated:

spread = (best_bid - best_ask) / best_bid

If spread >= Minimum_Arbi (default: 0.5%), it's logged as an opportunity.

5. Notification (notify_opportunity)

Currently logs to console. Designed to be extended with Telegram or other notification systems.


Project Structure

arbitrage_bot/
├── main.py          # All logic — Config, Call, Exchange classes, Engine, Notify
└── requirements.txt

Configuration

Inside main.py, edit the Config class:

class Config:
    Check_Arbi_Interval = 5    # Seconds between each scan cycle
    Minimum_Arbi        = 0.5  # Minimum spread % to log as opportunity

Installation

git clone https://github.com/yourusername/arbitrage-scanner.git
cd arbitrage-scanner
pip install -r requirements.txt
python main.py

Requirements:

pybit
requests

Sample Output

Total eligible pairs to trade: 1435
==================================================================================================================================
Arbitrage opportunity Buy BTCUSDT for 67200.0 at gate_io and Sell at bybit for 67850.0  Arbitrage opportunity: 0.958%
Arbitrage opportunity Buy ETHUSDT for 3521.0 at mexc and Sell at bybit for 3548.0  Arbitrage opportunity: 0.761%

Known Limitations

  • Symbol collision: Some tokens share the same ticker symbol across exchanges but are different assets. Opportunities showing spreads above ~5% are likely false positives caused by this. A contract-address verification layer (via CoinGecko API) would resolve this.
  • Transfer delay: Cross-exchange arbitrage requires on-chain fund transfers which take minutes. This scanner is best used to study market inefficiencies, not for high-frequency execution.
  • No execution: This is detection only. Adding order placement requires exchange API keys and careful risk management.

Extending This Bot

  • Telegram alerts — integrate aiogram inside the Notify class
  • File logging — replace print with Python's logging module to persist opportunities to disk
  • Symbol verification — query CoinGecko API to confirm same contract address before flagging as opportunity
  • Execution layer — add order placement through each exchange's authenticated API endpoints

Author

Built from scratch as a Python portfolio project covering async programming, multi-API integration, and real-time data normalization.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages