An advanced multi-exchange arbitrage bot built with N8N, featuring machine learning optimization, dynamic risk management, and comprehensive performance tracking.
This bot monitors price discrepancies across multiple decentralized and centralized exchanges to identify and execute profitable arbitrage opportunities in real-time. Built with a modular architecture, it features ML-driven threshold optimization, gas-aware execution, and sophisticated risk management.
Full project documentation is maintained in Notion:
Velocity-BPA — Cross-DEX Arbitrage Bot Suite
The Notion page covers system architecture, all eight n8n workflow descriptions, the Airtable data schema (9 tables), API integrations, the ML optimization engine, risk management framework, and key operational learnings.
- Multi-Exchange Integration: Monitors Uniswap, SushiSwap, 1inch, OKX DEX, Kraken, and CoinGecko
- Intelligent Price Aggregation: Normalizes quotes across venues with outlier detection (IQR filtering)
- Smart Execution Logic: Paper trading mode with realistic slippage simulation
- Cross-Chain Monitoring: XRPL-Ethereum bridge opportunity detection
-
🤖 Machine Learning Optimization
- Dynamic threshold adjustment based on historical performance
- F1 score optimization for precision/recall balance
- Confidence-weighted decision making
- Automatic retraining on 15-minute intervals
-
⛽ Gas Optimization Engine
- Real-time gas price monitoring via Etherscan
- Execution window classification (Optimal/Good/Poor/Avoid)
- Opportunity cost tracking for gas-related misses
- Predictive optimal window forecasting
-
🛡️ Risk Management System
- Portfolio-based position sizing (10% max per position)
- Daily loss limits (2% max drawdown)
- Dynamic trade size adjustment based on risk status
- Circuit breakers for critical market conditions
-
📈 Performance Analytics
- Exchange reliability rankings
- Win rate tracking (overall and ML-guided)
- Slippage analysis
- 7-day performance trends
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Price Feeds │────▶│ Normalization │────▶│ Arbitrage Calc │
│ (6 exchanges) │ │ & Filtering │ │ & Execution │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
┌─────────────────┐ ▼
│ ML Training │◀────────┌─────────────────┐
│ (Threshold Opt) │ │ Airtable │
└─────────────────┘ │ Data Store │
└─────────────────┘
▲
┌─────────────────┐ ┌─────────────────┐ │
│ Risk Management │────▶│ Gas Optimization│─────────────┘
└─────────────────┘ └─────────────────┘
| Workflow | Purpose | Schedule |
|---|---|---|
main_arbitrage.json |
Core arbitrage detection and execution | Every 5 minutes |
ml_training.json |
ML threshold optimization | Every 15 minutes |
gas_optimization.json |
Gas price analysis and threshold adjustment | Every 15 minutes |
risk_management.json |
Portfolio risk assessment | Every 5 minutes |
exchange_performance.json |
Exchange reliability tracking | Every 4 hours |
dashboard.json |
Web-based monitoring dashboard | On-demand webhook |
Real_Time_Monitor- All arbitrage opportunitiesExecuted_Trades- Trade execution recordsGas_Tracker- Historical gas pricesML_Thresholds- Model parametersRisk_Management- Portfolio risk metricsExchange_Performance- Exchange reliability statsGas_Optimization- Execution window analysisPosition_Limits- Per-pair exposure tracking
- N8N instance (v1.0+)
- Airtable account with base configured
- API keys for:
- Etherscan (gas prices)
- 1inch (DEX aggregation)
- OKX DEX (requires API credentials)
- Optional: Kraken (for CEX prices)
-
Import Workflows
- Import all 6 workflow JSON files into N8N
- Configure credentials for each service
-
Setup Airtable
- Create a new base named "Arbitrage Bot"
- Import the provided schema for all tables
- Generate API key and configure in N8N
-
Configure Parameters
// In main_arbitrage workflow PORTFOLIO_SIZE = 50000 // Your portfolio size TEST_MODE = true // Start with paper trading
-
Activate Workflows
- Start with
main_arbitrageworkflow - Once data flowing, activate
ml_training - Enable remaining workflows after validation
- Start with
Access the real-time dashboard at:
http://your-n8n-instance/webhook/dashboard
Features:
- 24-hour P&L tracking
- ML model performance metrics
- Exchange reliability rankings
- Gas optimization status
- Risk management indicators
- Recent trade activity feed
The bot includes a comprehensive 7-phase testing sequence:
- Data Collection - Validate price feeds
- Arbitrage Detection - Verify opportunity identification
- ML Training - Confirm model optimization
- Risk Management - Test safety mechanisms
- Exchange Performance - Validate rankings
- Integration - End-to-end testing
- Performance - Benchmark profitability
See TESTING.md for detailed testing instructions.
This bot is for educational purposes. Cryptocurrency arbitrage involves significant risks:
- Smart contract vulnerabilities
- MEV bot competition
- Impermanent loss
- Network congestion
- Exchange API failures
Always test thoroughly with small amounts before scaling up.
| Parameter | Default | Description |
|---|---|---|
PORTFOLIO_SIZE |
50000 | Total portfolio value in USD |
MAX_POSITION_PCT |
0.10 | Max position size as % of portfolio |
DAILY_LOSS_LIMIT_PCT |
0.02 | Max daily loss as % of portfolio |
GAS_LIMIT |
200000 | Estimated gas per transaction |
MIN_PROFIT_USD |
5 | Minimum profit to execute |
TEST_MODE |
true | Enable paper trading |
Expected performance (based on paper trading):
- Opportunities/Hour: 10-50 (volatility dependent)
- Execution Rate: 20-40%
- Average Spread: 0.2-0.5% after costs
- Win Rate: 60-75% with ML optimization
- Gas/Profit Ratio: <30%
Contributions welcome! Areas for improvement:
- WebSocket price feeds for lower latency
- Additional exchange integrations
- MEV protection strategies
- Cross-chain execution (not just monitoring)
- Advanced ML features (LSTM, ensemble methods)
MIT License - see LICENSE for details
- N8N community for workflow automation platform
- OpenZeppelin for smart contract best practices
- DeFi protocols for providing liquidity and arbitrage opportunities
For issues and questions:
- Open an issue in this repository
- Check TESTING.md for debugging guides
- Review Airtable logs for execution history
⚡ Built with N8N | 🤖 Powered by Machine Learning | 📊 Tracked with Airtable