techkit
v1.2.9
Published
High-performance technical analysis library - Native + WASM backends, 158+ TA-Lib compatible indicators, works in Node.js AND Browser
Maintainers
Readme
TechKit
High-Performance Technical Analysis Library
🚀 Native + WASM • 📊 158+ Indicators • 🌐 Node.js + Browser
Installation • Quick Start • Browser Usage • API Docs
✨ Features
| Feature | Description | |---------|-------------| | 🚀 Dual Backend | Native C++ for Node.js, WebAssembly for Browser | | 🌐 Browser Support | Full WASM support - run technical analysis in the browser! | | 📊 158+ Indicators | Complete TA-Lib compatible indicator set | | 🎯 100% Accurate | Validated against TA-Lib with < 1e-10 error tolerance | | ⚡ High Performance | Native: 10-100x faster, WASM: 5-20x faster than pure JS | | 💾 Memory Efficient | O(1) incremental updates, minimal footprint | | 🔒 Thread Safe | Each indicator instance is independent | | 📦 Zero Dependencies | No runtime dependencies |
📦 Installation
npm install techkit
# or
yarn add techkit
# or
pnpm add techkit🚀 Quick Start
Node.js Usage
import { init, SMA, EMA, RSI, MACD, BBANDS } from 'techkit';
// Initialize (auto-detects best backend: Native in Node.js)
await init();
// Sample price data
const prices = [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08];
// Create indicator instances
const sma = SMA.create(20);
const rsi = RSI.create(14);
// Calculate over array
const smaResult = sma.calculate(prices);
const rsiResult = rsi.calculate(prices);
console.log('SMA:', smaResult);
console.log('RSI:', rsiResult);🌐 Browser Usage (WASM)
TechKit runs entirely in the browser via WebAssembly! No server required.
Basic Browser Setup
<!DOCTYPE html>
<html>
<head>
<title>TechKit Browser Demo</title>
</head>
<body>
<script type="module">
import { init, SMA, RSI, MACD, BBANDS } from 'https://unpkg.com/techkit/dist/browser.mjs';
// Initialize WASM backend (required in browser)
await init();
// Now use indicators just like in Node.js!
const prices = [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10];
const sma = SMA.create(5);
const rsi = RSI.create(14);
console.log('SMA:', sma.calculate(prices));
console.log('RSI:', rsi.calculate(prices));
</script>
</body>
</html>React/Vue/Angular Integration
// React Component Example
import { useEffect, useState } from 'react';
import { init, SMA, RSI, MACD } from 'techkit';
function TechnicalChart({ priceData }) {
const [indicators, setIndicators] = useState(null);
const [initialized, setInitialized] = useState(false);
useEffect(() => {
// Initialize WASM on component mount
init().then(() => setInitialized(true));
}, []);
useEffect(() => {
if (!initialized || !priceData.length) return;
// Create indicators
const sma20 = SMA.create(20);
const sma50 = SMA.create(50);
const rsi = RSI.create(14);
const macd = MACD.create(12, 26, 9);
// Calculate
setIndicators({
sma20: sma20.calculate(priceData),
sma50: sma50.calculate(priceData),
rsi: rsi.calculate(priceData),
macd: macd.calculate(priceData)
});
}, [initialized, priceData]);
if (!initialized) return <div>Loading WASM...</div>;
return (
<div>
{/* Render chart with indicators */}
</div>
);
}Vue 3 Example
<template>
<div>
<div v-if="!initialized">Loading WASM...</div>
<div v-else>
<p>SMA(20): {{ sma20 }}</p>
<p>RSI(14): {{ rsi14 }}</p>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue';
import { init, SMA, RSI } from 'techkit';
const props = defineProps(['prices']);
const initialized = ref(false);
const sma20 = ref([]);
const rsi14 = ref([]);
onMounted(async () => {
await init();
initialized.value = true;
});
watch([() => props.prices, initialized], ([prices, ready]) => {
if (!ready || !prices.length) return;
const smaIndicator = SMA.create(20);
const rsiIndicator = RSI.create(14);
sma20.value = smaIndicator.calculate(prices);
rsi14.value = rsiIndicator.calculate(prices);
});
</script>Real-Time Chart Application
import { init, SMA, EMA, RSI, MACD, BBANDS } from 'techkit';
class TradingDashboard {
private sma: any;
private rsi: any;
private macd: any;
private bbands: any;
private initialized = false;
async initialize() {
// Initialize WASM backend
await init();
// Create indicator instances (reusable!)
this.sma = SMA.create(20);
this.rsi = RSI.create(14);
this.macd = MACD.create(12, 26, 9);
this.bbands = BBANDS.create(20, 2, 2);
this.initialized = true;
console.log('TechKit WASM initialized!');
}
calculateIndicators(prices: number[]) {
if (!this.initialized) {
throw new Error('Call initialize() first!');
}
return {
sma: this.sma.calculate(prices),
rsi: this.rsi.calculate(prices),
macd: this.macd.calculate(prices),
bbands: this.bbands.calculate(prices)
};
}
// Streaming updates
onNewPrice(price: number) {
const smaResult = this.sma.update(price);
const rsiResult = this.rsi.update(price);
if (smaResult.valid) {
this.updateChart('sma', smaResult.value);
}
if (rsiResult.valid) {
this.updateChart('rsi', rsiResult.value);
}
}
private updateChart(indicator: string, value: number) {
// Update your chart library (Chart.js, Highcharts, etc.)
}
}
// Usage
const dashboard = new TradingDashboard();
await dashboard.initialize();
// Fetch price data
const prices = await fetchPrices('BTCUSD');
const indicators = dashboard.calculateIndicators(prices);
// Subscribe to real-time updates
websocket.on('price', (price) => dashboard.onNewPrice(price));Webpack/Vite Configuration
Vite (vite.config.js):
export default {
optimizeDeps: {
exclude: ['techkit'] // Let Vite handle WASM properly
},
build: {
target: 'esnext' // Required for top-level await
}
}Webpack (webpack.config.js):
module.exports = {
experiments: {
asyncWebAssembly: true,
topLevelAwait: true
},
module: {
rules: [
{
test: /\.wasm$/,
type: 'webassembly/async'
}
]
}
};🔄 Streaming / Incremental Updates
Perfect for real-time data feeds in both Node.js and Browser:
import { init, SMA, RSI } from 'techkit';
await init();
// Create stateful indicators
const sma = SMA.create(20);
const rsi = RSI.create(14);
// WebSocket real-time feed
const ws = new WebSocket('wss://stream.example.com/prices');
ws.onmessage = (event) => {
const price = JSON.parse(event.data).price;
// O(1) incremental update - no recalculation!
const smaResult = sma.update(price);
const rsiResult = rsi.update(price);
if (smaResult.valid && rsiResult.valid) {
console.log(`SMA: ${smaResult.value.toFixed(2)}, RSI: ${rsiResult.value.toFixed(2)}`);
updateUI(smaResult.value, rsiResult.value);
}
};📊 Available Indicators
Moving Averages
| Function | Description | Parameters |
|----------|-------------|------------|
| SMA | Simple Moving Average | period |
| EMA | Exponential Moving Average | period |
| WMA | Weighted Moving Average | period |
| DEMA | Double Exponential MA | period |
| TEMA | Triple Exponential MA | period |
| KAMA | Kaufman Adaptive MA | period |
| TRIMA | Triangular MA | period |
| T3 | T3 Moving Average | period, vFactor |
Momentum Indicators
| Function | Description | Parameters |
|----------|-------------|------------|
| RSI | Relative Strength Index | period |
| MACD | MACD | fast, slow, signal |
| STOCH | Stochastic Oscillator | kPeriod, kSlow, dPeriod |
| CCI | Commodity Channel Index | period |
| ADX | Average Directional Index | period |
| MOM | Momentum | period |
| ROC | Rate of Change | period |
| WILLR | Williams %R | period |
| MFI | Money Flow Index | period |
| APO | Absolute Price Oscillator | fast, slow |
| PPO | Percentage Price Oscillator | fast, slow |
| CMO | Chande Momentum Oscillator | period |
| AROON | Aroon Indicator | period |
| ULTOSC | Ultimate Oscillator | p1, p2, p3 |
| TRIX | Triple Smooth EMA | period |
Volatility Indicators
| Function | Description | Parameters |
|----------|-------------|------------|
| ATR | Average True Range | period |
| NATR | Normalized ATR | period |
| TRANGE | True Range | - |
| BBANDS | Bollinger Bands | period, nbDevUp, nbDevDn |
Volume Indicators
| Function | Description | Parameters |
|----------|-------------|------------|
| OBV | On Balance Volume | - |
| AD | Accumulation/Distribution | - |
| ADOSC | A/D Oscillator | fast, slow |
Statistical Functions
| Function | Description | Parameters |
|----------|-------------|------------|
| STDDEV | Standard Deviation | period |
| VAR | Variance | period |
| LINEARREG | Linear Regression | period |
| LINEARREG_SLOPE | LR Slope | period |
| LINEARREG_ANGLE | LR Angle | period |
| CORREL | Pearson Correlation | period |
| BETA | Beta Coefficient | period |
Hilbert Transform (Cycle Indicators)
| Function | Description |
|----------|-------------|
| HT_TRENDLINE | Instantaneous Trendline |
| HT_SINE | SineWave |
| HT_TRENDMODE | Trend vs Cycle Mode |
| HT_DCPERIOD | Dominant Cycle Period |
| HT_DCPHASE | Dominant Cycle Phase |
| HT_PHASOR | Phasor Components |
⚡ Performance
Node.js (Native Backend)
| Indicator | TechKit | Pure JS | Speedup | |-----------|---------|---------|---------| | SMA(20) × 10k | 0.3ms | 12ms | 40x | | RSI(14) × 10k | 0.5ms | 25ms | 50x | | MACD × 10k | 0.8ms | 45ms | 56x | | BBANDS × 10k | 0.6ms | 35ms | 58x |
Browser (WASM Backend)
| Indicator | TechKit WASM | Pure JS | Speedup | |-----------|--------------|---------|---------| | SMA(20) × 10k | 1.2ms | 12ms | 10x | | RSI(14) × 10k | 2.0ms | 25ms | 12x | | MACD × 10k | 3.2ms | 45ms | 14x | | BBANDS × 10k | 2.4ms | 35ms | 15x |
Benchmarks on Chrome 120, Apple M1
📖 Documentation
Full Documentation: https://techkit-docs.netlify.app/
Quick Links
| Topic | Link | |-------|------| | Installation | Getting Started | | Quick Start | Quick Start Guide | | Node.js API | Node.js API Reference | | All Indicators | Indicator List | | Examples | Code Examples | | Changelog | Version History | | 中文文档 | Chinese Documentation |
🔧 API Reference
📖 Full API documentation: techkit-docs.netlify.app/en/api/nodejs-api/
Initialization
import { init, getBackendInfo } from 'techkit';
// Initialize backend (required before using indicators)
await init();
// Check which backend is active
const info = getBackendInfo();
console.log(info);
// Node.js: { type: 'native', ready: true }
// Browser: { type: 'wasm', ready: true }Indicator Factory Pattern
// All indicators use the factory pattern
const indicator = IndicatorName.create(param1, param2, ...);
// Calculate over array
const results = indicator.calculate(dataArray);
// Incremental update (returns { value, valid })
const result = indicator.update(newValue);
// Reset state
indicator.reset();
// Properties
indicator.lookback; // Warmup period needed
indicator.ready; // Is warmup complete?Multi-Output Indicators
// MACD returns 3 arrays
const macd = MACD.create(12, 26, 9);
const { macd: macdLine, signal, histogram } = macd.calculate(prices);
// Bollinger Bands returns 3 arrays
const bbands = BBANDS.create(20, 2, 2);
const { upper, middle, lower } = bbands.calculate(prices);
// Stochastic returns 2 arrays
const stoch = STOCH.create(14, 3, 3);
const { k, d } = stoch.calculate(high, low, close);🌍 Platform Support
| Platform | Environment | Backend | Status | |----------|-------------|---------|--------| | Browser | Chrome/Firefox/Safari/Edge | WASM | ✅ | | Node.js | Windows x64 | Native | ✅ | | Node.js | macOS x64 | Native | ✅ | | Node.js | macOS ARM64 (M1/M2) | Native | ✅ | | Node.js | Linux x64 | Native | ✅ | | Deno | All platforms | WASM | ✅ | | Bun | All platforms | Native/WASM | ✅ |
📄 License
MIT License - see LICENSE for details.
🔗 Links
- 📖 Full Documentation - API Reference & Guides
- GitHub Repository
- Issue Tracker
- Changelog
- techkit-full - Extended version with 189 indicators
Works everywhere JavaScript runs!
Node.js • Browser • Deno • Bun
Made with ❤️ by the TechKit Team
