Binance Arbitrage
Binance cash-and-carry arbitrage bot
Binance arbitrage bot - opportunity detector & automated trading for cash-and-carry arbitrage The project is written primarily in Python, first published in 2022. Key topics include: arbitrage-bot, arbitrage-trading, automated-trading-bot, binance, bitcoin.
Binance-Arbitrage
Binance arbitrage bot - opportunity detector & automated trading for cash-and-carry arbitrage
<img src='./imgs/demo3.png' width=90% height=50% />Basics
1. Arbitrage Process
- Repeated detection for trading opportunity
- Open positions:
- Open long in Spot account
- Universal account transfer:Spot account -> COIN-M Account
- Open short in COIN-M account
- Close positions:
- Close short in COIN-M account
- Universal account transfer:COIN-M account -> Spot Account
- Close long in Spot account
2. Scripts
Config.py:Account & multiplier informationBinanceArb.py: Arbitrage bot for BinanceLogger.py:Logger configurationdetect_spread.py:Spread detectionbasis_trading.py:Open/Close positions
Getting Started
1. Install Prerequisites
- Install CCXT:
conda create -n binance_arb python=3.8pip install ccxtpip install urllib3==1.25.8- Check whether installation is successful:
Pythonimport ccxt exchange = ccxt.binance() data = exchange.fetch_ticker(symbol='BTC/USDT') print(data)
- Install other required packages, such as pandas, coloredlogs
2. Fill in Hyperparameters for Arbitrage Bot
- Fill your api key and secret in
Config.py - Change the hyperparameters in
detect_spread.py - Change the hyperparameters in
basis_trading.py
3. Execute Arbitrage
Run the following command in terminal:
# Spread detection
python detect_spread.py
# Arbitrage trading
python basis_trading.py --coin 'BTC' --future_date '221230' --amount 1000 --threshold 0.02
# Hyperparameter settings:
--coin Trading Target
--future_date expiration date for delivery contract
--coin_precision price precision (decimal points)
--slippage slippage (proportion of crypto price)
--spot_fee_rate commission rate for spot
--contract_fee_rate commission rate for contract
--max_trial maximum trial for stable connections
--amount trading amount for one iteration
--num_maximum maximum execution numbers
--threshold opening/closing threshold
Adjust hyperparameters for your need.
Important
The code is well-organized for further extention to OKX, bitfinex, etc.
But take care of the following information before employment:
- Open universal account transfer for your API
- Check your multiplier for coin-margin
- Check your trading fee
TimeInForce: choices for placing orders- GTC - Good Till Cancel
- IOC - Immediate or Cancel
- FOK - Fill or Kill
- GTX - Good Till Crossing
- Internet connections and error handling
Real Trading Demo
Account Transfer
<img src='./imgs/demo2.png' width=90% height=50% />Close Positions
<img src='./imgs/demo1.png' width=90% height=50% />Contributors
Showing top 1 contributor by commit count.
This article is auto-generated from bradleyboyuyang/Binance-Arbitrage via the GitHub API.Last fetched: 6/29/2026
