Get Last Trades (WebSocket)
Retrieve the most recent trade execution history (fills) from Synthetix's orderbook across all users through the WebSocket connection. Each trade represents a filled order or partial fill that has been executed. This endpoint provides public market data without requiring authentication.
Endpoint
ws.send() wss://api.synthetix.io/v1/ws/infoRequest
Request Format
{
"id": "trades-1",
"method": "post",
"params": {
"action": "getLastTrades",
"symbol": "BTC-USDT",
"limit": 100
}
}Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Client-generated unique request identifier |
method | string | Yes | Must be "post" |
params | object | Yes | Request parameters wrapper |
params.action | string | Yes | Must be "getLastTrades" |
params.symbol | string | Yes | Trading pair symbol (e.g., "BTC-USDT") |
params.limit | integer | No | Maximum number of trades to return (default: 50, max: 100) |
Response
Success Response
{
"id": "trades-1",
"status": 200,
"result": {
"response": {
"trades": [
{
"tradeId": "123456789",
"symbol": "BTC-USDT",
"side": "buy",
"price": "50000.50",
"quantity": "0.1",
"timestamp": 1704067200500,
"isMaker": false
},
{
"tradeId": "123456788",
"symbol": "BTC-USDT",
"side": "sell",
"price": "50000.25",
"quantity": "0.05",
"timestamp": 1704067199800,
"isMaker": true
}
]
},
"status": "success"
}
}Response Fields
| Field | Type | Description |
|---|---|---|
result.response.trades | array | Array of trade objects (see below) |
result.status | string | Always "success" for successful responses |
Trade Object (Public)
| Field | Type | Description |
|---|---|---|
tradeId | string | Unique identifier for the trade |
symbol | string | Market symbol (e.g., "BTC-USDT") |
side | string | Order side: "buy" or "sell" |
price | string | Execution price as string |
quantity | string | Executed quantity as string |
timestamp | integer | Execution time in milliseconds since epoch |
isMaker | boolean | Whether this was a maker order (added liquidity) |
Error Response
{
"id": "trades-1",
"status": 400,
"result": null,
"error": {
"code": 400,
"message": "Invalid symbol"
}
}WebSocket Connection Example
const ws = new WebSocket('wss://papi.synthetix.io/v1/ws/info');
ws.onopen = () => {
// Request recent trades for BTC-USDT
ws.send(JSON.stringify({
id: 'trades-1',
method: 'post',
params: {
action: 'getLastTrades',
symbol: 'BTC-USDT',
limit: 50
}
}));
};
ws.onmessage = (event) => {
const response = JSON.parse(event.data);
if (response.id === 'trades-1' && response.status === 200) {
const data = response.result.response;
console.log('Last Trades:', data);
// Process trade data
data.trades.forEach(trade => {
console.log(`${trade.side} ${trade.quantity} @ ${trade.price}`);
});
}
};Examples
Get Recent Trades with Custom Limit
{
"id": "trades-custom",
"method": "post",
"params": {
"action": "getLastTrades",
"symbol": "BTC-USDT",
"limit": 25
}
}Filter by Symbol
{
"id": "trades-eth",
"method": "post",
"params": {
"action": "getLastTrades",
"symbol": "ETH-USDT",
"limit": 100
}
}Maximum Results
{
"id": "trades-max",
"method": "post",
"params": {
"action": "getLastTrades",
"symbol": "BTC-USDT",
"limit": 100
}
}Implementation Notes
- Public Data: No authentication required for this endpoint
- Symbol Required: A valid market symbol must be provided
- Limit Usage: Default limit is 50 trades, maximum 100 trades per request
- Sorting: Trades are returned in descending order by timestamp (newest first)
- Caching: Trade data is immutable once created, suitable for short-term caching
- Real-time Updates: For continuous updates, consider using WebSocket subscriptions for live trade streams
Use Cases
Market Analysis
- Recent price discovery and trade flow analysis
- Volume and liquidity assessment
- Market depth analysis when combined with orderbook data
Trading Interfaces
- Displaying recent market activity
- Trade history components
- Price movement indicators
Data Feeds
- Building market data aggregators
- Feeding external analytics systems
- Creating public market displays
Differences from getTrades
| Feature | getLastTrades (Public) | getTrades (Private) |
|---|---|---|
| Authentication | Not required | Required (EIP-712 signature) |
| Data Scope | All users | Specific subaccount only |
| Sensitive Data | Excluded | Included (fees, PnL, order IDs) |
| Symbol Parameter | Required | Optional |
| Maximum Limit | 100 trades | 1000 trades |
Performance Considerations
- Low Latency: WebSocket connection provides faster response times than REST
- Persistent Connection: Reuse the same connection for multiple requests
- Efficient Updates: Combine with orderbook subscriptions for complete market view
- Bandwidth: Filter by symbol to reduce data transfer
Validation Rules
- No authentication required (public Info WebSocket)
- No rate limiting beyond standard API limits
- Symbol parameter is required and must be a valid market symbol
- Limit must be between 1 and 100 (defaults to 50 if not specified)
Related Endpoints
- Orderbook Updates - Real-time orderbook changes
- Market Price Updates - Live price feeds
- REST Alternative - HTTP request for last trades