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.
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.
{"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.*
subscribeCandlesResponsesubscribeOrderBookResponsesubscribeTradesResponsesubscribeInfoResponsesubscribeLastPriceResponsecandletradeorderbooktradingStatuslastPriceping
Events in operations.portfolioStream
subscriptionsportfolioping
Events in operations.positionsStream
subscriptionspositionping
Events in orders.tradesStream
subscriptionorderTradesping
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.
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— printpingevents tostdout.--raw— print the generated response without the normalized event envelope.--format=jsonl— output format. The supported format isjsonl.
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 bySIGINT.143— process stopped bySIGTERM.
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
- Configure a streaming CLI command — choose a stream and subscriptions in JSON.
- Run a CLI command — pass common arguments and check the exit code.