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

@ttech-pub/invest-engine-node

v1.61.0

Published

T-Tech Invest strategy and backtesting engine for Node.js

Readme

@ttech-pub/invest-engine-node

Движок стратегий и бэктеста для Node.js: свечные серии, индикаторы, правила входа и выхода, прогон по истории и мост к live-торговле. Зависит только от @ttech-pub/invest-core — сам в сеть не ходит и от gRPC-клиентов не зависит, свечи подаёт вызывающий код.

Документация проекта: https://opensource.tbank.ru/invest/invest-js

Установка

npm install @ttech-pub/invest-engine-node @ttech-pub/invest-core

Бэктест

BarSeries хранит историю, BaseStrategy связывает правила входа и выхода, BarSeriesManager.run прогоняет стратегию и возвращает TradingRecord.

import {
  BarSeries,
  BaseStrategy,
  ClosePriceIndicator,
  RSIIndicator,
  OverboughtRSIRule,
  OversoldRSIRule,
  BarSeriesManager,
  ReturnCriterion,
} from '@ttech-pub/invest-engine-node';
import { Decimal } from '@ttech-pub/invest-core';

const series = new BarSeries({ name: 'SBER' }, []);
// series.addBar(...) — свечи из GetCandlesCommand

const close = new ClosePriceIndicator(series);
const rsi = new RSIIndicator(close, 14);

const strategy = new BaseStrategy(
  new OversoldRSIRule(rsi, new Decimal('30')),
  new OverboughtRSIRule(rsi, new Decimal('70'))
);

const record = new BarSeriesManager(series).run(strategy, {
  initialEquity: new Decimal('100000'),
});

new ReturnCriterion().calculate(series, record).toString();

RunOptions

| Параметр | Тип | По умолчанию | Значение | | ---------------------- | --------------- | ----------------------- | --------------------------------------------------- | | positionType | PositionType | LONG | Направление позиций прогона | | positionSizer | PositionSizer | FixedQuantitySizer(1) | Расчёт объёма позиции | | initialEquity | Decimal | 0 | Стартовый капитал; нужен процентным сайзерам | | startIndex | number | series.beginIndex | Первый бар итерации; история до него идёт в warm-up | | endIndex | number | series.endIndex | Последний бар итерации | | transactionCostModel | CostModel | ZeroCostModel | Издержки, применяются к входу и выходу отдельно | | slippageModel | SlippageModel | ZeroSlippageModel | Проскальзывание цены close до записи ордера |

Открытая на конце серии позиция остаётся незакрытой — что с ней делать, решает вызывающий код.

Live-прогон

LiveStrategyRunner — мост «новый бар → решение → намерение ордера». Он не отправляет заявки: push возвращает OrderIntent либо null, а маппинг в реальную заявку и вызов recordFill после подтверждения брокером остаются на стороне приложения.

import { LiveStrategyRunner, PositionType } from '@ttech-pub/invest-engine-node';

const runner = new LiveStrategyRunner(series, strategy, { positionType: PositionType.LONG });

const intent = runner.push(bar);
if (intent) {
  // intent: { side, quantity, referencePrice, type, index, time }
}

LiveStrategyRunnerOptions

| Параметр | Тип | По умолчанию | Значение | | --------------- | --------------------- | --------------------------------- | -------------------------------------------------------------------------------------- | | positionType | PositionType | record?.positionType или LONG | Направление позиций. При конфликте с record.positionType конструктор бросает ошибку | | positionSizer | PositionSizer | FixedQuantitySizer(1) | Расчёт объёма позиции | | initialEquity | Decimal | 0 | Стартовый капитал для процентных сайзеров | | orderType | 'market' \| 'limit' | 'market' | Тип эмитируемых намерений | | record | TradingRecord | новая запись | Внешняя торговая запись — если состояние ведётся совместно с реконсилиацией от брокера |

push возвращает null, пока не пройден warm-up стратегии (getUnstableBars), а также если сайзер дал нулевой или отрицательный объём.

Подключаемые модели

| Назначение | Реализации | | --------------------------------- | --------------------------------------------------------------------------- | | Объём позиции (PositionSizer) | FixedQuantitySizer, PercentEquitySizer, ATRBasedSizer | | Издержки (CostModel) | ZeroCostModel, LinearTransactionCostModel, FixedTransactionCostModel | | Проскальзывание (SlippageModel) | ZeroSlippageModel, FixedBpsSlippageModel, SpreadFractionSlippageModel |

Индикаторы, правила и метрики

Индикаторы (67 классов) сгруппированы по директориям indicators/{moving-averages,momentum,volatility,trend,volume,statistics,candles,helpers} — скользящие средние, RSI, MACD, стохастик, ATR, полосы Боллинджера и прочие.

Правила комбинируются булевой логикой: AndRule, OrRule, NotRule, XorRule, NandRule, NorRule, combineAnd, combineOr. Готовые торговые правила — StopLossRule, TakeProfitRule, TrailingStopRule, WaitRule, CrossedUpIndicatorRule и другие из rules/.

Метрики результата: ReturnCriterion, BuyAndHoldReturnCriterion, ProfitFactorCriterion, SharpeRatioCriterion, MaximumDrawdownCriterion, MaximumDrawdownByBarCriterion, NumberOfBarsCriterion, NumberOfPositionsCriterion.

Агрегация свечей в другой таймфрейм — DurationBarAggregator, OhlcvBarAggregator, aggregateBarSeries; Heikin-Ashi — toHeikinAshiBars, toHeikinAshiSeries.

Пример

Готовый RSI-бэктест: examples/engine-node.