WS Trade
WS Trade Order
Submit orders via private WebSocket connection.
Prerequisites
A valid listenKey must be obtained and the private WebSocket connection must be established before sending trade requests.
Batch Orders
Submit up to 5 orders in a single request.
Request Format
{"action":"batch-orders","param":{"id":"1002","args":[{...},{...}]}}
| Field | Required | Type | Description |
|---|---|---|---|
| action | Yes | string | Fixed as "batch-orders" |
| param | Yes | object | Batch order parameters |
| param.id | Yes | string | Client request ID, used to match the response |
| param.args | Yes | array | Order arguments array, 1 to 5 objects |
args[N] Object Fields
| Field Name | Required | Type | Description |
|---|---|---|---|
| instId | Yes | string | Instrument ID, e.g. "BTC-USDT-SWAP", "BTC-USDT" |
| tdMode | Yes | string | Trade mode: cash, cross, isolated |
| ccy | No | string | Margin currency |
| side | Yes | string | Order side: buy, sell |
| posSide | No | string | Position side: long, short. Required for SWAP |
| mrgPosition | No | string | Margin position: merge, split. Required for SWAP |
| closePosId | No | string | Position ID for split-margin close |
| ordType | Yes | string | Order type: market, limit, post_only, ioc |
| sz | Yes | string | Order quantity |
| px | No | string | Order price. Required for limit, post_only |
| tgtCcy | No | string | Market order quantity type: base_ccy, quote_ccy. Spot only |
| tpTriggerPx | No | string | Take profit trigger price. Spot only |
| slTriggerPx | No | string | Stop loss trigger price. Spot only |
Request Example
{
"action": "batch-orders",
"param": {
"id": "1002",
"args": [
{
"instId": "BTC-USDT-SWAP",
"tdMode": "cross",
"side": "buy",
"ordType": "limit",
"sz": "1",
"px": "65000",
"posSide": "long",
"mrgPosition": "merge"
},
{
"instId": "ETH-USDT-SWAP",
"tdMode": "cross",
"side": "sell",
"ordType": "market",
"sz": "2",
"posSide": "short",
"mrgPosition": "merge"
}
]
}
}
Response Format
{"id":"1002","action":"batch-orders","code":"0","msg":"","data":[{"ordId":"1000587866646229","sCode":"0","sMsg":""},{"ordId":"","sCode":"50012","sMsg":"order failed: InsufficientMoney"}]}
Response Parameters
| Field Name | Type | Description |
|---|---|---|
| id | string | Client request ID, matching the request |
| action | string | Fixed as "batch-orders" |
| code | string | Result code, "0" means all items processed |
| msg | string | Result message |
| data | array | Per-order results, in the same order as args |
| data[].ordId | string | Order ID, empty on failure |
| data[].sCode | string | Per-item result code, "0" means success |
| data[].sMsg | string | Per-item result message |
Error Codes
| Code | Description |
|---|---|
| 0 | Success |
| 50002 | Internal error |
| 50003 | Data validation failed |
| 50005 | Invalid parameter |
| 50006 | Missing parameter |
| 50008 | Invalid configuration |
| 50011 | Unsupported |
| 50012 | Operation failed |
| 50018 | Invalid request |
Batch Order Error Handling
| Scenario | Code | Message |
|---|---|---|
| All orders placed | 0 | |
param is not valid JSON | 50018 | Invalid request json |
args empty or > 5 | 50005 | args length must be between 1 and 5 |
| Single item: invalid arg | 50003 | Invalid arg (per-item sCode) |
| Single item: missing posSide/mrgPosition | 50006 | posSide/mrgPosition is required (per-item sCode) |
| Single item: invalid instId | 50005 | invalid instId (per-item sCode) |
| Single item: unsupported | 50011 | unsupported (per-item sCode) |
| Single item: backend failure | 50012 | Order failed (per-item sCode) |
Notes
- Order status updates will be pushed via the existing
PushOrdernotification (action=PushOrder,table=Order) - Trade results will be pushed via the existing
PushTradenotification (action=PushTrade,table=Trade) - This feature does not add new push channels