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

note

For Futures and Spot, a single message has up to 1024 trades. So it may have mutiple messages for the same cross.

Response Parameters

ParameterTypeComments
idstringMessage id. Unique field for option
topicstringTopic name
typestringData type. snapshot
tsnumberThe timestamp (ms) that the system generates the data
dataarrayObject. Sorted by the time the trade was matched 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 Perps & futures
> istringTrade ID
> BTbooleanWhether it is a block trade order or not
> RPIbooleanWhether it is a RPI trade or not
> seqintegercross sequence
> 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,
"seq": 1783284617
}
]
}