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
- Automated Grid Trading: Executes buy/sell orders within predefined price grids for OKB-USDT.
- Adaptive Grid Sizing: Adjusts grid parameters (
GRID_PARAMSinconfig.py) based on real-time market volatility. Risk Controls:
- Max drawdown limit (
MAX_DRAWDOWN). - Daily loss threshold (
DAILY_LOSS_LIMIT). - Position size caps (
MAX_POSITION_RATIO).
- Max drawdown limit (
- Web UI: Live monitoring via a Flask-based dashboard (
web_server.py). - State Persistence: Saves trading data to
data/for seamless recovery after restarts. - Notifications: PushPlus integration for alerts (
PUSHPLUS_TOKEN). - Logging: Detailed activity logs in
trading_system.log.
Prerequisites
- Python 3.8+
- Libraries listed in
requirements.txt. Recommended Server Specs:
- CPU: 2 cores (minimum 1 core).
- RAM: 1GB (512MB minimum).
- Storage: 500MB free space.
- OS: Windows/Linux/macOS.
- Network: Low-latency connection to OKX APIs (e.g., Japanese servers).
Installation
Clone the Repository:
git clone https://github.com/tingxifa/okx-grid-bot cd okx-grid-botSet Up a Virtual Environment:
Windows:
python -m venv .venv .\.venv\Scripts\activateLinux/macOS:
python3 -m venv .venv source .venv/bin/activate
Install Dependencies:
pip install -r requirements.txt
Configuration
Create
.envFile:
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 alignmentCustomize
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
- Adjust
Deployment
Local Execution
Run the bot after activating the virtual environment:
python main.py Docker Deployment
- Ensure
.envis configured. Build and launch:
docker-compose up -d
Web Interface
Access the dashboard at: http://localhost:58080
Functions:
- Real-time balance/order tracking.
- Manual overrides.
- Performance analytics.
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
- Risk Disclosure: Automated trading carries market risks—test thoroughly before deploying capital.
- API Security: Never share API keys; disable withdrawal permissions.
- Config Review: Validate all settings match your risk tolerance.
Contribute
PRs and bug reports are welcome!
Credits
Adapted from GridBNB-USDT by @EBOLABOY.