Skip to content

Kelvin0110/Trading-Bot-Web3-Quant-Hackathon-

Repository files navigation

Trading-Bot-Web3-Quant-Hackathon

A sophisticated Quantitative Algorithmic Trading Agent designed to maximize profit in crypto trading competitions while managing risk through systematic decision-making.

Overview

This trading agent operates autonomously using a 4-tool architecture:

  1. Data Collector: Fetches real-time market data and news sentiment from Horus API
  2. Data Analysis: Performs technical analysis (RSI, Moving Averages, Trend Detection)
  3. Strategy Picker: Selects optimal trading strategy (Momentum Trend or Mean Reversion)
  4. Trading Action: Executes trades on the Roostoo paper trading platform

Features

Risk Management

  • 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)

Trading Strategies

  • Momentum Trend: Capitalizes on clear uptrends/downtrends
  • Mean Reversion: Trades on price reversion in sideways markets

Operational Features

  • Automatic analysis every 5 minutes
  • Top 5 cryptocurrencies by market cap
  • Real-time news sentiment integration
  • Comprehensive technical analysis (RSI, SMA, Trend Detection)

Project Structure

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

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Trading-Bot-Web3-Quant-Hackathon-
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables: Create a .env file 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

Usage

Running the Agent

Test mode (1 cycle):

python main.py --test

Run for specific duration (minutes):

python main.py --duration 60  # Run for 1 hour

Run for specific number of cycles:

python main.py --cycles 10  # Run 10 cycles (50 minutes)

Run indefinitely (press Ctrl+C to stop):

python main.py

Testing API Connections

Test Roostoo API connection:

python test_api.py

How It Works

Workflow Cycle (Every 5 Minutes)

  1. Initiate Cycle: Start timestamp and status check
  2. Data Collection: Fetch market data and news sentiment for top 5 cryptos
  3. Data Analysis: Calculate RSI, moving averages, identify trends
  4. Strategy Selection: Choose Momentum Trend or Mean Reversion based on analysis
  5. Decision Making: Determine BUY, SELL, or HOLD based on strategy rules
  6. Pre-Trade Checks:
    • Verify no existing position
    • Check portfolio balance
    • Verify drawdown limits
    • Calculate position size
  7. Trade Execution: Execute trade with stop-loss if all checks pass
  8. Log Output: Record cycle results

Strategy Logic

Momentum Trend Strategy

  • Buy Condition: Uptrend AND RSI < 70 (not overbought)
  • Sell Condition: Downtrend AND RSI > 30 (not oversold)

Mean Reversion Strategy

  • Buy Condition: RSI < 30 (oversold)
  • Sell Condition: RSI > 70 (overbought)

API Integration

Horus API

  • 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

Roostoo API

  • 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

Configuration

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

Example Output

============================================================
🚀 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

Error Handling

The agent includes comprehensive error handling:

  • API connection failures (retries with fallbacks)
  • Invalid data handling
  • Risk limit enforcement
  • Trade execution validation

Development

Adding New Strategies

  1. Update tools/strategy_picker.py with new strategy logic
  2. Add strategy rules in get_strategy_rules()
  3. Update decision logic in agent/trading_agent.py

Adding New Indicators

  1. Add calculation method in tools/data_analysis.py
  2. Include in analyze() method
  3. Update decision logic to use new indicator

License

[Your License Here]

Disclaimer

This is a trading bot for educational and competition purposes. Trading cryptocurrencies involves substantial risk of loss. Use at your own risk.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages