Skip to main content

WebSocket API

Beta

The WebSocket API is currently in beta. Features and endpoints are subject to change.

Overview

The TradeZero WebSocket API provides real-time streaming updates for account data. The API follows the standard RFC 6455 WebSocket protocol, with all messages exchanged in JSON format.

Base URL: wss://webapi.tradezero.com/stream

Connection & Authentication

Step 1: Connect to the WebSocket

Connect to the WebSocket URL:

wss://webapi.tradezero.com/stream/{endpoint}

Upon successful connection, you'll receive a system message indicating that authentication is required:

{
"@system": true,
"ts": 1770236373127,
"status": "PENDING_AUTH",
"message": "Send authenticate message"
}

Step 2: Authenticate

Send your API credentials as a JSON message:

{
"key": "YOUR_TZ-API-KEY-ID",
"secret": "YOUR_TZ-API-SECRET-KEY"
}

Authentication Responses

Success:

{
"@system": true,
"ts": 1770237123968,
"status": "CONNECTED"
}

Failure:

{
"@system": true,
"ts": 1770236412039,
"status": "FAILED_AUTH",
"message": "Authentication parameters not properly provided"
}

Available Endpoints

Profit & Loss (PnL) Stream

Endpoint: wss://webapi.tradezero.com/stream/pnl

Real-time streaming of account profit and loss updates with position-level details.

See the PnL Stream documentation for detailed information.

Portfolio Stream

Endpoint: wss://webapi.tradezero.com/stream/portfolio

Real-time streaming of order status changes and position updates driven by order activity.

See the Portfolio Stream documentation for detailed information.

System Messages

Messages with "@system": true are system-level notifications about connection status and authentication. Always check for these messages to handle authentication and connection errors properly.

Disconnecting

To stop receiving updates, simply disconnect from the WebSocket. There is currently no unsubscribe message; closing the connection will terminate all subscriptions.