Order
Subscribe to the order stream to see changes to your orders in real-time.
All-In-One Topic: order
Categorised Topic: order.spot, order.linear, order.inverse, order.option
info
- All-In-One topic and Categorised topic cannot be in the same subscription request
- All-In-One topic: Allow you to listen to all categories (spot, linear, inverse, option) websocket updates
- Categorised Topic: Allow you to listen only to specific category websocket updates
tip
You may receive two orderStatus=Filled messages when the cancel request is accepted but the order is executed at the same time. Generally, one
message contains "orderStatus=Filled, rejectReason=EC_NoError", and another message contains "orderStatus=Filled, cancelType=CancelByUser, rejectReason=EC_OrigClOrdIDDoesNotExist".
The first message tells you the order is executed, and the second message tells you the followed cancel request is rejected due to order is executed.
Response Parameters
| Parameter | Type | Comments |
|---|---|---|
| id | string | Message ID |
| topic | string | Topic name |
| creationTime | number | Data created timestamp (ms) |
| data | array | Object |
| > category | string | Product type |
| > orderId | string | Order ID |
| > orderLinkId | string | User customised order ID |
| > isLeverage | string | Whether to borrow. Unified spot only. 0: false, 1: trueClassic spot is not supported, always 0 |
| > blockTradeId | string | Block trade ID |
| > symbol | string | Symbol name |
| > price | string | Order price |
| > brokerOrderPrice | string | Dedicated field for EU liquidity provider |
| > qty | string | Order qty |
| > side | string | Side. Buy,Sell |
| > positionIdx | integer | Position index. Used to identify positions in different position modes |
| > orderStatus | string | Order status |
| > createType | string | Order create type |
| > cancelType | string | Cancel type |
| > rejectReason | string | Reject reason. Classic spot is not supported |
| > avgPrice | string | Average filled price "" for those orders without avg price, and also for those classic account orders have partilly filled but cancelled at the end"" |
| > leavesQty | string | The remaining qty not executed. Classic spot is not supported |
| > leavesValue | string | The remaining value not executed. Classic spot is not supported |
| > cumExecQty | string | Cumulative executed order qty |
| > cumExecValue | string | Cumulative executed order value |
| > cumExecFee | string | Deprecated. Cumulative executed trading fee.
|
| > closedPnl | string | Closed profit and loss for each close position order. The figure is the same as "closedPnl" from Get Closed PnL |
| > feeCurrency | string | Deprecated. Trading fee currency for Spot only. Please understand Spot trading fee currency here |
| > timeInForce | string | Time in force |
| > orderType | string | Order type. Market,Limit. For TP/SL orders, is the order type after the order was triggered |
| > stopOrderType | string | Stop order type |
| > ocoTriggerBy | string | The trigger type of Spot OCO order.OcoTriggerByUnknown, OcoTriggerByTp, OcoTriggerBySl. Classic spot is not supported |
| > orderIv | string | Implied volatility |
| > marketUnit | string | The unit for qty when create Spot market orders for UTA account. baseCoin, quoteCoin |
| > slippageToleranceType | string | Spot and Futures market order slippage tolerance type TickSize, Percent, UNKNOWN(default) |
| > slippageTolerance | string | Slippage tolerance value |
| > triggerPrice | string | Trigger price. If stopOrderType=TrailingStop, it is activate price. Otherwise, it is trigger price |
| > takeProfit | string | Take profit price |
| > stopLoss | string | Stop loss price |
| > tpslMode | string | TP/SL mode, Full: entire position for TP/SL. Partial: partial position tp/sl. Spot does not have this field, and Option returns always "" |
| > tpLimitPrice | string | The limit order price when take profit price is triggered |
| > slLimitPrice | string | The limit order price when stop loss price is triggered |
| > tpTriggerBy | string | The price type to trigger take profit |
| > slTriggerBy | string | The price type to trigger stop loss |
| > triggerDirection | integer | Trigger direction. 1: rise, 2: fall |
| > triggerBy | string | The price type of trigger price |
| > lastPriceOnCreated | string | Last price when place the order |
| > reduceOnly | boolean | Reduce only. true means reduce position size |
| > closeOnTrigger | boolean | Close on trigger. What is a close on trigger order? |
| > placeType | string | Place type, option used. iv, price |
| > smpType | string | SMP execution type |
| > smpGroup | integer | Smp group ID. If the UID has no group, it is 0 by default |
| > smpOrderId | string | The counterparty's orderID which triggers this SMP execution |
| > createdTime | string | Order created timestamp (ms) |
| > updatedTime | string | Order updated timestamp (ms) |
| > cumFeeDetail | json | Cumulative trading fee details instead of cumExecFee and feeCurrency |
Subscribe Example
{
"op": "subscribe",
"args": [
"order"
]
}
from pybit.unified_trading import WebSocket
from time import sleep
ws = WebSocket(
testnet=True,
channel_type="private",
api_key="xxxxxxxxxxxxxxxxxx",
api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
)
def handle_message(message):
print(message)
ws.order_stream(callback=handle_message)
while True:
sleep(1)
Stream Example
{
"id": "5923240c6880ab-c59f-420b-9adb-3639adc9dd90",
"topic": "order",
"creationTime": 1672364262474,
"data": [
{
"symbol": "ETH-30DEC22-1400-C",
"orderId": "5cf98598-39a7-459e-97bf-76ca765ee020",
"side": "Sell",
"orderType": "Market",
"cancelType": "UNKNOWN",
"price": "72.5",
"qty": "1",
"orderIv": "",
"timeInForce": "IOC",
"orderStatus": "Filled",
"orderLinkId": "",
"lastPriceOnCreated": "",
"reduceOnly": false,
"leavesQty": "",
"leavesValue": "",
"cumExecQty": "1",
"cumExecValue": "75",
"avgPrice": "75",
"blockTradeId": "",
"positionIdx": 0,
"cumExecFee": "0.358635",
"closedPnl": "0",
"createdTime": "1672364262444",
"updatedTime": "1672364262457",
"rejectReason": "EC_NoError",
"stopOrderType": "",
"tpslMode": "",
"triggerPrice": "",
"takeProfit": "",
"stopLoss": "",
"tpTriggerBy": "",
"slTriggerBy": "",
"tpLimitPrice": "",
"slLimitPrice": "",
"triggerDirection": 0,
"triggerBy": "",
"closeOnTrigger": false,
"category": "option",
"placeType": "price",
"smpType": "None",
"smpGroup": 0,
"smpOrderId": "",
"feeCurrency": "",
"cumFeeDetail": {
"MNT": "0.00242968"
}
}
]
}