T-Invest Node SDK Node.js
On this page

Run a streaming CLI command

Use this reference to receive T-Invest events with stream run. Choose a stream and subscriptions in JSON. The CLI opens the connection, writes events to stdout, and reports errors in stderr. Its exit code identifies how the stream ended, including configured limits, signals, and provider errors.

Start a stream

stream run opens a long-running stream, prints events, and exits on a limit, timeout, signal, or provider error.

Shell
t-invest-node-sdk stream run --config=PATH [runtime options]

Choose the method and initial requests in the configuration file. Supported methods are listed below.

Choose a stream

Choose stream based on the events your application needs. Market data streams carry candles, trades, and order books. Separate account streams carry portfolio changes, position updates, and order trades.

Configuration stream value SDK method gRPC method Stream type
marketdata.marketDataStream sdk.marketdataStream.marketDataStream MarketDataStreamService/MarketDataStream Bidirectional with static initial requests
marketdata.marketDataServerSideStream sdk.marketdataStream.marketDataServerSideStream MarketDataStreamService/MarketDataServerSideStream Server-side
operations.portfolioStream sdk.operationsStream.portfolioStream OperationsStreamService/PortfolioStream Server-side
operations.positionsStream sdk.operationsStream.positionsStream OperationsStreamService/PositionsStream Server-side
orders.tradesStream sdk.ordersStream.tradesStream OrdersStreamService/TradesStream Server-side

Run the command

Each invocation of stream run opens one session with configuration settings and CLI overrides. Limits maxEvents, durationMs, and idleTimeoutMs cause normal completion. A provider error before a timeout still propagates.

See the streaming session architecture for how reading is canceled, the iterator ends, and the SDK closes.

Write events and errors

The stream uses jsonl. It prints each event as a separate JSON line.

JSON
{"stream":"marketdata.marketDataServerSideStream","sequence":1,"receivedAt":"2026-06-29T12:00:00.000Z","type":"candle","payload":{"instrumentUid":"..."}}

Every event has these fields.

  • stream — stream name from the configuration.
  • sequence — sequence number in the current process.
  • receivedAt — time the CLI received the event, in ISO format.
  • type — normalized event type.
  • payload — event data.

The CLI writes only events to stdout. Errors reading configuration, transport errors, provider errors, and write failures go to stderr. Subscription status, including rejected subscriptions, appears as events in stdout. Set runtime.includeSubscriptionEvents: false to suppress these events.

Identify event types

Events in marketdata.*

  • subscribeCandlesResponse
  • subscribeOrderBookResponse
  • subscribeTradesResponse
  • subscribeInfoResponse
  • subscribeLastPriceResponse
  • candle
  • trade
  • orderbook
  • tradingStatus
  • lastPrice
  • ping

Events in operations.portfolioStream

  • subscriptions
  • portfolio
  • ping

Events in operations.positionsStream

  • subscriptions
  • position
  • ping

Events in orders.tradesStream

  • subscription
  • orderTrades
  • ping

To print ping events to stdout, set runtime.includePings to true.

Configure execution and output

runtime specifies the output format and when to stop. CLI flags can override these settings. Set subscriptions in the configuration file.

Shell
t-invest-node-sdk stream run \
  --config=marketdata.json \
  --max-events=100 \
  --duration-ms=60000 \
  --include-pings

Runtime options

  • --config=PATH — required path to a JSON configuration file.
  • --max-events=N — exit after printing N events.
  • --duration-ms=N — exit after N milliseconds.
  • --idle-timeout-ms=N — exit after N milliseconds without an event.
  • --include-pings — print ping events to stdout.
  • --raw — print the generated response without the normalized event envelope.
  • --format=jsonl — output format. The supported format is jsonl.

Boolean runtime flags accept --flag or --no-flag. Use --no-include-pings or --no-raw to override true from the configuration. The forms --flag=true and --flag=false are unsupported.

Numeric runtime values must be positive safe JavaScript integers.

Check the exit code

  • 0 — completion due to a limit, timeout, or normal stream closure.
  • 2 — configuration failed syntactic or semantic validation.
  • 1 — configuration read, provider, or runtime error.
  • 130 — process stopped by SIGINT.
  • 143 — process stopped by SIGTERM.

On normal completion, timeout, or a handled error, the command closes the SDK in finally. On SIGINT and SIGTERM, the built-in CLI follows standard Node.js termination behavior, which can interrupt cancellation and finally.

Account for backpressure

stream run emits chunks as they arrive. When the stdout or stderr write buffer is full, the CLI waits for drain or a write error.

Current command limitations

The following features are outside the current command's scope.

  • Printing stream events as a table or CSV.
  • Automatic reconnection.
  • Saving the read position to persistent storage.
  • Changing subscriptions interactively after startup.
  • Bidirectional request sources from stdin, files, or timers.
  • Aggregating events into an application report.
  • Writing directly to a file.

Configure the command