Binance-Arbitrage
Binance-Arbitrage copied to clipboard
Binance cash-and-carry arbitrage bot
Binance-Arbitrage
Binance arbitrage bot - opportunity detector & automated trading for cash-and-carry arbitrage

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 information -
BinanceArb.py
: Arbitrage bot for Binance -
Logger.py
:Logger configuration -
detect_spread.py
:Spread detection -
basis_trading.py
:Open/Close positions
Getting Started
1. Install Prerequisites
- Install CCXT:
-
conda create -n binance_arb python=3.8
-
pip install ccxt
-
pip install urllib3==1.25.8
- Check whether installation is successful:
-
import 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

Close Positions
