Websocket Trade Guideline
URL
- Mainnet:
wss://stream.bybit.com/v5/trade
info
- Turkey users registered from "www.bybit-tr.com", please use
wss://stream.bybit-tr.com/v5/trade
- Kazakhstan users registered from "www.bybit.kz", please use
wss://stream.bybit.kz/v5/trade
- Testnet:
wss://stream-testnet.bybit.com/v5/trade
Support
Authentication
Request Parameters
Parameter | Required | Type | Comments |
---|---|---|---|
reqId | false | string | Optional field, used to match the response |
op | true | string | Op type. auth |
args | false | string | ["api key", expiry timestamp, "signature"]. Please click here to generate signature |
Response Parameters
Parameter | Type | Comments |
---|---|---|
reqId | string | |
retCode | integer | 0 : auth success20001 : repeat auth10004 : invalid sign10001 : param error |
retMsg | string | OK |
op | string | Op type |
connId | string | Connection id, the unique id for the connection |
Request Example
{
"op": "auth",
"args": [
"XXXXXX",
1711010121452,
"ec71040eff72b163a36153d770b69d6637bcb29348fbfbb16c269a76595ececf"
]
}
Response Example
{
"retCode": 0,
"retMsg": "OK",
"op": "auth",
"connId": "cnt5leec0hvan15eukcg-2t"
}
Create/Amend/Cancel Order
Request Parameters
Parameter | Required | Type | Comments |
---|---|---|---|
reqId | false | string | Used to identify the uniqueness of the request, the response will return it when passed. The length cannot exceed 36 characters. |
header | true | object | Request headers |
> X-BAPI-TIMESTAMP | true | string | Current timestamp |
> X-BAPI-RECV-WINDOW | false | string | 5000(ms) by default. Request will be rejected when not satisfy this rule: Bybit_server_time - X-BAPI-RECV-WINDOW <= X-BAPI-TIMESTAMP < Bybit_server_time + 1000 |
> Referer | false | string | The referer identifier for API broker user |
op | true | string | Op type order.create : create an orderorder.amend : amend an orderorder.cancel : cancel an order |
args | false | array<object> | Args array, support one item only for now order.create : refer to create order requestorder.amend : refer to amend order requestorder.cancel : refer to cancel order request |
Response Parameters
Parameter | Type | Comments |
---|---|---|
reqId | string | |
retCode | integer | 0 : success10404 : 1. op type is not found; 2. category is not correct/supported10429 : System level frequency protection20006 : reqId is duplicated10016 : 1. internal server error; 2. Service is restarting10019 : ws trade service is restarting, do not accept new request, but the request in the process is not affected. You can build new connection to be routed to normal service |
retMsg | string | OK "" |
op | string | Op type |
data | object | Business data, keep the same as result on rest api response order.create : refer to create order responseorder.amend : refer to amend order responseorder.cancel : refer to cancel order response |
header | object | Header info |
> TraceId | string | Trace ID, used to track the trip of request |
> Timenow | string | Current timestamp |
> X-Bapi-Limit | string | The total rate limit of the current account for this op type |
> X-Bapi-Limit-Status | string | The remaining rate limit of the current account for this op type |
> X-Bapi-Limit-Reset-Timestamp | string | The timestamp indicates when your request limit resets if you have exceeded your rate limit. Otherwise, this is just the current timestamp (it may not exactly match timeNow ) |
connId | string | Connection id, the unique id for the connection |
info
The ack of create/amend/cancel order request indicates that the request is successfully accepted. Please use websocket order stream to confirm the order status
Request Example
{
"reqId": "test-005",
"header": {
"X-BAPI-TIMESTAMP": "1711001595207",
"X-BAPI-RECV-WINDOW": "8000",
"Referer": "bot-001" // for api broker
},
"op": "order.create",
"args": [
{
"symbol": "ETHUSDT",
"side": "Buy",
"orderType": "Limit",
"qty": "0.2",
"price": "2800",
"category": "linear",
"timeInForce": "PostOnly"
}
]
}
Response Example
{
"reqId": "test-005",
"retCode": 0,
"retMsg": "OK",
"op": "order.create",
"data": {
"orderId": "a4c1718e-fe53-4659-a118-1f6ecce04ad9",
"orderLinkId": ""
},
"header": {
"X-Bapi-Limit": "10",
"X-Bapi-Limit-Status": "9",
"X-Bapi-Limit-Reset-Timestamp": "1711001595208",
"Traceid": "38b7977b430f9bd228f4b19724794dfd",
"Timenow": "1711001595209"
},
"connId": "cnt5leec0hvan15eukcg-2v"
}
Ping
Request Parameters
Parameter | Required | Type | Comments |
---|---|---|---|
op | true | string | Op type. ping |
Response Parameters
Parameter | Type | Comments |
---|---|---|
retCode | integer | Result code |
retMsg | string | Result message |
op | string | Op type pong |
data | array | One item in the array, current timestamp (string) |
connId | string | Connection id, the unique id for the connection |
Request Example
{
"op": "ping"
}
Response Example
{
"retCode": 0,
"retMsg": "OK",
"op": "pong",
"data": [
"1711002002529"
],
"connId": "cnt5leec0hvan15eukcg-2v"
}