A Python-based cryptocurrency trading bot that identifies and executes triangular arbitrage opportunities across multiple trading pairs on Binance.
This bot continuously monitors cryptocurrency trading pairs to find profitable triangular arbitrage opportunities. It specifically looks for price discrepancies between three trading pairs that form a cycle, starting and ending with a stablecoin (USDT, USDC, BUSD, or FDUSD).
- Multi-threaded price monitoring and trade execution
- Supports multiple stablecoins as base currencies
- Configurable profit margins and trade amounts
- Automatic order book analysis
- Debug mode for testing without actual trades
- Efficient path caching system
- Rate limit handling
- Comprehensive logging
- Python 3.7+
- Binance API key and secret
- Active Binance account
- Clone the repository:
git clone [repository-url]
cd triangular-arbitrage-bot- Install required packages:
pip install -r requirements.txt- Create a
.envfile in the project root with your Binance credentials:
BINANCE_API_KEY=your_api_key_here
BINANCE_SECRET=your_secret_here
Key parameters can be adjusted in the main script:
TRADE_AMOUNT: Base trade amount in USDTPROFIT_MARGIN: Minimum profit margin to execute tradesCHECK_INTERVAL: Time between price checks (seconds)DEBUG_MODE: Enable/disable test mode without actual tradingMAX_PARALLEL_REQUESTS: Limit concurrent API requests
- Start the bot:
python main.py- The bot will:
- Initialize by finding valid triangular paths
- Cache paths to disk for future use
- Continuously monitor for profitable opportunities
- Execute trades when opportunities are found (if not in debug mode)
-
Path Generation:
- Identifies all possible triangular paths starting with stablecoins
- Validates paths against available trading pairs
- Caches valid paths to disk
-
Arbitrage Detection:
- Monitors order books for all valid paths
- Calculates potential profits including fees
- Checks liquidity at each step
-
Trade Execution:
- Executes trades when profit exceeds threshold
- Handles all three trades in sequence
- Includes safety checks and error handling
- Sandbox mode support for testing
- Rate limit handling
- Liquidity checks before trade execution
- Comprehensive error handling
- Debug mode for risk-free testing
The bot maintains detailed logs including:
- Initialization progress
- Path discovery
- Price checks
- Trade execution
- Errors and warnings
Cryptocurrency trading involves significant risk. This bot is provided for educational purposes only. Always test thoroughly with small amounts before running with significant funds.
[Your chosen license]
Feel free to submit issues, fork the repository, and create pull requests for any improvements.