Skip to main content

Position

Subscribe to the position stream to see changes to your position data in real-time.

All-In-One Topic: position
Categorised Topic: position.linear, position.inverse, position.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 (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
> symbolstringSymbol name
> sidestringPosition side. Buy: long, Sell: short
  • one-way mode: classic & UTA1.0(inverse), an empty position returns None.
  • UTA2.0(linear, inverse) & UTA1.0(linear): either one-way or hedge mode returns an empty string "" for an empty position.
> sizestringPosition size
> positionIdxintegerUsed to identify positions in different position modes
> tradeModeintegerTrade mode
> positionValuestringPosition value
> riskIdintegerRisk tier ID
for portfolio margin mode, this field returns 0, which means risk limit rules are invalid
> riskLimitValuestringRisk limit value
for portfolio margin mode, this field returns 0, which means risk limit rules are invalid
> entryPricestringEntry price
> markPricestringMark price
> leveragestringPosition leverage
for portfolio margin mode, this field returns "", which means leverage rules are invalid
> positionBalancestringPosition margin
  • Classic & UTA1.0(inverse) can refer to this field to get the position initial margin
  • > autoAddMarginintegerWhether to add margin automatically. 0: false, 1: true. For UTA, it is meaningful only when UTA enables ISOLATED_MARGIN
    > positionIMstringInitial margin
  • Classic & UTA1.0(inverse): ignore this field
  • UTA portfolio margin mode, it returns ""
  • > positionMMstringMaintenance margin
  • Classic & UTA1.0(inverse): ignore this field
  • UTA portfolio margin mode, it returns ""
  • > liqPricestringPosition liquidation price
    • UTA1.0(inverse) & UTA(isolated margin enabled) & Classic account: it is the real price for isolated and cross positions, and keeps "" when liqPrice <= minPrice or liqPrice >= maxPrice
    • UTA (Cross margin mode): it is an estimated price for cross positions(because the unified mode controls the risk rate according to the account), and keeps "" when liqPrice <= minPrice or liqPrice >= maxPrice
    However, this field is empty for Portfolio Margin Mode, and no liquidation price will be provided
    > bustPricestringBankruptcy price
    Unified mode returns "", no position bankruptcy price (except UTA1.0(inverse))
    > tpslModestringdeprecated, meaningless here, always "Full"
    > takeProfitstringTake profit price
    > stopLossstringStop loss price
    > trailingStopstringTrailing stop
    > unrealisedPnlstringUnrealised profit and loss
    > curRealisedPnlstringThe realised PnL for the current holding position
    > sessionAvgPricestringUSDC contract session avg price, it is the same figure as avg entry price shown in the web UI
    > deltastringDelta
    > gammastringGamma
    > vegastringVega
    > thetastringTheta
    > cumRealisedPnlstringCumulative realised pnl
    • Futures & Perp: it is the all time cumulative realised P&L
    • Option: it is the realised P&L when you hold that position
    > positionStatusstringPosition status. Normal, Liq, Adl
    > adlRankIndicatorintegerAuto-deleverage rank indicator. What is Auto-Deleveraging?
    > isReduceOnlybooleanUseful when Bybit lower the risk limit
    • true: Only allowed to reduce the position. You can consider a series of measures, e.g., lower the risk limit, decrease leverage or reduce the position, add margin, or cancel orders, after these operations, you can call confirm new risk limit endpoint to check if your position can be removed the reduceOnly mark
    • false: There is no restriction, and it means your position is under the risk when the risk limit is systematically adjusted
    • Only meaningful for isolated margin & cross margin of USDT Perp, USDC Perp, USDC Futures, Inverse Perp and Inverse Futures, meaningless for others
    > mmrSysUpdatedTimestringUseful when Bybit lower the risk limit
    • When isReduceOnly=true: the timestamp (ms) when the MMR will be forcibly adjusted by the system
    • When isReduceOnly=false: the timestamp when the MMR had been adjusted by system
    • It returns the timestamp when the system operates, and if you manually operate, there is no timestamp
    • Keeps "" by default, if there was a lower risk limit system adjustment previously, it shows that system operation timestamp
    • Only meaningful for isolated margin & cross margin of USDT Perp, USDC Perp, USDC Futures, Inverse Perp and Inverse Futures, meaningless for others
    > leverageSysUpdatedTimestringUseful when Bybit lower the risk limit
    • When isReduceOnly=true: the timestamp (ms) when the leverage will be forcibly adjusted by the system
    • When isReduceOnly=false: the timestamp when the leverage had been adjusted by system
    • It returns the timestamp when the system operates, and if you manually operate, there is no timestamp
    • Keeps "" by default, if there was a lower risk limit system adjustment previously, it shows that system operation timestamp
    • Only meaningful for isolated margin & cross margin of USDT Perp, USDC Perp, USDC Futures, Inverse Perp and Inverse Futures, meaningless for others
    > createdTimestringTimestamp of the first time a position was created on this symbol (ms)
    > updatedTimestringPosition data updated timestamp (ms)
    > seqlongCross sequence, used to associate each fill and each position update
    • Different symbols may have the same seq, please use seq + symbol to check unique
    • Returns "-1" if the symbol has never been traded
    • Returns the seq updated by the last transaction when there are setting like leverage, risk limit

    Subscribe Example

    {
    "op": "subscribe",
    "args": [
    "position"
    ]
    }
    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.position_stream(callback=handle_message)
    while True:
    sleep(1)

    Stream Example

    {
    "id": "1003076014fb7eedb-c7e6-45d6-a8c1-270f0169171a",
    "topic": "position",
    "creationTime": 1697682317044,
    "data": [
    {
    "positionIdx": 2,
    "tradeMode": 0,
    "riskId": 1,
    "riskLimitValue": "2000000",
    "symbol": "BTCUSDT",
    "side": "",
    "size": "0",
    "entryPrice": "0",
    "leverage": "10",
    "positionValue": "0",
    "positionBalance": "0",
    "markPrice": "28184.5",
    "positionIM": "0",
    "positionMM": "0",
    "takeProfit": "0",
    "stopLoss": "0",
    "trailingStop": "0",
    "unrealisedPnl": "0",
    "curRealisedPnl": "1.26",
    "cumRealisedPnl": "-25.06579337",
    "sessionAvgPrice": "0",
    "createdTime": "1694402496913",
    "updatedTime": "1697682317038",
    "tpslMode": "Full",
    "liqPrice": "0",
    "bustPrice": "",
    "category": "linear",
    "positionStatus": "Normal",
    "adlRankIndicator": 0,
    "autoAddMargin": 0,
    "leverageSysUpdatedTime": "",
    "mmrSysUpdatedTime": "",
    "seq": 8327597863,
    "isReduceOnly": false
    }
    ]
    }