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

Response Parameters

ParameterTypeComments
idstringMessage ID
topicstringTopic name
creationTimenumberData created timestamp (ms)
dataarrayObject
> categorystringProduct type
  • UTA2.0, UTA1.0: spot, linear, inverse, option
  • Classic account: spot, linear, inverse.
> orderIdstringOrder ID
> orderLinkIdstringUser customised order ID
> isLeveragestringWhether to borrow. Unified spot only. 0: false, 1: true
Classic spot is not supported, always 0
> blockTradeIdstringBlock trade ID
> symbolstringSymbol name
> pricestringOrder price
> qtystringOrder qty
> sidestringSide. Buy,Sell
> positionIdxintegerPosition index. Used to identify positions in different position modes
> orderStatusstringOrder status
> createTypestringOrder create type
  • Only for category=linear or inverse
  • Spot, Option do not have this key
  • > cancelTypestringCancel type
    > rejectReasonstringReject reason. Classic spot is not supported
    > avgPricestringAverage filled price
  • returns "" for those orders without avg price, and also for those classic account orders have partilly filled but cancelled at the end
  • Classic Spot: not supported, always ""
  • > leavesQtystringThe remaining qty not executed. Classic spot is not supported
    > leavesValuestringThe remaining value not executed. Classic spot is not supported
    > cumExecQtystringCumulative executed order qty
    > cumExecValuestringCumulative executed order value
    > cumExecFeestringCumulative executed trading fee.
    • Classic spot: it is the latest execution fee for order.
    • 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
    > feeCurrencystringTrading fee currency for Spot only. Please understand Spot trading fee currency here
    > timeInForcestringTime in force
    > orderTypestringOrder type. Market,Limit. For TP/SL order, it means the order type after triggered
    > stopOrderTypestringStop order type
    > ocoTriggerBystringThe trigger type of Spot OCO order.OcoTriggerByUnknown, OcoTriggerByTp, OcoTriggerBySl. Classic spot is not supported
    > orderIvstringImplied volatility
    > marketUnitstringThe unit for qty when create Spot market orders for UTA account. baseCoin, quoteCoin
    > 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
    > smpGroupintegerSmp 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)

    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="XXXXX",
    api_secret="XXXXX",
    )
    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": ""
    }
    ]
    }