Registry / trading / tinkoff-sdk-grpc-js

tinkoff-sdk-grpc-js

JSON →
library3.0.0jsnpmunverified

Lightweight TypeScript SDK for T-Invest API (Tinkoff Investments) built on nice-grpc and ts-proto. Provides full gRPC client covering Users, Orders, MarketData, Operations, Instruments, StopOrders, Sandbox, and Signals services. Integrates unary and streaming endpoints with optional split channels. Includes a high-level MarketDataStreamController for managing subscriptions. Exposes TypeLoggerCb for structured logging with rate-limit headers and API error mapping. Supports sandbox mode, custom endpoints, and gRPC channel options. Currently at v3.0.0, actively maintained with releases tied to upstream contract updates.

npm install tinkoff-sdk-grpc-js
INSTALL
IMPORT
SIG · TINKOFF-SDK-GRPC-J
T
tinkoff-sdk-grpc-js
tradingjavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createSdk
import { createSdk } from 'tinkoff-sdk-grpc-js'
const createSdk = require('tinkoff-sdk-grpc-js').createSdk
ESM import works directly; CJS require returns an object with createSdk as a property
createMarketDataStreamController
import { createMarketDataStreamController } from 'tinkoff-sdk-grpc-js'
Named export for stream subscription helper
CandleInterval
import { CandleInterval } from 'tinkoff-sdk-grpc-js'
import { CandleInterval } from 'tinkoff-sdk-grpc-js' should work but enum is also available as sdk.CandleInterval after creating SDK instance
Enums are re-exported as members of the SDK object; direct import also works

Demonstrates creating SDK with token, fetching 5-minute candles, and disconnecting.

import { createSdk } from 'tinkoff-sdk-grpc-js'; const sdk = createSdk(process.env.TINVEST_TOKEN ?? '', 'example.my-app'); async function main() { const candles = await sdk.marketData.getCandles({ instrumentId: 'BBG0047315Y7', from: new Date('2022-04-04T11:00:00Z'), to: new Date('2022-04-04T11:20:59Z'), interval: sdk.CandleInterval.CANDLE_INTERVAL_5_MIN, }); console.log(candles); await sdk.disconnect(); } main().catch(console.error);
Debug
Known issues
breakingSDK v3: createSdk now returns a new SDK object with disconnect method; old v2 pattern using client classes is removed
fix
Migrate from direct RPC method calls to createSdk interface; ensure .disconnect() is called after usage
affects: >=3.0.0 <3.0.0
gotchaToken and appName parameters are mandatory; appName must be a non-empty string or undefined will cause runtime error
fix
Always provide appName (e.g., 'my-app'); it's used for x-app-name header
affects: >=1.0.0
gotchaBy default errors are thrown and not swallowed; middleware.swallowErrors must be set to true for legacy silent error handling
fix
If you want errors to be logged and not thrown, pass options: { middleware: { swallowErrors: true } } to createSdk
affects: >=3.0.0
gotchaStream subscriptions: calling subscribe* after stream is closed results in 'Client is closed' or 'Event loop completed' errors
fix
Ensure you call subscribe before awaiting stream.close(); use a flag to prevent double subscription
affects: >=1.0.0
deprecatedDirect import of protobuf enums like CandleInterval from generated paths (e.g., from 'tinkoff-sdk-grpc-js/src/generated/...') is deprecated
fix
Use re-exports from package main entry: import { CandleInterval } from 'tinkoff-sdk-grpc-js'
affects: >=1.0.0
Errors
Common errors & fixes
Error: 5 PERMISSION_DENIED: Permission denied
Invalid or expired token, or token does not have access to the requested resource
fix
Verify TINVEST_TOKEN environment variable is set and valid; generate a new token in Tinkoff Broker settings
TypeError: sdk.marketData is undefined
SDK not fully initialized (e.g., missing token or appName leading to creation failure) or attempting to access service before await
fix
Ensure createSdk is called with valid token and appName; check that no exception was thrown during creation
Error: UNAVAILABLE: DNS resolution failed for invest-public-api.tbank.ru:443
Network issues, DNS misconfiguration, or proxy interference blocking access to Tinkoff API
fix
Check internet connection; if behind a corporate proxy, configure Node.js proxy settings (e.g., HTTP_PROXY environment variable) or use a different network
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
nice-grpcrequiredCore gRPC client library used for all RPC calls
Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
1
Resources
tinkoff-sdk-grpc-js — npm install tinkoff-sdk-grpc-js · libregistry