> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bulk.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Balances & Positions

> Apply margin, position, and transfer-lock updates to account state.

Use `marginUpdate`, `positionUpdate`, and `lockedAmountsUpdate` to maintain
balances and positions after an [account snapshot](https://docs.bulk.trade/api-reference/ws-account/snapshot.md).
These arrive on the public [account subscription](https://docs.bulk.trade/api-reference/ws-account.md),
without a signature. There is no network-side event filter; other account
messages may also arrive.

## When it arrives

Updates report changes to account margin, positions, or transfer and withdrawal
locks. Delivery is asynchronous relative to a trading `post` result; neither
arrival order acts as a barrier for the other stream.

## Handling

Apply reported values to the relevant state rather than adding them as numeric
increments. `marginUpdate` places account-local fields directly in `data`;
snapshots place them inside `data.margin`. For parents with attached isolated
accounts, incremental parent margin updates are suppressed: obtain local and
`agg*` totals from snapshots or [HTTP account state](https://docs.bulk.trade/api-reference/getAccount.md).
Do not depend on a margin delta after every isolated fill or add isolated
values to aggregate totals again.

Key positions by symbol and isolated-account identity. A zero-size update
closes that position row. Replace the locked-amount list when it updates;
an empty array clears all locks. Use protocol-reported margin and risk values
instead of reconstructing them from position rows.

There is no account sequence or replay cursor. On reconnect, replace state
from a fresh snapshot and reconcile missed fills through
[account history](https://docs.bulk.trade/api-reference/getAccount.md#history-queries).


## AsyncAPI

````yaml api-reference/asyncapi.yaml account-balances
id: account-balances
title: Balances and positions
description: >-
  Public read-only account subscription; no signature. This channel is a
  documentation view of selected messages, not a network-side event filter.
  Every view sends the same account subscription and the live connection can
  receive all account event types. Wait for accountSnapshot before treating
  account state as ready. Snapshot replaces state; identify positions by symbol
  and isoPubkey and subscribe to subaccounts separately. No replay cursor. Save
  the acknowledged topic for unsubscribe. Unsubscribe using the acknowledged
  topic; see [Connection Management](/api-reference/ws-connection#unsubscribe).
servers:
  - id: mainnet
    protocol: wss
    host: mainnet-ws1.bulk.trade
    bindings: []
    variables: []
  - id: testnet
    protocol: wss
    host: exchange-ws1.bulk.trade
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_1
    id: account-balancesSubscribe
    title: Subscribe
    type: receive
    messages:
      - &ref_3
        id: subscribe
        contentType: application/json
        payload:
          - name: Subscribe
            description: >-
              Schema defaults on this request are playground example prefills,
              not omitted-field defaults accepted by the network endpoint.
            type: object
            properties:
              - name: method
                type: string
                enumValues:
                  - subscribe
                required: true
              - name: subscription
                type: array
                description: >-
                  Playground form template only. Paste an account public key
                  into user before sending; the blank value is not a valid
                  account and no account is preselected.
                required: true
                properties:
                  - name: type
                    type: string
                    enumValues:
                      - account
                    required: true
                  - name: user
                    type: oneOf
                    description: >-
                      Paste the account public key to observe. No account is
                      preselected.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            method:
              type: string
              enum:
                - subscribe
              default: subscribe
              x-parser-schema-id: <anonymous-schema-312>
            subscription:
              type: array
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - account
                    default: account
                    x-parser-schema-id: <anonymous-schema-315>
                  user:
                    oneOf:
                      - type: string
                        description: Account public key in base58.
                        x-parser-schema-id: <anonymous-schema-317>
                      - type: array
                        minItems: 1
                        items:
                          type: string
                          x-parser-schema-id: <anonymous-schema-319>
                        x-parser-schema-id: <anonymous-schema-318>
                    description: >-
                      Paste the account public key to observe. No account is
                      preselected.
                    x-parser-schema-id: <anonymous-schema-316>
                required:
                  - type
                  - user
                x-parser-schema-id: <anonymous-schema-314>
              minItems: 1
              default:
                - type: account
                  user: ''
              description: >-
                Playground form template only. Paste an account public key into
                user before sending; the blank value is not a valid account and
                no account is preselected.
              x-parser-schema-id: <anonymous-schema-313>
          required:
            - method
            - subscription
          x-parser-schema-id: <anonymous-schema-311>
        title: Subscribe
        description: >-
          Schema defaults on this request are playground example prefills, not
          omitted-field defaults accepted by the network endpoint.
        example: |-
          {
            "method": "subscribe",
            "subscription": [
              {
                "type": "account",
                "user": "FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
              }
            ]
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribe
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: account-balances
  - &ref_2
    id: account-balancesEvents
    title: Receive events
    type: send
    messages:
      - &ref_4
        id: marginUpdate
        contentType: application/json
        payload:
          - name: Margin update
            description: Network-published marginUpdate
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - account
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: type
                    type: string
                    enumValues:
                      - marginUpdate
                    required: true
                  - name: totalMargin
                    type: number
                    required: false
                  - name: availableMargin
                    type: number
                    required: false
                  - name: executionImpact
                    type: number
                    required: false
                  - name: transferableBalance
                    type: number
                    required: false
                  - name: marginUsed
                    type: number
                    required: false
                  - name: marginBufferRate
                    type: number
                    required: false
                  - name: bufferedMargin
                    type: number
                    required: false
                  - name: notional
                    type: number
                    required: false
                  - name: realizedPnl
                    type: number
                    required: false
                  - name: unrealizedPnl
                    type: number
                    required: false
                  - name: fees
                    type: number
                    required: false
                  - name: funding
                    type: number
                    required: false
              - name: topic
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - account
              x-parser-schema-id: <anonymous-schema-425>
            data:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - marginUpdate
                  x-parser-schema-id: <anonymous-schema-427>
                totalMargin:
                  type: number
                  x-parser-schema-id: <anonymous-schema-428>
                availableMargin:
                  type: number
                  x-parser-schema-id: <anonymous-schema-429>
                executionImpact:
                  type: number
                  x-parser-schema-id: <anonymous-schema-430>
                transferableBalance:
                  type: number
                  x-parser-schema-id: <anonymous-schema-431>
                marginUsed:
                  type: number
                  x-parser-schema-id: <anonymous-schema-432>
                marginBufferRate:
                  type: number
                  x-parser-schema-id: <anonymous-schema-433>
                bufferedMargin:
                  type: number
                  x-parser-schema-id: <anonymous-schema-434>
                notional:
                  type: number
                  x-parser-schema-id: <anonymous-schema-435>
                realizedPnl:
                  type: number
                  x-parser-schema-id: <anonymous-schema-436>
                unrealizedPnl:
                  type: number
                  x-parser-schema-id: <anonymous-schema-437>
                fees:
                  type: number
                  x-parser-schema-id: <anonymous-schema-438>
                funding:
                  type: number
                  x-parser-schema-id: <anonymous-schema-439>
              required:
                - type
              x-parser-schema-id: <anonymous-schema-426>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-440>
          required:
            - type
            - data
            - topic
          x-parser-schema-id: <anonymous-schema-424>
        title: Margin update
        description: Network-published marginUpdate
        example: |-
          {
            "type": "account",
            "data": {
              "type": "marginUpdate",
              "totalMargin": 100500,
              "availableMargin": 95500,
              "executionImpact": -25,
              "transferableBalance": 94500,
              "marginUsed": 5000,
              "marginBufferRate": 0.05,
              "bufferedMargin": 5250,
              "notional": 50500,
              "realizedPnl": 1234.5,
              "unrealizedPnl": 567.8,
              "fees": 12.34,
              "funding": 5.67
            },
            "topic": "account.FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: marginUpdate
      - &ref_5
        id: positionUpdate
        contentType: application/json
        payload:
          - name: Position update
            description: Network-published positionUpdate
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - account
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: type
                    type: string
                    enumValues:
                      - positionUpdate
                    required: true
                  - name: symbol
                    type: string
                    required: false
                  - name: size
                    type: number
                    required: false
                  - name: price
                    type: number
                    required: false
                  - name: realizedPnl
                    type: number
                    required: false
                  - name: unrealizedPnl
                    type: number
                    required: false
                  - name: leverage
                    type: number
                    required: false
                  - name: liquidationPrice
                    type: number
                    required: false
                  - name: fairPrice
                    type: number
                    required: false
                  - name: notional
                    type: number
                    required: false
                  - name: fees
                    type: number
                    required: false
                  - name: funding
                    type: number
                    required: false
                  - name: maintenanceMargin
                    type: number
                    required: false
                  - name: impact
                    type: number
                    required: false
                  - name: reserve
                    type: array
                    required: false
                    properties:
                      - name: item
                        type: number
                        required: false
                  - name: worstCaseMaintenanceMargin
                    type: number
                    required: false
                  - name: lambda
                    type: number
                    required: false
                  - name: riskAllocation
                    type: number
                    required: false
                  - name: iso
                    type: boolean
                    required: false
              - name: topic
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - account
              x-parser-schema-id: <anonymous-schema-442>
            data:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - positionUpdate
                  x-parser-schema-id: <anonymous-schema-444>
                symbol:
                  type: string
                  x-parser-schema-id: <anonymous-schema-445>
                size:
                  type: number
                  x-parser-schema-id: <anonymous-schema-446>
                price:
                  type: number
                  x-parser-schema-id: <anonymous-schema-447>
                realizedPnl:
                  type: number
                  x-parser-schema-id: <anonymous-schema-448>
                unrealizedPnl:
                  type: number
                  x-parser-schema-id: <anonymous-schema-449>
                leverage:
                  type: number
                  x-parser-schema-id: <anonymous-schema-450>
                liquidationPrice:
                  type: number
                  x-parser-schema-id: <anonymous-schema-451>
                fairPrice:
                  type: number
                  x-parser-schema-id: <anonymous-schema-452>
                notional:
                  type: number
                  x-parser-schema-id: <anonymous-schema-453>
                fees:
                  type: number
                  x-parser-schema-id: <anonymous-schema-454>
                funding:
                  type: number
                  x-parser-schema-id: <anonymous-schema-455>
                maintenanceMargin:
                  type: number
                  x-parser-schema-id: <anonymous-schema-456>
                impact:
                  type: number
                  x-parser-schema-id: <anonymous-schema-457>
                reserve:
                  type: array
                  items:
                    type: number
                    x-parser-schema-id: <anonymous-schema-459>
                  x-parser-schema-id: <anonymous-schema-458>
                worstCaseMaintenanceMargin:
                  type: number
                  x-parser-schema-id: <anonymous-schema-460>
                lambda:
                  type: number
                  x-parser-schema-id: <anonymous-schema-461>
                riskAllocation:
                  type: number
                  x-parser-schema-id: <anonymous-schema-462>
                iso:
                  type: boolean
                  x-parser-schema-id: <anonymous-schema-463>
              required:
                - type
              x-parser-schema-id: <anonymous-schema-443>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-464>
          required:
            - type
            - data
            - topic
          x-parser-schema-id: <anonymous-schema-441>
        title: Position update
        description: Network-published positionUpdate
        example: |-
          {
            "type": "account",
            "data": {
              "type": "positionUpdate",
              "symbol": "BTC-USD",
              "size": 0.5,
              "price": 100000,
              "realizedPnl": 500,
              "unrealizedPnl": 500,
              "leverage": 5,
              "liquidationPrice": 95000,
              "fairPrice": 101000,
              "notional": 50500,
              "fees": 10,
              "funding": 2.5,
              "maintenanceMargin": 1000,
              "impact": 25,
              "reserve": [
                50,
                10
              ],
              "worstCaseMaintenanceMargin": 1250,
              "lambda": 0.05,
              "riskAllocation": 5000,
              "iso": false
            },
            "topic": "account.FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: positionUpdate
      - &ref_6
        id: lockedAmountsUpdate
        contentType: application/json
        payload:
          - name: Locked amounts update
            description: Network-published lockedAmountsUpdate
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - account
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: type
                    type: string
                    enumValues:
                      - lockedAmountsUpdate
                    required: true
                  - name: lockedAmounts
                    type: array
                    required: false
                    properties:
                      - name: hash
                        type: string
                        required: false
                      - name: symbol
                        type: string
                        required: false
                      - name: amount
                        type: number
                        required: false
                      - name: lockedAt
                        type: number
                        description: Unix timestamp in nanoseconds.
                        required: false
              - name: topic
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - account
              x-parser-schema-id: <anonymous-schema-466>
            data:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - lockedAmountsUpdate
                  x-parser-schema-id: <anonymous-schema-468>
                lockedAmounts:
                  type: array
                  items:
                    type: object
                    properties:
                      hash:
                        type: string
                        x-parser-schema-id: <anonymous-schema-471>
                      symbol:
                        type: string
                        x-parser-schema-id: <anonymous-schema-472>
                      amount:
                        type: number
                        x-parser-schema-id: <anonymous-schema-473>
                      lockedAt:
                        type: number
                        description: Unix timestamp in nanoseconds.
                        x-parser-schema-id: <anonymous-schema-474>
                    x-parser-schema-id: <anonymous-schema-470>
                  x-parser-schema-id: <anonymous-schema-469>
              required:
                - type
              x-parser-schema-id: <anonymous-schema-467>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-475>
          required:
            - type
            - data
            - topic
          x-parser-schema-id: <anonymous-schema-465>
        title: Locked amounts update
        description: Network-published lockedAmountsUpdate
        example: |-
          {
            "type": "account",
            "data": {
              "type": "lockedAmountsUpdate",
              "lockedAmounts": [
                {
                  "hash": "uQ8yioSC6fYLWwWS2XAi97vMJXKur3GKr7DEp1tdMqs",
                  "symbol": "USDC",
                  "amount": 500,
                  "lockedAt": 1700000000000000000
                }
              ]
            },
            "topic": "account.FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: lockedAmountsUpdate
      - &ref_7
        id: subscribed
        contentType: application/json
        payload:
          - name: Subscribed
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - subscriptionResponse
                required: true
              - name: topics
                type: array
                required: false
                properties:
                  - name: item
                    type: string
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - subscriptionResponse
              x-parser-schema-id: <anonymous-schema-418>
            topics:
              type: array
              items:
                type: string
                x-parser-schema-id: <anonymous-schema-420>
              x-parser-schema-id: <anonymous-schema-419>
          required:
            - type
          x-parser-schema-id: <anonymous-schema-417>
        title: Subscribed
        example: |-
          {
            "type": "subscriptionResponse",
            "topics": [
              "account.FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
            ]
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribed
      - &ref_8
        id: unsubscribed
        contentType: application/json
        payload:
          - name: Unsubscribed
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - unsubscribeResponse
                required: true
              - name: topic
                type: string
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - unsubscribeResponse
              x-parser-schema-id: <anonymous-schema-422>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-423>
          required:
            - type
          x-parser-schema-id: <anonymous-schema-421>
        title: Unsubscribed
        example: |-
          {
            "type": "unsubscribeResponse",
            "topic": "account.FuueqefENiGEW6uMqZQgmwjzgpnb85EgUcZa5Em4PQh7"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: unsubscribed
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
receiveMessages:
  - *ref_4
  - *ref_5
  - *ref_6
  - *ref_7
  - *ref_8
extensions:
  - id: x-parser-unique-object-id
    value: account-balances
securitySchemes: []

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.