A comprehensive trading bot for OKX MINA-USDT perpetual futures using OpenBB-style strategy and CCXT for execution.
- Multi-indicator Strategy: Combines RSI, MACD, Moving Averages, and Bollinger Bands
- Risk Management: Configurable position sizing, stop loss, and take profit
- Paper Trading: Sandbox mode for testing strategies
- Position Management: Automatic position opening/closing based on signals
- Comprehensive Logging: Detailed logs for all trading activities
- Install dependencies:
pip install -r requirements.txt- Configure your OKX API credentials in
config.json:
{
"api_key": "your_api_key_here",
"secret": "your_secret_here",
"password": "your_password_here",
"sandbox": true,
"leverage": 3,
"position_size": 0.1,
"stop_loss": 0.02,
"take_profit": 0.04,
"max_positions": 1,
"interval": "15m",
"strategy": {
"rsi_period": 14,
"rsi_overbought": 70,
"rsi_oversold": 30,
"macd_fast": 12,
"macd_slow": 26,
"macd_signal": 9,
"sma_short": 20,
"sma_long": 50
}
}python mina_okx_trading.py- sandbox: Set to
truefor paper trading,falsefor live trading - leverage: Trading leverage (default: 3x)
- position_size: Position size as percentage of account balance (default: 10%)
- stop_loss: Stop loss percentage (default: 2%)
- take_profit: Take profit percentage (default: 4%)
- interval: Candlestick interval (default: 15m)
- RSI: Overbought at 70, oversold at 30
- MACD: Fast=12, Slow=26, Signal=9
- Moving Averages: Short=20, Long=50
- Bollinger Bands: 20-period with 2 standard deviations
The bot uses a scoring system combining multiple indicators:
- RSI: +1 for oversold, -1 for overbought
- MACD: +1 for bullish crossover, -1 for bearish crossover
- Moving Averages: +1 for bullish alignment, -1 for bearish alignment
- Bollinger Bands: +1 for touching lower band, -1 for touching upper band
Signal Generation:
- BUY: Score ≥ 3
- SELL: Score ≤ -3
- HOLD: -2 ≤ Score ≤ 2
- Sandbox Mode: Test strategies without real money
- Position Limits: Maximum 1 position at a time
- Automatic Position Closure: Closes opposite positions before opening new ones
- Error Handling: Comprehensive error handling and logging
The bot creates detailed logs in mina_trading.log including:
- Trading signals and decisions
- Order executions
- Position updates
- Error messages
- Create OKX API credentials at https://www.okx.com/account/my-api
- Enable futures trading permissions
- Add your API key, secret, and password to
config.json - Start with sandbox mode enabled for testing
- Always test strategies in sandbox mode first
- Start with small position sizes
- Monitor the bot closely during initial runs
- Use appropriate stop losses and position sizing
You can modify the strategy by adjusting parameters in config.json or by editing the generate_signal() method in the code.
For issues and questions:
- Check the logs in
mina_trading.log - Ensure all dependencies are installed
- Verify API credentials and permissions
- Test in sandbox mode first