Binance arbitrage bot - opportunity detector & automated trading for cash-and-carry arbitrage
- 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
Config.py
:Account & multiplier informationBinanceArb.py
: Arbitrage bot for BinanceLogger.py
:Logger configurationdetect_spread.py
:Spread detectionbasis_trading.py
:Open/Close positions
- 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
- Fill your api key and secret in
Config.py
- Change the hyperparameters in
detect_spread.py
- Change the hyperparameters in
basis_trading.py
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.
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