Skip to main content

Trades WebSocket

Streams a trade message every time a public trade prints on the symbol you've subscribed to.

Event nameFETCH_TRADES_CS_PRO
ConnectionSee Connection for handshake and namespace details.

Subscribe

import socketio

sio = socketio.Client()

BASE_URL = "wss://ws.coinswitch.co/"
NAMESPACE = "/coinswitchx"
pair = "BTC,INR"

sio.connect(
url=BASE_URL,
namespaces=[NAMESPACE],
transports="websocket",
socketio_path="/pro/realtime-rates-socket/spot",
wait=True,
wait_timeout=3600,
)

sio.emit(
"FETCH_TRADES_CS_PRO",
{"event": "subscribe", "pair": pair},
namespace=NAMESPACE,
)

@sio.on("FETCH_TRADES_CS_PRO", namespace=NAMESPACE)
def on_trade(data):
print("Trade:", data)

sio.wait()

Update payload

{
"E": 1673257880000,
"p": "1472499.0",
"q": "0.0004",
"s": "BTC,INR",
"t": 395531528,
"e": "coinswitchx"
}
FieldTypeDescription
EintegerEvent time (Unix milliseconds).
pstringTrade price.
qstringTrade quantity (base asset).
sstringSymbol in BASE,QUOTE form.
tintegerTrade ID.
estringExchange identifier.