WebSocket API
GTX DEX provides comprehensive WebSocket support for real-time market data, order updates, and yield tracking. The WebSocket API enables building responsive trading applications with live data feeds.Connection Details
WebSocket Endpoint
Connection Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | No | API key for enhanced rate limits |
signature | string | No | HMAC signature for private streams |
timestamp | number | No | Request timestamp |
Message Format
All WebSocket messages use JSON format:Message Fields
| Field | Type | Description |
|---|---|---|
method | string | Action type: SUBSCRIBE, UNSUBSCRIBE, or stream data |
params | array | Stream names or parameters |
id | number | Request ID for tracking responses |
Public Data Streams
Ticker Stream
Real-time 24hr ticker statistics for all symbols.Subscribe to Ticker
Subscribe to Ticker
ticker@{symbol} or !ticker@arrTicker Data Format
Ticker Data Format
Trade Stream
Real-time trade execution data.Subscribe to Trades
Subscribe to Trades
trade@{symbol} or !trade@arrTrade Data Format
Trade Data Format
Order Book Stream
Real-time order book depth updates.Subscribe to Order Book
Subscribe to Order Book
depth@{symbol}- Full order bookdepth{levels}@{symbol}- Partial depth (5, 10, 20 levels)depthUpdate@{symbol}- Incremental updates
Order Book Data Format
Order Book Data Format
Candlestick Stream
Real-time OHLCV candlestick data.Subscribe to Candlesticks
Subscribe to Candlesticks
Candlestick Data Format
Candlestick Data Format
Private Data Streams
User Order Updates
Real-time updates for user orders.Subscribe to Order Updates
Subscribe to Order Updates
Order Update Format
Order Update Format
Account Updates
Real-time balance and position updates.Subscribe to Account Updates
Subscribe to Account Updates
Account Update Format
Account Update Format
Yield Updates
Real-time yield generation and rewards updates.Subscribe to Yield Updates
Subscribe to Yield Updates
Yield Update Format
Yield Update Format
Implementation Examples
TypeScript WebSocket Client
Advanced Features
Rate Limiting
WebSocket connections are subject to rate limits:| Connection Type | Limit | Notes |
|---|---|---|
| Public Streams | 5 connections per IP | Market data only |
| Private Streams | 3 connections per API key | User data streams |
| Messages/Second | 100 per connection | Subscription requests |
Connection Management
Stream Aggregation
Combine multiple streams for complex analysis:Error Handling
Common Error Codes
| Code | Message | Solution |
|---|---|---|
1000 | Normal closure | Connection closed normally |
1006 | Abnormal closure | Network issue, reconnect |
4001 | Invalid message format | Check JSON format |
4002 | Invalid stream name | Verify stream syntax |
4003 | Connection failed | Check connection parameters |
4004 | Rate limit exceeded | Reduce request frequency |
Robust Error Handling
The WebSocket API provides real-time access to all GTX DEX data streams. Combine with yield tracking to build applications that monitor both trading and earning opportunities in real-time.
