GitHub - tingxifa/okx-grid-bot: A Python-Based Automated Trading Solution for OKX

·

Overview

This Python-based automated trading bot is designed for the OKB-USDT trading pair on OKX Exchange. It employs a grid trading strategy, dynamically adjusting grids and positions to capitalize on market volatility while incorporating robust risk management protocols.


Key Features


Prerequisites


Installation

  1. Clone the Repository:

    git clone https://github.com/tingxifa/okx-grid-bot  
    cd okx-grid-bot  
  2. Set Up a Virtual Environment:

    • Windows:

      python -m venv .venv  
      .\.venv\Scripts\activate  
    • Linux/macOS:

      python3 -m venv .venv  
      source .venv/bin/activate  
  3. Install Dependencies:

    pip install -r requirements.txt  

Configuration

  1. Create .env File:
    Add these variables (replace placeholders):

    # OKX API Credentials  
    OKX_API_KEY=your_api_key  
    OKX_SECRET_KEY=your_secret_key  
    OKX_PASSPHRASE=your_passphrase  
    
    # PushPlus Token (optional)  
    PUSHPLUS_TOKEN=your_token  
    
    # Initial Settings (optional)  
    INITIAL_PRINCIPAL=1000.0  # Initial capital (USDT)  
    INITIAL_BASE_PRICE=600.0  # Baseline price for grid alignment  
  2. Customize config.py:

    • Adjust BASE_SYMBOL, QUOTE_SYMBOL, grid sizes, and risk parameters.
    • Example:

      MIN_TRADE_AMOUNT = 10.0  # Minimum trade size (USDT)  
      MAX_POSITION_RATIO = 0.8  # Max 80% portfolio exposure  

Deployment

Local Execution

Run the bot after activating the virtual environment:

python main.py  

Docker Deployment

  1. Ensure .env is configured.
  2. Build and launch:

    docker-compose up -d  

    👉 Customize port mappings in docker-compose.yml


Web Interface

Access the dashboard at:
http://localhost:58080


FAQ

Q: How does the bot handle extreme volatility?
A: It auto-adjusts grids or pauses trading if thresholds (e.g., MAX_DRAWDOWN) are breached.

Q: Can I modify risk parameters mid-session?
A: Yes, via the Web UI or by editing config.py (restart required).

Q: Is backtesting supported?
A: Not currently—live trading only.

👉 Explore advanced grid strategies


Caveats


Contribute

PRs and bug reports are welcome!

Credits

Adapted from GridBNB-USDT by @EBOLABOY.