Skip to main content

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​

ParameterTypeComments
idstringMessage ID
topicstringTopic name
creationTimenumberData created timestamp (ms)
dataarrayObject
> categorystringProduct type spot, linear, inverse, option
> orderIdstringOrder ID
> orderLinkIdstringUser customised order ID
> parentOrderLinkIdstringIndicates the linked parent order for attached take-profit and stop-loss orders. Supported for futures and options.
  • Amending take-profit or stop-loss orders does not change the parentOrderLinkId
  • Futures: using set trading stop to update attached TP/SL from the original order does not change the parentOrderLinkId.
  • Options: using set trading stop to update attached TP/SL from the original order will change the parentOrderLinkId.
  • Futures & Options: if TP/SL is set via set trading stopfor a position that originally has no attached TP/SL, the parentOrderLinkId is meaningless.
> isLeveragestringWhether to borrow. 0: false, 1: true
> blockTradeIdstringBlock trade ID
> symbolstringSymbol name
> pricestringOrder price
> brokerOrderPricestringDedicated field for EU liquidity provider
> qtystringOrder qty
> sidestringSide. Buy,Sell
> positionIdxintegerPosition index. Used to identify positions in different position modes
> orderStatusstringOrder status
> createTypestringOrder create type, Spot, Option do not have this key
> cancelTypestringCancel type
> rejectReasonstringReject reason
> avgPricestringAverage filled price, returns "" for those orders without avg price
> leavesQtystringThe remaining qty not executed
> leavesValuestringThe remaining value not executed
> cumExecQtystringCumulative executed order qty
> cumExecValuestringCumulative executed order value
> cumExecFeestring
  • inverse, option: Cumulative executed trading fee.
  • linear, spot: Deprecated. Use cumFeeDetail instead.
  • After upgraded to the Unified account, you can use execFee for each fill in Execution topic
> closedPnlstringClosed profit and loss for each close position order. The figure is the same as "closedPnl" from Get Closed PnL
> feeCurrencystringDeprecated. Trading fee currency for Spot only. Please understand Spot trading fee currency here
> timeInForcestringTime in force
> orderTypestringOrder type. Market,Limit. For TP/SL orders, is the order type after the order was triggered
> stopOrderTypestringStop order type
> ocoTriggerBystringThe trigger type of Spot OCO order.OcoTriggerByUnknown, OcoTriggerByTp, OcoTriggerBySl
> orderIvstringImplied volatility
> marketUnitstringThe unit for qty when create Spot market orders. baseCoin, quoteCoin
> slippageToleranceTypestringSpot and Futures market order slippage tolerance type TickSize, Percent, UNKNOWN(default)
> slippageTolerancestringSlippage tolerance value
> triggerPricestringTrigger price. If stopOrderType=TrailingStop, it is activate price. Otherwise, it is trigger price
> takeProfitstringTake profit price
> stopLossstringStop loss price
> tpslModestringTP/SL mode, Full: entire position for TP/SL. Partial: partial position tp/sl. Spot does not have this field, and Option returns always ""
> tpLimitPricestringThe limit order price when take profit price is triggered
> slLimitPricestringThe limit order price when stop loss price is triggered
> tpTriggerBystringThe price type to trigger take profit
> slTriggerBystringThe price type to trigger stop loss
> triggerDirectionintegerTrigger direction. 1: rise, 2: fall
> triggerBystringThe price type of trigger price
> lastPriceOnCreatedstringLast price when place the order
> reduceOnlybooleanReduce only. true means reduce position size
> closeOnTriggerbooleanClose on trigger. What is a close on trigger order?
> placeTypestringPlace type, option used. iv, price
> smpTypestringSMP execution type
> smpGroupstringSmp group ID. If the UID has no group, it is "0" by default
> smpOrderIdstringThe counterparty's orderID which triggers this SMP execution
> createdTimestringOrder created timestamp (ms)
> updatedTimestringOrder updated timestamp (ms)
> cumFeeDetailjson
  • linear, spot: Cumulative trading fee details instead of cumExecFee
> rpiTakerAccessbooleanWhether the order has matched with an RPI order as the counterparty. true: the counterparty is an RPI order, false: the counterparty is not an RPI order.
> rpiMatchedQtystringCumulative quantity matched against RPI orders as the counterparty.

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"
},
"rpiTakerAccess": false,
"rpiMatchedQty": "0"
}
]
}