Have you ever wanted a flexible, zero-bloat engine to build, test, and iterate on trading strategies — without digging through mountains of boilerplate code?
Let me introduce you to trading-cycle
— a modular, blazing-fast core for backtesting trading logic in JavaScript/TypeScript.
Designed to be lightweight, extensible, and unapologetically developer-friendly.
No magic. No assumptions. Just powerful building blocks.
Why I Built This
Most open-source trading frameworks are either:
- bloated and hard to extend, or
- too minimal, lacking support for real-world conditions.
trading-cycle
is my take on solving that. It provides:
- A powerful event-driven pipeline to simulate ticks.
- A core + handlers architecture for full customization.
- Built-in presets so you can start in seconds.
And yes, it's written in TypeScript, typed from top to bottom.
⚙️ Installation
npm install trading-cycle
This gives you:
- The full version, including indicators like Renko, logic handlers, candles, etc.
- The light version, for when you want just the core.
🚀 Quick Start
import {
TradingCycle,
defaultPreset,
handlers,
} from 'trading-cycle/full';
const cycle = new TradingCycle(handlers, defaultPreset);
// your data: ticks from CSV or real-time
ticks.forEach(tick => cycle.execute(tick));
console.log(cycle.state); // inspect the result
Want just the bare bones?
import { TradingCycle } from 'trading-cycle/light';
🧩 Plug-and-Play Handlers
Built-in modules you can use out of the box:
Candles,
PositiveValues,
NegativeValues,
Renko,
TimeRenko,
TestLogic,
PositiveTimeLength,
NegativeTimeLength,
FakeTrader,
LogCandle,
RenkoCounter
Customize the flow using presets or your own HandlerConfig[]
.
💡 Writing Your Own Handler
You can write a handler in ~10 lines. Here's the idea:
class MyHandler extends AbstractHandler {
prev = 0;
doExecute() {
if (this.v.close < this.prev) {
this.prev = this.v.close;
return this.v;
}
this.prev = this.v.close;
return undefined;
}
}
📄 CSV-Based Backtests
const cycle = new TradingCycle(handlers, defaultPreset);
// Load and parse your CSV into ticks
for (const tick of ticks) {
cycle.execute(tick);
}
console.log(cycle.state); // final results
Use your own indicators, logic, trader bots — or combine with built-ins.
🧪 CI/CD + Code Coverage
All PRs go through:
yarn lint
-
jest
unit tests - Code coverage via Codecov
- Node.js 18 on GitHub Actions
- name: Run tests
run: yarn test --coverage
- name: Upload to Codecov
uses: codecov/codecov-action@v3
Fully automated. No manual steps.
📦 Bundle Size
trading-cycle
is lean:
Version | Minified | Gzipped |
---|---|---|
Full | ~4.1kb | ~1.7kb |
Light | Even smaller ⚡️ |
🔍 API Overview
new TradingCycle(handlers, config);
cycle.execute(tick);
cycle.state // final outputs
Handlers can:
- read inputs (
this.v
) - track internal state (
this._s
) - emit values when ready
👨💻 Made with ❤️ by @vladtarrow
MIT licensed. Contributions welcome. PRs and GitHub stars fuel this project.
👉 Try it now
npm install trading-cycle
And start simulating strategies without friction.
Have questions? Want to show off your own handlers? Drop a comment below or open an issue 💬