A sophisticated Quantitative Algorithmic Trading Agent designed to maximize profit in crypto trading competitions while managing risk through systematic decision-making.
This trading agent operates autonomously using a 4-tool architecture:
- Data Collector: Fetches real-time market data and news sentiment from Horus API
- Data Analysis: Performs technical analysis (RSI, Moving Averages, Trend Detection)
- Strategy Picker: Selects optimal trading strategy (Momentum Trend or Mean Reversion)
- Trading Action: Executes trades on the Roostoo paper trading platform
- Maximum Position Size: 25% of portfolio per trade
- Stop-Loss: Automatic 5% stop-loss on all trades
- Maximum Drawdown: 15% portfolio drawdown limit (no new trades if exceeded)
- Momentum Trend: Capitalizes on clear uptrends/downtrends
- Mean Reversion: Trades on price reversion in sideways markets
- Automatic analysis every 5 minutes
- Top 5 cryptocurrencies by market cap
- Real-time news sentiment integration
- Comprehensive technical analysis (RSI, SMA, Trend Detection)
Trading-Bot-Web3-Quant-Hackathon-/
├── agent/
│ ├── __init__.py
│ └── trading_agent.py # Main trading agent orchestrator
├── tools/
│ ├── __init__.py
│ ├── data_collector.py # Tool #1: Horus API integration
│ ├── data_analysis.py # Tool #2: Technical analysis
│ ├── strategy_picker.py # Tool #3: Strategy selection
│ └── trading_action.py # Tool #4: Roostoo API integration
├── main.py # Entry point
├── test_api.py # Roostoo API test script
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
└── README.md
-
Clone the repository:
git clone <repository-url> cd Trading-Bot-Web3-Quant-Hackathon-
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile in the root directory:ROOSTOO_API_KEY=your_roostoo_api_key ROOSTOO_API_SECRET=your_roostoo_api_secret HORUS_API_KEY=your_horus_api_key # Optional if Horus API requires auth
Test mode (1 cycle):
python main.py --testRun for specific duration (minutes):
python main.py --duration 60 # Run for 1 hourRun for specific number of cycles:
python main.py --cycles 10 # Run 10 cycles (50 minutes)Run indefinitely (press Ctrl+C to stop):
python main.pyTest Roostoo API connection:
python test_api.py- Initiate Cycle: Start timestamp and status check
- Data Collection: Fetch market data and news sentiment for top 5 cryptos
- Data Analysis: Calculate RSI, moving averages, identify trends
- Strategy Selection: Choose Momentum Trend or Mean Reversion based on analysis
- Decision Making: Determine BUY, SELL, or HOLD based on strategy rules
- Pre-Trade Checks:
- Verify no existing position
- Check portfolio balance
- Verify drawdown limits
- Calculate position size
- Trade Execution: Execute trade with stop-loss if all checks pass
- Log Output: Record cycle results
- Buy Condition: Uptrend AND RSI < 70 (not overbought)
- Sell Condition: Downtrend AND RSI > 30 (not oversold)
- Buy Condition: RSI < 30 (oversold)
- Sell Condition: RSI > 70 (overbought)
- Base URL:
https://api-horus.com - Endpoints used:
/api/v1/market/ohlcv- OHLCV data/api/v1/news/sentiment- News sentiment scores/api/v1/market/top- Top cryptocurrencies by market cap
- Base URL:
https://mock-api.roostoo.com - Authentication: HMAC-SHA256 signature
- Endpoints used:
/v3/balance- Portfolio balance/v3/positions- Open positions/v3/order- Execute trades
You can modify risk parameters in agent/trading_agent.py:
self.max_position_size_pct = 0.25 # 25% max per position
self.stop_loss_pct = 0.05 # 5% stop-loss
self.max_drawdown_pct = 0.15 # 15% max drawdown============================================================
🚀 Starting Analysis Cycle: 2025-11-04 15:40:00 UTC
============================================================
💰 Portfolio Status:
Total Value: $10000.00
Available Cash: $10000.00
📊 Analyzing Top 5 Cryptocurrencies: BTC, ETH, BNB, SOL, XRP
🔍 Analyzing BTC/USD...
📈 Current Price: $50000.00
📊 Trend: uptrend
📉 RSI: 65.00
📰 Sentiment: 0.60
🎯 Strategy: Momentum Trend
💡 Decision: BUY
📏 Quantity: 0.05000000
🛑 Stop-Loss: $47500.00
✅ Trade Executed Successfully!
Order ID: 1234567890
The agent includes comprehensive error handling:
- API connection failures (retries with fallbacks)
- Invalid data handling
- Risk limit enforcement
- Trade execution validation
- Update
tools/strategy_picker.pywith new strategy logic - Add strategy rules in
get_strategy_rules() - Update decision logic in
agent/trading_agent.py
- Add calculation method in
tools/data_analysis.py - Include in
analyze()method - Update decision logic to use new indicator
[Your License Here]
This is a trading bot for educational and competition purposes. Trading cryptocurrencies involves substantial risk of loss. Use at your own risk.