Understanding Passphrase Security
The passphrase refers to the password you created when applying for your APIKey. This credential is critical for accessing your OKX account programmatically. Remember:
- Passphrases are irrecoverable if forgotten
- No retrieval mechanism exists - you must generate a new APIKey
- Store your passphrase securely using password managers or encrypted notes
๐ Protect your API credentials with OKX's security features
Demo Trading API Setup
To practice trading using OKX's demo environment:
- Log in to your OKX account
- Navigate to: Trading > Demo Trading > Personal Center
- Select Create Demo Account APIKey
- Begin simulated trading with virtual funds
Key benefit: Risk-free environment to test trading strategies before deploying real capital.
APIKey Expiration Policies
OKX implements smart expiration rules:
| APIKey Type | Activity Requirement | Expiration Timeline |
|---|---|---|
| Unrestricted Keys | No transactions/withdrawals | 14 days inactivity |
| Read-Only Keys | IP-bound | Never expires |
| Active Keys | Regular interface calls | Remains active |
Pro Tip: Calling account balance or order placement interfaces resets the inactivity timer.
Order Placement Specifications
When placing contract orders:
- Interface defaults to contract quantity (not USDT)
- Use conversion formulas for coin-equivalent calculations
- Reference the contracts-to-coin conversion interface for accurate translations
Calculation Example: Contracts needed = (USDT Amount) / (Contract Value ร Last Price)
Calculating Price Fluctuations
Obtain market movement data through:
- Fetch 24-hour K-line opening price (
open24h) - Get latest transaction price (
last) - Apply formula:
Fluctuation Rate = [(last - open24h) / open24h] ร 100%
Position Side Errors ("51000")
Resolve this by verifying your account mode:
1. Check `posMode` via interface:
- **Hedge Mode**: Requires `posSide` (long/short)
- **One-way Mode**: Use `net` or omit parameter
2. Cross-validate with product type:
- Contracts mandate position sides
- Spot trading doesn't support them๐ Master OKX trading modes for seamless API integration
Contract Specifications Access
Retrieve critical trading parameters through:
ctVal: Contract face valueminSz: Minimum order quantity
Available in the trading products information interface.
Instrument ID Format Guide
Standard instId structures:
| Product Type | Format Example | Case Sensitivity |
|---|---|---|
| Spot Trading | BTC-USDT | Uppercase required |
| Perpetual SWAP | BTC-USD-SWAP | All caps |
| Futures | BTC-USD-210326 | Week/month codes |
| Options | BTC-USD-210326-2000-C | Letter suffixes |
Stop-Loss/Take-Profit Configuration
Two implementation methods:
- Attached Orders: Use
attachAlgoOrdsarray in main order request - Separate Triggers: Leverage the strategy commission interface
Price Validation Rules:
- Sell Orders: TP > Last Price > SL
- Buy Orders: TP < Last Price < SL
Timestamp Errors ("50102")
Synchronization protocol:
- Call OKX's server time interface (UTC+8)
- Adjust local clock to within 30 seconds of server time
- Ensure request headers use UTC0 timestamps
Developer Note: Implement automatic time synchronization routines in your code.
Environment Mismatch ("50101")
Resolution matrix:
| Environment | APIKey Type | Header Parameter |
|---|---|---|
| Live Trading | Real Account Key | x-simulated-trading: 0 |
| Demo Trading | Sandbox Key | x-simulated-trading: 1 |
Account Mode Conflicts ("51010")
Mode requirements:
- Spot trading: Only in Spot Mode
- Margin/Contracts: Any non-Spot Mode
First-time configuration must occur via web/app interface.
Lot Size Errors ("51121")
Order quantity rules:
- Must be integer multiples of
minSz - Validate against product specifications
- Round fractional quantities downward
Example: If minSz=0.01, valid quantities are 0.01, 0.02, etc.
Withdrawal Whitelisting ("58207")
API withdrawal workflow:
- Manually add addresses via web interface
- Enable "Non-Verified by Visa" option
- Whitelist status overrides page settings
System Timeouts ("50004")
Peak period management:
| High-Load Periods | Recommended Action |
|---|---|
| 8AM/4PM/12AM UTC | Postpone batch operations |
| Other Times | Implement retry logic |
Note: 50004 errors require result verification - the operation may have succeeded.
FAQ Section
How often should I rotate my APIKeys?
We recommend regenerating APIKeys every 90 days as part of routine security maintenance.
Can I use the same APIKey for live and demo trading?
No. Separate APIKeys are required for each environment with corresponding header parameters.
What's the maximum request rate for OKX API?
The standard limit is 20 requests per second. Prioritize request batching during high volatility.
How do I troubleshoot authentication failures?
- Verify timestamp synchronization
- Check APIKey environment matching
- Validate signature generation
- Confirm header formatting
Are there WebSocket alternatives for real-time data?
Yes. OKX provides WebSocket APIs for market data and account updates with lower latency than REST polling.
What happens to open orders when an APIKey expires?
Active orders remain operational. Only new API requests are blocked until you generate a new key.