Environment Setup
To diagnose the issue effectively, let’s outline the technical environment where the problem occurred:
- Operating System: Raspbian 11
- Python Version: 3.9.2
- CCXT Library: 2.7.45
- Freqtrade Version: 2023.2.dev-e8dc3dd59
Note: Ensure all technical details are accurately provided for efficient troubleshooting. Enhancement requests or incomplete issue reports may be closed without further action.
Problem Description
Users encounter failures when attempting to create trades on the OKX exchange via Freqtrade’s live trading mode. Specifically, the system rejects trade requests due to leverage configuration errors.
Expected Behavior
Trades should execute seamlessly on OKX’s futures market with isolated margin settings.
Reproduction Steps
- Configure Freqtrade for Live Trading: - { "dry_run": false, "trading_mode": "futures", "margin_mode": "isolated", "exchange": { "name": "okx", "key": "xxxx", "secret": "xxxx", "password": "xxxx" } }
- Launch Freqtrade:  
 Run the command:freqtrade trade --strategy SomeStrategy -v
Observed Results
- Actual Outcome: Trades fail with leverage-related errors.
- Expected Outcome: Successful trade execution on OKX.
Error Logs
Critical log excerpts highlight the issue:
2023-02-07 12:04:41,252 - freqtrade.exchange.common - WARNING - _lev_prep() returned exception: "Could not set leverage due to BadRequest. Message: okx setLeverage() requires the posSide argument to be either 'long' or 'short'". Retrying still for 4 times.
...
2023-02-07 12:04:41,255 - freqtrade.freqtradebot - WARNING - Unable to create trade for COMP/USDT:USDT: Could not set leverage...Root Cause Analysis
The error stems from missing posSide specification in leverage configuration. OKX mandates explicit position direction (long or short) for futures trading.
👉 Learn how to configure OKX leverage settings
Solution
Modify your configuration to include posSide:
{
  "exchange": {
    "name": "okx",
    "additional_params": {
      "posSide": "long"  // or "short" based on strategy
    }
  }
}Best Practices for OKX Futures Trading
- Leverage Settings: Always define posSideto avoid API rejections.
- Margin Mode: Verify isolatedorcrossaligns with your risk management.
- API Permissions: Ensure keys have futures trading enabled.
FAQ Section
Why does OKX require posSide for leverage?
OKX’s API enforces direction-specific leverage to manage risk in futures markets. This prevents ambiguous position setups.
How do I check my current leverage on OKX?
👉 View leverage via OKX’s API or web interface
Can I switch leverage after a trade is active?
Yes, but adjustments may require closing/reopening positions depending on market conditions.
Conclusion
Configuring posSide resolves the trade creation issue. Always validate exchange-specific requirements when integrating APIs. For advanced troubleshooting, refer to OKX’s official documentation or community forums.