Trade WebSocket
The Trade WebSocket provides authenticated, real-time access to trading operations with lower latency than REST endpoints.
Endpoint
ws.send() wss://api.synthetix.io/v1/ws/tradeFeatures
- Low Latency Trading: Submit orders with minimal delay
- Real-time Updates: Instant order status notifications
- Persistent Connection: Single connection for all operations
- Authenticated Connection: EIP-712 signature-based connection authentication
- Mixed Operations: Read operations use connection auth, write operations use per-request signatures
- Bidirectional: Request-response and server-pushed updates
Connection Flow
- Establish Connection: Connect to WebSocket endpoint
- Authenticate: Send authentication message with signature
- Trade: Send trading commands using
method: "post" - Subscribe: Receive real-time updates
- Maintain: Send heartbeats to keep connection alive
Authentication Patterns
The Trade WebSocket uses two different authentication patterns depending on the operation:
| Operation | Pattern | Details |
|---|---|---|
| Connection auth | Stringified typed data | params.message contains JSON.stringify({types, domain, primaryType, message}) with a raw hex params.signature |
| Trading operations | Flat params with signature object | All fields (subAccountId, orders, nonce, etc.) go directly inside params, with signature: {v, r, s} as a nested object |
Connection authentication (method: "auth") sends the entire EIP-712 structure as a JSON-stringified string in params.message, paired with a raw hex signature string.
Trading operations (method: "post") use flat parameters with the signature split into {v, r, s} components. See WebSocket Authentication for the connection auth flow and Place Orders for an example of the trading pattern.
Authentication
Authentication is required immediately after connecting to the Trade WebSocket endpoint. See WebSocket Authentication for complete authentication flow and examples.
Quick Summary:- Connect to
wss://papi.synthetix.io/v1/ws/trade - Send authentication message with EIP-712 signature
- Receive authentication confirmation with
subAccountId - Begin trading operations
- Uses EIP-712 typed data signing
- Timestamp must be within ±60 seconds of server time
- Authentication establishes which subaccount you're trading with
- Connection remains authenticated until disconnected
Security
- Secure private key storage
- WSS encrypted connections
- Re-authentication on connection drops
- Server response validation
Comparison with REST
| Feature | WebSocket | REST |
|---|---|---|
| Latency | Lower (~10-50ms) | Higher (~50-200ms) |
| Connection | Persistent | Per-request |
| Real-time Updates | Yes | No (polling required) |
| Overhead | Minimal | HTTP headers each request |
| Complexity | Higher | Lower |
| Best For | Active trading | Occasional trades |
Available Methods
Order Management
- Place Orders - Submit new orders
- Modify Order - Modify existing order
- Cancel Orders - Cancel specific orders
Account Management
- Create Subaccount - Create a new subaccount
- Get Subaccount - Get account details
- Update Leverage - Adjust market leverage
- Update Subaccount Name - Rename a subaccount
- Withdraw Collateral - Withdraw funds to wallet
Delegation
- Add Delegated Signer - Add a delegated signer
- Get Delegated Signers - List delegated signers
- Remove Delegated Signer - Remove a delegated signer
Data Queries
- Get Open Orders - Query active open orders
- Get Order History - Query order history with filters
- Get Positions - Query open and closed positions
- Get Position History - Query closed position history
- Get Trades - Query trade execution history
- Get Balance Updates - Query deposit/withdrawal history
- Get Funding Payments - Query funding payment history
- Get Performance History - Query performance analytics
- Get Withdrawable Amounts - Query per-collateral withdrawable amounts
Authentication & Setup
- Authentication - WebSocket authentication flow
- Timeouts & Heartbeats - Connection management
Related Resources
- REST Trade API - REST API alternative for trading
- WebSocket Subscriptions - Real-time data streams
