So you've heard about algorithmic trading on crypto exchanges, and now you want to test your bot before feeding it real money. Smart move. Because here's the thing — most people skip the testing phase, their bot goes live, and three bad trades later they're posting in Reddit threads about "unexpected behavior."
OKX has a demo trading API that's genuinely one of the better sandbox environments in crypto. It mirrors real market conditions, uses live price data, and the API behavior is nearly identical to the live environment. This guide walks you through everything: what the demo API actually does, how to set it up, how to connect it with code, and how OKX's fee structure works when you eventually go live.
The OKX demo trading API is a sandboxed version of OKX's full trading API. You get a simulated account loaded with virtual funds, and you can fire API calls at it exactly like you would in production — placing orders, checking balances, subscribing to WebSocket streams, the whole thing.
The key distinction from the live API: you add one header to your requests: x-simulated-trading: 1. That's it. Everything else works the same way.
This matters because:
- You can test your bot logic against real market conditions without risking actual capital
- Your API key won't expire from inactivity the way live API keys can
- The learning curve is real: OKX's API covers spot, margin, futures, and options — getting familiar with the structure in demo saves you from expensive surprises in production
If you're building a trading strategy — whether that's a market maker, a momentum bot, or just automating DCA entries — the demo environment is where you should spend your first few weeks.
👉 Get Started with OKX Demo Trading
The process is straightforward, but the menu navigation trips people up the first time. Here's exactly where to find it:
Web (Desktop):
- Log in to your OKX account (or create a free one — demo trading doesn't require KYC to start)
- Hover over Trade in the top navigation
- Select Demo Trading — this switches your session to the simulated environment
- Go to Personal Center (your profile icon, top right)
- Find Demo Trading API in the menu
- Click Create Demo Trading API Key
- Set your permissions (read, trade, withdraw — note: withdraw doesn't work in demo, but you can still configure it)
Mobile:
- Log in → tap your avatar/profile icon
- Find Demo Trading under the Trade section
- Switch to demo mode
- Navigate to API management from within demo mode
Your demo API key is separate from your live API key. It only works against the demo environment, so there's no risk of accidentally sending a test order to the live exchange.
This is the one thing everyone forgets the first time. Without it, your demo API key will fail authentication or route to the wrong environment.
Every single request to the demo trading API needs this header:
x-simulated-trading: 1
A complete request header looks like this:
Content-Type: application/json OK-ACCESS-KEY: your_demo_api_key OK-ACCESS-SIGN: your_generated_signature OK-ACCESS-PASSPHRASE: your_passphrase OK-ACCESS-TIMESTAMP: 2026-04-20T10:30:00.000Z x-simulated-trading: 1
Drop that last line and your requests either fail or hit the wrong endpoint. It's a small thing that causes big headaches.
The REST endpoint is the same (https://www.okx.com), but the WebSocket endpoints differ:
| Connection Type | Demo Environment | Live Environment |
|---|---|---|
| REST API | https://www.okx.com |
https://www.okx.com |
| Public WebSocket | wss://wspap.okx.com:8443/ws/v5/public |
wss://ws.okx.com:8443/ws/v5/public |
| Private WebSocket | wss://wspap.okx.com:8443/ws/v5/private |
wss://ws.okx.com:8443/ws/v5/private |
| Business WebSocket | wss://wspap.okx.com:8443/ws/v5/business |
wss://ws.okx.com:8443/ws/v5/business |
Note the wspap subdomain for demo WebSockets versus ws for live. If your WebSocket subscriptions aren't connecting in demo mode, this is usually the issue.
OKX maintains an official Python SDK that handles the authentication signatures and header management for you. It's the cleanest way to interact with the API.
Install:
bash pip install python-okx
Demo Trading Setup:
python import okx.Account as Account import okx.Trade as Trade
api_key = "your_demo_api_key" secret_key = "your_demo_secret_key" passphrase = "your_passphrase"
flag = "1"
account_api = Account.AccountAPI(api_key, secret_key, passphrase, False, flag)
balance = account_api.get_account_balance() print(balance)
Placing a Demo Order:
python import okx.Trade as Trade
trade_api = Trade.TradeAPI(api_key, secret_key, passphrase, False, flag)
result = trade_api.place_order( instId="BTC-USDT", tdMode="cash", # spot trading side="buy", ordType="limit", px="60000", # limit price sz="0.001" # size in BTC )
print(result)
The flag parameter does all the heavy lifting — flip it to "0" when you're ready to go live. Everything else in your code stays the same.
👉 Create Your Free OKX Account
Supported trading types in demo mode:
- Spot trading
- Margin trading
- Futures trading (including perpetual swaps)
- Options trading
API functions that work in demo:
- Place, modify, and cancel orders
- Check account balances
- Stream real-time market data via WebSocket
- Access position and order history
Functions NOT supported in demo:
- Withdrawals
- Deposits
- Purchase/redemption (for OKX Earn products)
- Sub-account creation and management
These limitations make sense — they're either purely financial operations that don't translate to a simulated environment or infrastructure-level features. For testing trading logic, none of these matter.
One thing that genuinely sets OKX's demo environment apart: it uses live market data. Your simulated trades are filled against real order book prices, real bid-ask spreads, real volatility.
This matters more than it sounds. A lot of demo environments use synthetic data that's "market-like" but misses edge cases — thin liquidity during news events, wide spreads on low-cap altcoins, the way slippage behaves on large orders. OKX's demo uses the actual live feed, so your bot encounters real market microstructure.
For WebSocket users, you subscribe to market data channels exactly as you would in production:
python
import asyncio import websockets import json
async def subscribe_ticker(): uri = "wss://wspap.okx.com:8443/ws/v5/public" async with websockets.connect(uri) as ws: subscribe_msg = { "op": "subscribe", "args": [{"channel": "tickers", "instId": "BTC-USDT"}] } await ws.send(json.dumps(subscribe_msg)) while True: msg = await ws.recv() print(msg)
asyncio.run(subscribe_ticker())
Change wspap.okx.com to ws.okx.com when you go live. Everything else stays identical.
Once your strategy is validated in demo, you'll move to live trading. Here's the fee structure you'll be working with.
OKX uses a maker-taker model. Makers (limit orders that add liquidity) pay lower fees than takers (market orders or limit orders that immediately execute against existing orders).
| Tier | Requirement | Maker Fee | Taker Fee |
|---|---|---|---|
| Regular | Default | 0.08% | 0.10% |
| Regular + OKB | Hold 1,000+ OKB | 0.06% | 0.08% |
| VIP 1 | ≥$500K 30-day volume or ≥$50K assets | 0.07% | 0.09% |
| VIP 2 | ≥$2M 30-day volume or ≥$200K assets | 0.06% | 0.08% |
| VIP 3 | ≥$10M 30-day volume or ≥$500K assets | 0.05% | 0.07% |
| VIP 4 | ≥$50M 30-day volume or ≥$1M assets | 0.04% | 0.06% |
| VIP 5+ | ≥$100M+ 30-day volume | Further reductions | Further reductions |
| Tier | Maker Fee | Taker Fee |
|---|---|---|
| Regular | 0.02% | 0.05% |
| VIP 1 | 0.015% | 0.04% |
| VIP 2 | 0.010% | 0.035% |
| VIP 3 | 0.005% | 0.030% |
| VIP 4 | 0.000% | 0.025% |
| VIP 5+ | -0.005% (rebate) | 0.020% |
The futures fees are notably competitive, especially at higher VIP tiers where makers can earn rebates. For high-frequency strategies, this is a meaningful edge.
VIP tier qualification: OKX takes either your 30-day trading volume or your total account assets — whichever qualifies you for the higher tier. So if you hold significant assets on the exchange, you can access lower fees even with moderate trading volume.
New account bonus: Using the referral link with code CASH20 gives you a 20% commission rebate on trading fees — a solid advantage when you're starting out and every basis point counts.
When you're ready to move your tested strategy to production, here's what actually needs to change in your code:
- Create a live API key from your main OKX account settings (not demo mode)
- Change
flagfrom"1"to"0"in your SDK initialization - Update WebSocket URLs from
wspap.okx.comtows.okx.com - Remove
x-simulated-trading: 1from any raw HTTP clients (SDK handles this automatically when flag is 0) - Adjust position sizes — demo virtual funds are generous, live trading needs real risk management
- Test with small sizes first — even a validated strategy can behave differently with real liquidity and real fills
The code structure doesn't change. The API contracts are identical. The migration is essentially a credential swap and a flag change.
"Invalid API key" errors in demo mode: You're probably using your live API key against the demo environment. Create a separate demo API key specifically through the demo trading interface.
Orders not filling in demo: The demo environment uses real market prices. If your limit order is too far from the market, it won't fill — just like in production. Check your order is within reasonable range of the current price.
WebSocket disconnections:
The demo WebSocket endpoints (wspap.okx.com) can occasionally have higher latency than production. Add reconnection logic with exponential backoff.
"Function not supported" errors: Withdraw, deposit, and sub-account operations genuinely don't work in demo mode. If your bot has these functions, mock them out or gate them behind an environment check.
Positions not resetting: Before resetting your demo account to initial virtual funds, you must close all open positions and cancel all pending orders. The reset will fail with active positions.
OKX's API is among the better-documented exchanges in crypto. The official docs at okx.com/docs-v5/en/ cover REST and WebSocket with full parameter references, error code explanations, and code examples across Python, JavaScript, and Java.
A few things that make it stand out for algo traders:
- Unified account model: A single account holds spot, margin, and derivatives. Your collateral works across all instruments.
- Sub-millisecond WebSocket feeds: For HFT strategies or execution logic that needs tight fills, the latency profile is competitive.
- Institutional-grade API limits: Higher rate limits than many exchanges, with clear documentation on the limits per endpoint.
- OKX python-okx SDK: Actively maintained, handles signature generation, and has examples specifically for demo trading.
The demo API makes it low-risk to evaluate whether OKX is the right fit for your strategy before committing capital.
👉 Start Demo Trading on OKX — use code CASH20 for a 20% trading fee rebate when you go live.
The OKX demo trading API is one of those features that's genuinely useful rather than just checking a marketing box. Live market data, identical API contracts, a real WebSocket infrastructure — it lets you do real strategy development, not just toy around with synthetic prices.
The setup is simple: create a demo API key through the demo trading interface, add x-simulated-trading: 1 to your headers (or set flag="1" in the Python SDK), use the demo WebSocket endpoints, and you're running. When you're satisfied with the results, flip the flag and swap the credentials.
The fee structure rewards volume and commitment — regular traders start at 0.08%/0.10% for spot, with futures even cheaper at 0.02%/0.05%. The 20% rebate from the CASH20 code is a real discount worth taking at sign-up.
Test first. Break things in demo. Then go live.