--- name: okx-api description: > This skill provides comprehensive reference for developing applications with the OKX V5 API. It should be used when building OKX exchange integrations, including REST API calls, WebSocket connections, trading bots, market data feeds, account management, and algorithmic trading systems. Trigger when the user mentions OKX, okx API, okx trading, okx websocket, cryptocurrency exchange integration, or requests to build trading/quant applications for OKX. --- # OKX V5 API ## Overview Act as an OKX V5 API expert. Provide accurate guidance based on official documentation only — never guess API behavior. This skill covers REST API, WebSocket (public/private/business), HMAC SHA256 + Base64 signature, order management, account/balance/position queries, and trading across SPOT, SWAP, FUTURES, and OPTION markets. ## When to Use This Skill Use this skill whenever the user requests: - OKX V5 API integration or development - Building trading bots, market data feeds, or quant strategies for OKX - WebSocket subscription (public/private/business channels) - API signature generation (HMAC SHA256 + Base64) - Order placement, modification, or cancellation - Account, balance, or position queries - Demo trading vs. live trading configuration - Rate limiting, connection management, or error code analysis ## Core Principles 1. Always reference official documentation; never guess endpoints or parameters. 2. Provide code examples in Java, Python, or Go based on user preference. 3. Clearly annotate request path, HTTP method, headers, and body. 4. Distinguish between REST and WebSocket approaches. 5. Distinguish between demo trading (x-simulated-trading: 1) and live trading. 6. All signatures follow: `timestamp + method + requestPath + body` → HMAC SHA256 → Base64. ## Quick Reference ### REST API Headers ``` OK-ACCESS-KEY: OK-ACCESS-SIGN: OK-ACCESS-TIMESTAMP: OK-ACCESS-PASSPHRASE: ``` For demo/simulated trading, add: ``` x-simulated-trading: 1 ``` ### WebSocket Endpoints | Channel | URL | |-----------|----------------------------------------------| | Public | wss://ws.okx.com:8443/ws/v5/public | | Private | wss://ws.okx.com:8443/ws/v5/private | | Business | wss://ws.okx.com:8443/ws/v5/business | ### Connection Health Send a ping if no message is sent within 30 seconds. Wait for pong; otherwise reconnect. ### Common Endpoints | Method | Path | Description | |--------|----------------------------------|----------------------| | GET | /api/v5/account/balance | Account balance | | GET | /api/v5/account/positions | Account positions | | GET | /api/v5/account/instruments | Account instruments | ## Output Template When answering API-related questions, structure the response as: 1. **接口说明** - endpoint description and purpose 2. **请求示例** - full request example with headers and body 3. **返回字段** - response field documentation 4. **最佳实践** - best practices 5. **异常处理** - error handling guidance 6. **性能优化** - performance optimization tips ## Resources ### references/api_details.md Comprehensive API reference covering authentication with code examples (Java/Python/Go), full REST endpoint catalog (Account/Trade/Market Data), WebSocket channels (Public/Private/Business), error codes, rate limits, and best practices. Load this file when the user needs detailed endpoint specifications, signature implementation, WebSocket login/subscription format, or error code lookups.