Skip to main content

Trade

Subscribe to the recent trades stream.

After subscription, you will be pushed trade messages in real-time.

Push frequency: real-time

Topic:
publicTrade.{symbol}
Note: option uses baseCoin, e.g., publicTrade.BTC

Response Parameters

ParameterTypeComments
idstringMessage id. Unique field for option
topicstringTopic name
typestringData type. snapshot
tsnumberThe timestamp (ms) that the system generates the data
dataarrayObject. The element in the array is sort by matching time in ascending order
> TnumberThe timestamp (ms) that the order is filled
> sstringSymbol name
> SstringSide of taker. Buy,Sell
> vstringTrade size
> pstringTrade price
> LstringDirection of price change. Unique field for future
> istringTrade ID
> BTbooleanWhether it is a block trade order or not
> mPstringMark price, unique field for option
> iPstringIndex price, unique field for option
> mIvstringMark iv, unique field for option
> ivstringiv, unique field for option

Subscribe Example

from pybit.unified_trading import WebSocket
from time import sleep
ws = WebSocket(
testnet=True,
channel_type="linear",
)
def handle_message(message):
print(message)
ws.trade_stream(
symbol="BTCUSDT",
callback=handle_message
)
while True:
sleep(1)

Response Example

{
"topic": "publicTrade.BTCUSDT",
"type": "snapshot",
"ts": 1672304486868,
"data": [
{
"T": 1672304486865,
"s": "BTCUSDT",
"S": "Buy",
"v": "0.001",
"p": "16578.50",
"L": "PlusTick",
"i": "20f43950-d8dd-5b31-9112-a178eb6023af",
"BT": false
}
]
}