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,Sell
> sizestringPosition size
> positionIdxintegerUsed to identify positions in different position modes
> tradeModeintegerTrade mode
  • Classic & UTA (inverse): 0: cross-margin, 1: isolated margin
  • UTA: depreciated, always 0
> positionValuestringPosition value
> riskIdintegerRisk limit ID. Note: for portfolio margin mode, it returns 0, which the risk limit value is invalid
> riskLimitValuestringRisk limit value corresponding to riskId. Note: for portfolio margin mode, it returns "", which the risk limit value is invalid
> entryPricestringEntry price
> markPricestringMark price
> leveragestringLeverage. Note: for portfolio margin mode, it returns "", which the leverage value is invalid
> positionBalancestringPosition margin. For portfolio margin mode, it returns ""
> autoAddMarginintegerWhether to add margin automatically. 0: false, 1: true. For UTA, it is meaningful only when UTA enables ISOLATED_MARGIN
> positionMMstringPosition maintenance margin. Note: for portfolio margin mode, it returns ""
> positionIMstringPosition initial margin. Note: for portfolio margin mode, it returns ""
> liqPricestringPosition liquidation price
  • UTA (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
> bustPricestringEst.bankruptcy price. "" for Unified trade(spot/linear/options)
> tpslModestringDepreciated, meaningless here, always "Full". Spot does not return this field. Option returns ""
> 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, unique field for option
> gammastringGamma, unique field for option
> vegastringVega, unique field for option
> thetastringTheta, unique field for option
> 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
> createdTimestringPosition created timestamp (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
}
]
}