Skip to content

Update Subaccount Name (WebSocket)

Rename an existing trading subaccount through the WebSocket connection. The authenticated subaccount's display name is updated to the new value provided in the request.

Endpoint

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

Request

Request Format

{
  "id": "rename-subaccount-1",
  "method": "post",
  "params": {
    "action": "updateSubAccountName",
    "subAccountId": "1867542890123456789",
    "name": "Scalping Strategy",
    "nonce": 1704067200000,
    "expiresAfter": 1704067300,
    "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 Fields

ParameterTypeRequiredDescription
actionstringYesMust be "updateSubAccountName"
subAccountIdstringYesSubaccount identifier to rename
namestringYesNew display name for the subaccount
nonceintegerYesIncrementing nonce (Unix ms timestamp as number)
expiresAfterintegerNoOptional expiration timestamp in seconds (0 = no expiration)
signatureobjectYesEIP-712 signature

EIP-712 Type Definition

const UpdateSubAccountNameTypes = {
  UpdateSubAccountName: [
    { name: "subAccountId", type: "uint256" },
    { name: "name", type: "string" },
    { name: "nonce", type: "uint256" },
    { name: "expiresAfter", type: "uint256" }
  ]
}

Response Format

Success Response

{
  "id": "rename-subaccount-1",
  "requestId": "rename-subaccount-1",
  "status": 200,
  "timestamp": 1704067200123,
  "result": {
    "status": "success",
    "response": {
      "subAccountId": "1867542890123456789",
      "name": "Scalping Strategy"
    }
  }
}
Response Fields:
FieldTypeDescription
idstringEcho of the client-provided request identifier
requestIdstringSame value as id (included for forward compatibility)
statusintegerHTTP status code
timestampintegerServer timestamp in milliseconds (Unix epoch)
result.statusstring"success" on successful requests
result.response.subAccountIdstringSubaccount identifier that was renamed
result.response.namestringThe new display name that was applied

Error Response

{
  "id": "rename-subaccount-1",
  "requestId": "rename-subaccount-1",
  "status": 400,
  "timestamp": 1704067200456,
  "error": {
    "code": 400,
    "errorCode": "VALIDATION_ERROR",
    "category": "REQUEST",
    "message": "subAccountId is required",
    "retryable": false
  }
}

Implementation Example

import { ethers } from 'ethers';
 
async function updateSubAccountName(ws, signer, subAccountId, name) {
  const nonce = Date.now();
  const expiresAfter = Math.floor(Date.now() / 1000) + 30;
 
  const domain = {
    name: "Synthetix",
    version: "1",
    chainId: 1,
    verifyingContract: "0x0000000000000000000000000000000000000000"
  };
 
  const types = {
    UpdateSubAccountName: [
      { name: "subAccountId", type: "uint256" },
      { name: "name", type: "string" },
      { name: "nonce", type: "uint256" },
      { name: "expiresAfter", type: "uint256" }
    ]
  };
 
  const message = {
    subAccountId: BigInt(subAccountId),
    name,
    nonce: BigInt(nonce),
    expiresAfter: BigInt(expiresAfter)
  };
 
  const sig = await signer.signTypedData(domain, types, message);
  const signature = ethers.Signature.from(sig);
 
  ws.send(JSON.stringify({
    id: `rename-subaccount-${Date.now()}`,
    method: "post",
    params: {
      action: "updateSubAccountName",
      subAccountId,
      name,
      nonce,
      expiresAfter,
      signature: { v: signature.v, r: signature.r, s: signature.s }
    }
  }));
}
 
// Usage: Rename a subaccount
await updateSubAccountName(ws, signer, "1867542890123456789", "Grid Trading Bot");

Code Examples

Rename Subaccount

{
  "id": "rename-1",
  "method": "post",
  "params": {
    "action": "updateSubAccountName",
    "subAccountId": "1867542890123456789",
    "name": "Main Trading",
    "nonce": 1704067200000,
    "expiresAfter": 1704067300,
    "signature": { "v": 28, "r": "0x...", "s": "0x..." }
  }
}

Rename to Strategy-Based Name

{
  "id": "rename-2",
  "method": "post",
  "params": {
    "action": "updateSubAccountName",
    "subAccountId": "1867542890123456789",
    "name": "Grid Trading Bot",
    "nonce": 1704067200001,
    "expiresAfter": 1704067301,
    "signature": { "v": 28, "r": "0x...", "s": "0x..." }
  }
}

Error Handling

Common Errors

Error CodeMessageDescription
400subAccountId is requiredNo subaccount was specified
400Invalid request bodyRequest payload could not be parsed
400Name already in useAnother subaccount already uses this name
404Subaccount not foundThe specified subaccount does not exist

Signing

All trading methods are signed using EIP-712. Each successful trading request will contain:

  • A piece of structured data that includes the sender address
  • A signature of the hash of that structured data, signed by the sender

For detailed information on EIP-712 signing, see EIP-712 Signing.

Nonce Management

The nonce system prevents replay attacks and ensures order uniqueness:

  • Use any positive integer as nonce
  • Each nonce must be greater than the previous one (incrementing)
  • Date.now() is a convenient option, not a requirement
  • If nonce conflicts occur, increment by 1 and retry

:::note SubAccountAction Exception SubAccountAction endpoints (getPositions, getOpenOrders, getOrdersHistory, getTrades, getFundingPayments, getSubAccount, getSubAccounts, getDelegatedSigners, getBalanceUpdates) do not require a nonce. Only the signature and optional expiresAfter parameters are needed. :::

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