{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tradingview/json-schema/tradingview-stream-positions-message-schema.json",
  "title": "StreamPositionsMessage",
  "x-generated": "2026-11-05",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tradingview-broker-rest-api-openapi.yml#/components/schemas/StreamPositionsMessage",
  "type": "array",
  "items": {
    "anyOf": [
      {
        "$ref": "#/$defs/Position"
      },
      {
        "$ref": "#/$defs/StreamClosedPosition"
      }
    ]
  },
  "$defs": {
    "CustomFieldsValueItem": {
      "title": "CustomFieldsValueItem",
      "type": "object",
      "properties": {
        "id": {
          "description": "Column identifier as defined in [/config](#operation/getConfiguration) response.",
          "type": "string"
        },
        "value": {
          "description": "Localized column value",
          "type": "string"
        }
      },
      "required": [
        "id",
        "value"
      ],
      "additionalProperties": false
    },
    "Position": {
      "title": "Position",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier.",
          "type": "string"
        },
        "instrument": {
          "description": "Instrument name that is used on a broker's side.",
          "type": "string"
        },
        "qty": {
          "description": "Quantity.",
          "type": "number"
        },
        "side": {
          "description": "Side.",
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ]
        },
        "avgPrice": {
          "description": "Average price of position trades.",
          "type": "number"
        },
        "unrealizedPl": {
          "description": "Unrealized (open) profit/loss.",
          "type": "number"
        },
        "message": {
          "$ref": "#/$defs/PositionInformationalMessage"
        },
        "lastModified": {
          "description": "Indicates the time when the position was last modified, Unix timestamp (UTC).",
          "type": "number"
        },
        "customFields": {
          "type": "array",
          "description": "Localized position custom fields values data.\nCustom fields are configured in the [/config](#operation/getConfiguration) endpoint response.\n",
          "items": {
            "$ref": "#/$defs/CustomFieldsValueItem"
          },
          "minItems": 1
        }
      },
      "required": [
        "id",
        "instrument",
        "qty",
        "side",
        "avgPrice"
      ],
      "additionalProperties": false
    },
    "PositionInformationalMessage": {
      "title": "PositionInformationalMessage",
      "description": "Informational message description, that will be displayed for the position in the Account manager. The message will be marked\nwith a color, corresponding to a message type.\n",
      "type": "object",
      "properties": {
        "text": {
          "description": "Message text",
          "type": "string"
        },
        "type": {
          "description": "Message type",
          "type": "string",
          "enum": [
            "information",
            "warning",
            "error"
          ]
        }
      },
      "required": [
        "text",
        "type"
      ],
      "additionalProperties": false
    },
    "StreamClosedPosition": {
      "title": "StreamClosedPosition",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier.",
          "type": "string"
        },
        "qty": {
          "description": "Quantity. Should be equal to `0`.",
          "type": "number"
        }
      },
      "required": [
        "id",
        "qty"
      ]
    }
  }
}