Skip to content

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/info

Request

Request Format

{
  "id": "trades-1",
  "method": "post",
  "params": {
    "action": "getLastTrades",
    "symbol": "BTC-USDT",
    "limit": 100
  }
}

Request Parameters

ParameterTypeRequiredDescription
idstringYesClient-generated unique request identifier
methodstringYesMust be "post"
paramsobjectYesRequest parameters wrapper
params.actionstringYesMust be "getLastTrades"
params.symbolstringYesTrading pair symbol (e.g., "BTC-USDT")
params.limitintegerNoMaximum 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

FieldTypeDescription
result.response.tradesarrayArray of trade objects (see below)
result.statusstringAlways "success" for successful responses

Trade Object (Public)

FieldTypeDescription
tradeIdstringUnique identifier for the trade
symbolstringMarket symbol (e.g., "BTC-USDT")
sidestringOrder side: "buy" or "sell"
pricestringExecution price as string
quantitystringExecuted quantity as string
timestampintegerExecution time in milliseconds since epoch
isMakerbooleanWhether 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

FeaturegetLastTrades (Public)getTrades (Private)
AuthenticationNot requiredRequired (EIP-712 signature)
Data ScopeAll usersSpecific subaccount only
Sensitive DataExcludedIncluded (fees, PnL, order IDs)
Symbol ParameterRequiredOptional
Maximum Limit100 trades1000 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