npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tinkoff-sdk-grpc-js

v3.0.0

Published

`tinkoff-sdk-grpc-js` — легковесный SDK на `nice-grpc` + `ts-proto` для T-Invest API.

Readme

T-Invest gRPC SDK (TypeScript / Node.js)

tinkoff-sdk-grpc-js — легковесный SDK на nice-grpc + ts-proto для T-Invest API.

Установка

npm i tinkoff-sdk-grpc-js

Быстрый старт

const { createSdk } = require('tinkoff-sdk-grpc-js');

const sdk = createSdk(process.env.TINVEST_TOKEN, 'example.my-app');

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();

Endpoint policy

По умолчанию:

  • prod: invest-public-api.tbank.ru:443
  • sandbox: sandbox-invest-public-api.tbank.ru:443

Можно переопределить через createSdk options (apiUrl, sandboxApiUrl).

API createSdk

createSdk(
  token: string,
  appName?: string,
  loggerCb?: TypeLoggerCb,
  options?: CreateSdkOptions
)

CreateSdkOptions

  • isSandbox?: boolean — использовать sandbox endpoint.
  • apiUrl?: string — override prod endpoint.
  • sandboxApiUrl?: string — override sandbox endpoint.
  • grpcChannelOptions?: ChannelOptions — merge поверх default gRPC options.
  • splitChannels?: boolean — разнести unary и stream сервисы по разным каналам.
  • middleware?: { swallowErrors?: boolean }
    • false (default): ошибки пробрасываются наверх.
    • true: legacy-режим, ошибки логируются и не пробрасываются.

Возвращаемый SDK

  • Unary/stream клиенты: users, orders, ordersStream, marketData, marketDataStream, operations, operationsStream, instruments, stopOrders, sandbox, signals.
  • Экспорт enum/структур.
  • disconnect(): Promise<void> — idempotent закрытие каналов.

Логирование и ошибки

TypeLoggerCb получает:

  1. metadata (x-tracking-id, message, rate-limit headers),
  2. ошибку,
  3. описание из api_errors.json (если сопоставлено),
  4. context: { path, code, details }.

Важно: по умолчанию ошибки не проглатываются.

Управляемые stream-подписки

SDK экспортирует helper:

const { createMarketDataStreamController } = require('tinkoff-sdk-grpc-js');

Пример:

const sdk = createSdk(process.env.TINVEST_TOKEN, 'example.stream', undefined, {
  splitChannels: true,
});

const stream = createMarketDataStreamController(sdk.marketDataStream, {
  closeGraceMs: 100,
});

stream.subscribeLastPrice('BBG000N9MNX3');
stream.subscribeCandles('BBG000N9MNX3', {
  interval: sdk.SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
  waitingClose: true,
});

for await (const event of stream.response) {
  console.log(event);
  break;
}

stream.unsubscribeCandles('BBG000N9MNX3');
stream.unsubscribeLastPrice('BBG000N9MNX3');
await stream.close();
await sdk.disconnect();

Поддерживаются методы:

  • send
  • subscribeLastPrice / unsubscribeLastPrice
  • subscribeInfo / unsubscribeInfo
  • subscribeCandles / unsubscribeCandles
  • subscribeOrderBook / unsubscribeOrderBook
  • subscribeTrades / unsubscribeTrades
  • close

Генерация контрактов

npm run generate:proto

По умолчанию скрипт тянет invest-contracts из git-репозитория.

Варианты источника

  1. Remote (default):
INVEST_CONTRACTS_REPO_URL=https://opensource.tbank.ru/invest/invest-contracts.git \
INVEST_CONTRACTS_REF=master \
npm run generate:proto
  1. Локальный source-of-truth (монорепо):
INVEST_CONTRACTS_LOCAL_DIR=../invest-contracts \
npm run generate:proto

INVEST_CONTRACTS_LOCAL_DIR должен указывать на корень invest-contracts (где есть src/docs/contracts).

Debug/timeout

npm run generate:proto:debug
INVEST_PROTO_DEBUG=1 INVEST_PROTO_HEARTBEAT_SEC=10 npm run generate:proto
INVEST_PROTO_NPM_CI_TIMEOUT_SEC=300 npm run generate:proto
INVEST_PROTO_SKIP_NPM_CI=1 npm run generate:proto

Manifest генерации

После генерации создается src/generated/contracts-manifest.json:

  • source type (remote/local),
  • repo/ref/commit,
  • paths и число proto файлов,
  • timestamp.

Это используется для диагностики агентами и проверки актуальности source contracts.

Тесты и проверка

npm run test
npm run check

check = build + test (без live API вызовов).

Примеры

Смотрите src/examples/*.ts:

  • unary (users, orders, marketData, operations, sandbox, stopOrders, instruments)
  • bidirectional stream + контроллер (marketDataStream.ts)