Skip to content

Get Trades For Position (WebSocket)

Retrieve trade execution history (fills) for a specific position within a subaccount through the WebSocket connection. Unlike getTrades, which returns all trades for a subaccount, this endpoint filters trades to those associated with a single position identified by positionId.

Request-Response vs Subscriptions

This method provides on-demand snapshots of trades for a specific position. For real-time updates when new trades execute, use SubAccount Updates Subscription.

MethodPurposeWhen to Use
getTradesForPositionPosition-specific trade historyAnalyzing fills for a single position
getTradesAll trades for a subaccountBroad trade history, reconciliation
Trade Updates SubscriptionReal-time notificationsLive UI updates, trade event handling

Endpoint

ws.send() wss://api.synthetix.io/v1/ws/trade

Request

Request Format

{
  "id": "trades-pos-1",
  "method": "post",
  "params": {
    "action": "getTradesForPosition",
    "subAccountId": "1867542890123456789",
    "positionId": "42",
    "limit": 100,
    "offset": 0,
    "expiresAfter": 1704067500,
    "signature": {
      "v": 28,
      "r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
      "s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
    }
  }
}

Parameters

Request Parameters

ParameterTypeRequiredDescription
idstringYesClient-generated unique request identifier
methodstringYesMust be "post"
paramsobjectYesContains all parameters for the request

Params Object

ParameterTypeRequiredDescription
actionstringYesMust be "getTradesForPosition"
subAccountIdstringYesSubaccount identifier that owns the position
positionIdstringYesPosition ID to retrieve trades for (numeric string)
limitintegerNoMaximum number of trades to return (default: 100, max: 1000)
offsetintegerNoNumber of trades to skip for pagination (default: 0)
expiresAfterintegerNoOptional expiration timestamp in Unix seconds (use 0 for no expiration)
signatureobjectYesEIP-712 signature using SubAccountAction type
Important Notes:
  • This endpoint uses SubAccountAction EIP-712 type (no nonce required, only expiresAfter is optional)
  • positionId is required and must be a valid numeric string
  • Unlike getTrades, this endpoint does not support symbol, orderId, startTime, or endTime filters

EIP-712 Signature

const domain = {
  name: "Synthetix",
  version: "1",
  chainId: 1,
  verifyingContract: "0x0000000000000000000000000000000000000000"
};
 
const types = {
  SubAccountAction: [
    { name: "subAccountId", type: "uint256" },
    { name: "action", type: "string" },
    { name: "expiresAfter", type: "uint256" }
  ]
};
 
const message = {
  subAccountId: "1867542890123456789",
  action: "getTradesForPosition",
  expiresAfter: 0
};
 
const signature = await signer._signTypedData(domain, types, message);

Response Format

Success Response

{
  "id": "trades-pos-1",
  "status": 200,
  "result": {
    "status": "success",
    "response": {
      "trades": [
        {
          "tradeId": "123456789",
          "order": {
            "venueId": "1948058938469519360",
            "clientId": "cli-1948058938469519360"
          },
          "orderId": "1948058938469519360",
          "symbol": "BTC-USDT",
          "side": "buy",
          "direction": "open long",
          "orderType": "limit",
          "price": "50000.50",
          "quantity": "0.1",
          "realizedPnl": "0.00",
          "fee": "5.00",
          "feeRate": "0.001",
          "markPrice": "50025.00",
          "entryPrice": "50000.50",
          "timestamp": 1704067200500,
          "maker": false,
          "reduceOnly": false,
          "triggeredByLiquidation": false,
          "postOnly": false
        },
        {
          "tradeId": "123456790",
          "order": {
            "venueId": "1948058938469519361",
            "clientId": "cli-1948058938469519361"
          },
          "orderId": "1948058938469519361",
          "symbol": "BTC-USDT",
          "side": "buy",
          "direction": "open long",
          "orderType": "market",
          "price": "50100.00",
          "quantity": "0.05",
          "realizedPnl": "0.00",
          "fee": "2.51",
          "feeRate": "0.001",
          "markPrice": "50110.00",
          "entryPrice": "50033.67",
          "timestamp": 1704067201000,
          "maker": false,
          "reduceOnly": false,
          "triggeredByLiquidation": false,
          "postOnly": false
        }
      ],
      "hasMore": false
    }
  }
}

Empty Result

{
  "id": "trades-pos-1",
  "status": 200,
  "result": {
    "status": "success",
    "response": {
      "trades": [],
      "hasMore": false
    }
  }
}

Error Response

{
  "id": "trades-pos-1",
  "status": 400,
  "result": null,
  "error": {
    "code": 400,
    "message": "positionId is required"
  }
}

Response Fields

FieldTypeDescription
idstringEchoed request identifier
statusintegerHTTP-style status code
result.statusstring"success" on success
result.response.tradesarrayArray of trade objects for the specified position
result.response.hasMorebooleanWhether more trades exist beyond current result

Trade Object Fields

FieldTypeDescription
tradeIdstringUnique trade identifier
order.venueIdstringCanonical venue-generated order ID
order.clientIdstringOptional client-provided order ID
orderIdstringDeprecated legacy order ID
symbolstringTrading pair symbol (e.g., "BTC-USDT")
sidestringTrade side: "buy" or "sell"
directionstringPosition effect (e.g., "open long", "close long", "open short", "close short")
orderTypestringOrder type that produced this trade: "limit", "market", "stopMarket", "takeProfitMarket", "stopLimit", or "takeProfitLimit"
pricestringExecution price
quantitystringFilled quantity for this trade
realizedPnlstringProfit/loss realized from this trade
feestringTrading fee charged
feeRatestringFee rate applied (maker/taker rate)
markPricestringMark price at time of trade execution
entryPricestringPosition's average entry price at time of trade
timestampintegerTrade execution timestamp (Unix milliseconds)
makerbooleanWhether this trade provided liquidity (maker) or took liquidity (taker)
reduceOnlybooleanWhether this trade reduced an existing position
triggeredByLiquidationbooleanWhether this trade was part of a liquidation
postOnlybooleanWhether this order was post-only (maker-only)

Migration Note: Use order.venueId as canonical order reference. orderId remains for backward compatibility.

Code Examples

Get All Trades for a Position

{
  "id": "trades-pos-all",
  "method": "post",
  "params": {
    "action": "getTradesForPosition",
    "subAccountId": "1867542890123456789",
    "positionId": "42",
    "expiresAfter": 0,
    "signature": { "v": 28, "r": "0x...", "s": "0x..." }
  }
}

Paginated Request

{
  "id": "trades-pos-page2",
  "method": "post",
  "params": {
    "action": "getTradesForPosition",
    "subAccountId": "1867542890123456789",
    "positionId": "42",
    "limit": 50,
    "offset": 50,
    "expiresAfter": 0,
    "signature": { "v": 28, "r": "0x...", "s": "0x..." }
  }
}

Validation Rules

  • Subaccount ID must be valid and accessible
  • positionId is required and must be a valid numeric string
  • Limit must be between 0 and 1000 (default: 100)
  • Offset must be non-negative (default: 0)

Common Errors

ErrorDescriptionSolution
positionId is requiredMissing position IDProvide positionId in request params
positionId must be a valid numeric valueNon-numeric position IDUse a numeric string for positionId
subaccountId is requiredMissing subaccountInclude subAccountId in request params
Invalid limitLimit exceeds maximum or is negativeUse limit between 0 and 1000
Invalid offsetNegative offset valueUse offset >= 0
Authentication failedInvalid signatureVerify signature generation
500 Internal Server ErrorTrade history contains an unrecognized direction value (e.g. "unknown", "", or any unexpected string)Indicates corrupted trade direction data on the backend that requires operator investigation. Previously these cases were silently defaulted to side: "buy" in the response.
Error CodeDescriptionRetryable
UNAUTHORIZEDEIP-712 signature validation failedNo
VALIDATION_ERRORRequest validation failedNo
MISSING_REQUIRED_FIELDRequired field is missingNo
INVALID_FORMATField format is invalidNo
INVALID_VALUEInvalid parameter valueNo
RATE_LIMIT_EXCEEDEDToo many requests in time windowYes
INSUFFICIENT_MARGINNot enough margin for tradeNo
ORDER_NOT_FOUNDOrder does not existNo
OPERATION_TIMEOUTOperation timed outYes

Next Steps