T-Invest Node SDK Node.js
On this page

Configure a streaming CLI command

Use this reference when stream run needs to open a particular stream with specified subscriptions. Describe the stream, initial requests, and exit conditions in JSON. The CLI validates the configuration before creating the SDK, then opens the stream or returns a configuration error.

Choose a stream and subscriptions

The configuration selects a stream, subscriptions, and output options. For standard subscriptions, the CLI builds requests from the generated gRPC contracts.

This is the smallest valid configuration.

marketdata-stream.json
{
  "stream": "marketdata.marketDataServerSideStream",
  "subscriptions": {
    "trades": [
      {
        "instrumentId": "BBG00QPYJ5H0"
      }
    ]
  },
  "runtime": {
    "format": "jsonl"
  }
}

Set configuration fields

Start with stream. Provide subscriptions for the server-side market data stream, requests for the bidirectional stream, or accounts for account events.

Field Type Required Purpose
stream string Always Selects the streaming API method
subscriptions object Server-side market data stream Market data subscriptions
requests object[] Bidirectional market data stream Static set of initial requests
accounts string[] Account streams Account identifiers for operations and orders streams
runtime object Optional Output and exit settings

Supported stream values

  • marketdata.marketDataStream
  • marketdata.marketDataServerSideStream
  • operations.portfolioStream
  • operations.positionsStream
  • orders.tradesStream

marketdata.marketDataStream uses a separate requests field for its bidirectional stream. The CLI sends the configured requests first, then reads provider events.

Configuration validation rejects rawRequests for all streams.

Configure execution and output

runtime controls the output format, event count, and exit conditions.

marketdata-stream.json
{
  "runtime": {
    "format": "jsonl",
    "maxEvents": 100,
    "durationMs": 60000,
    "idleTimeoutMs": 15000,
    "includePings": false,
    "includeSubscriptionEvents": true,
    "raw": false
  }
}
  • format — output format. The supported value is jsonl.
  • maxEvents — exit after printing N events.
  • durationMs — exit N milliseconds after the stream starts.
  • idleTimeoutMs — exit after N milliseconds without events.
  • includePings — include ping events in stdout.
  • includeSubscriptionEvents — include subscription statuses in stdout.
  • raw — output the generated response without the normalized event envelope.

Subscribe to market data

subscriptions groups subscriptions by event family.

marketdata-stream.json
{
  "stream": "marketdata.marketDataServerSideStream",
  "subscriptions": {
    "candles": [
      {
        "instrumentId": "BBG00QPYJ5H0",
        "interval": "1min",
        "waitingClose": false
      }
    ],
    "orderBooks": [
      {
        "instrumentId": "BBG00QPYJ5H0",
        "depth": 10
      }
    ],
    "trades": [
      {
        "instrumentId": "BBG00QPYJ5H0"
      }
    ],
    "info": [
      {
        "instrumentId": "BBG00QPYJ5H0"
      }
    ],
    "lastPrices": [
      {
        "instrumentId": "BBG00QPYJ5H0"
      }
    ]
  },
  "runtime": {
    "format": "jsonl",
    "maxEvents": 100,
    "includePings": false
  }
}

Subscription defaults and rules

  • The CLI always subscribes using SUBSCRIPTION_ACTION_SUBSCRIBE and rejects action in the configuration.
  • Deprecated figi fields of the generated contracts keep their protobuf defaults and are omitted during serialization.
  • instrumentId is required for every instrument.
  • waitingClose defaults to false.
  • orderBooks[].depth is required and must be an integer from 1 to 2147483647, the protobuf int32 range.

Use the same waitingClose value for all candle subscriptions within one request. For a server-side stream, this applies to the entire subscriptions.candles array. For a bidirectional stream, it applies to instruments in one subscribeCandles request. An omitted field counts as false.

Supported candle interval aliases

  • 1min
  • 5min

The generated streaming SubscriptionInterval supports only one- and five-minute intervals. Other historical candle CLI aliases are unsupported here.

Choose a Market Data stream

marketdata.marketDataServerSideStream sends one initial request built from subscriptions, then reads events.

marketdata.marketDataStream is bidirectional. stream run accepts a static set of typed initial requests in the configuration. Additional requests from stdin, files, timers, and interactive input are unsupported.

Bidirectional stream configuration
marketdata-bidirectional.json
{
  "stream": "marketdata.marketDataStream",
  "requests": [
    {
      "type": "subscribeTrades",
      "instruments": [
        {
          "instrumentId": "BBG00QPYJ5H0"
        }
      ]
    },
    {
      "type": "getMySubscriptions"
    }
  ],
  "runtime": {
    "format": "jsonl",
    "maxEvents": 50
  }
}

Supported request type values

  • subscribeCandles
  • subscribeOrderBook
  • subscribeTrades
  • subscribeInfo
  • subscribeLastPrice
  • getMySubscriptions

Request entries use the same instrument fields as server-side market data subscriptions.

  • subscribeCandles requires instrumentId and interval. waitingClose is optional.
  • subscribeOrderBook requires instrumentId and depth.
  • subscribeTrades, subscribeInfo, and subscribeLastPrice require instrumentId.
  • getMySubscriptions rejects instruments.

Use requests with the typed variants above to send bidirectional requests.

Subscribe to account events

Portfolio stream

portfolio-stream.json
{
  "stream": "operations.portfolioStream",
  "accounts": ["2000000000"],
  "runtime": {
    "format": "jsonl",
    "maxEvents": 50
  }
}

Positions stream

positions-stream.json
{
  "stream": "operations.positionsStream",
  "accounts": ["2000000000"],
  "runtime": {
    "format": "jsonl",
    "maxEvents": 50
  }
}

Order trades stream

order-trades-stream.json
{
  "stream": "orders.tradesStream",
  "accounts": ["2000000000"],
  "runtime": {
    "format": "jsonl",
    "includePings": false
  }
}
  • accounts must contain at least one account ID.
  • The CLI passes the IDs to accounts in the generated request.
  • Account streams reject subscriptions.
  • Unknown fields are rejected before the SDK is created.

Validate configuration before starting

Configuration validation rejects the following.

  • Unknown stream values.
  • Missing accounts for account streams.
  • Empty subscriptions for a server-side market data stream.
  • Missing or empty requests for marketdata.marketDataStream.
  • Unknown top-level fields.
  • The unsupported rawRequests field.
  • Unsupported runtime.format.
  • Nonpositive numeric limits in runtime.
  • Market Data entries without instrumentId.
  • Generated enum names and aliases unsupported by the configuration converter.

The CLI validates configuration before creating TInvestNodeSDK.

Override settings on the CLI

CLI flags can override settings from runtime.

Shell
t-invest-node-sdk stream run \
  --config=portfolio-stream.json \
  --max-events=10 \
  --include-pings

See Streaming CLI runtime settings for supported flags and boolean override rules.

Set subscriptions and account selection in the configuration file. This lets one command support multiple streams with the same set of flags.

Choose the output format

Default normalized event

JSON
{"stream":"orders.tradesStream","sequence":1,"receivedAt":"2026-06-29T12:00:00.000Z","type":"orderTrades","payload":{"orderId":"..."}}

Raw event with runtime.raw: true

JSON
{"orderTrades":{"orderId":"..."}}

By default, all streaming methods emit normalized events with a shared structure.

Run the command