$ show bennycode/trading-signals
This repository is a comprehensive, production-oriented algorithmic trading framework implemented in TypeScript. It is organized as a monorepo with six interdependent packages: `trading-signals` (100+ technical indicator implementations with streaming `add`/`replace` semantics, each verified against external reference data like Tulip Indicators and Skender.Stock.Indicators), `trading-strategies` (strategy base classes, concrete strategies such as SMA crossover, scalp, trailing stop, and a multi-indicator confluence strategy, plus a backtesting engine and report generators), `exchange` (abstract broker interface with real implementations for Alpaca and Trading212, including mock broker for backtesting, candle batching, WebSocket streaming, and a CLI tool), `messaging` (a Telegram bot for managing accounts, strategies, watches, and reports via multi-step wizards), `candles` (labeled historical candle datasets for testing), and `trading-signals-docs` (a Next.js documentation site with interactive indicator demos and a visual backtester). The architecture emphasizes clean separation between signal generation, strategy logic, broker execution, and user interface. The indicator library is the core asset, providing a consistent contract (`IndicatorSeries`, `TechnicalIndicator`, `TrendIndicator`) with rich signal detection and state rollback. The strategy framework supports live trading and backtesting via the same advice-execution pipeline. The project is actively maintained with CI/CD, mutation testing, and a well-defined broker integration template. While the codebase shows high craftsmanship in its indicator implementations and test patterns, the large number of indicators and hand-derived test fixtures introduce maintenance overhead, and the tight coupling to Telegram limits platform portability.
The LLM identified 6 files worth highlighting for reuse:
Defines the abstract base classes (`IndicatorSeries`, `TechnicalIndicator`, `TrendIndicatorSeries`, `ZeroCrossSeries`, `ThresholdCrossSeries`) that all 100+ indicators extend. Implements a consistent streaming API with `add(value, replace?)` for sequential updates and `replace(value)` for deterministic state rollback used in backtesting. Tracks `isStable`, `updates`, and signal generation with change detection. Highly reusable as a foundation for any time-series or streaming calculation module requiring lazy evaluation and revertable state.
Implements the `Broker` interface for simulated order execution used by `BacktestExecutor`. Supports configurable slippage, balance tracking, candle-driven order matching, and fill events. Can be extracted and reused in any trading backtest framework that requires a mock exchange with realistic order lifecycle (limit/market orders, stop-loss, take-profit). Demonstrates clean separation of concerns and uses the same `AdviceExecutor` as live trading for consistent behavior.
A reusable retry utility with a class-based decorator approach. Supports configurable retry count, delay function (e.g., exponential backoff), and a predicate to decide which errors should trigger a retry. Used across broker API calls (Alpaca, Trading212) to handle transient failures. Self-contained and applicable to any network-bound application without external dependencies beyond TypeScript.
A reusable Vitest test contract that validates any indicator implementation against a standard set of properties: correct warm-up periods, `replace()` restoring previous state, stability with equal input values, signal changes, and edge cases like division by zero. Used by every indicator test in the codebase. Can be extracted and adapted to validate any streaming computation library with a similar add/replace interface, saving significant test boilerplate.
Defines the abstract `Strategy` base class with lifecycle hooks (`init`, `processCandle`, `onFill`, `onOrderFilled`, `restoreState`, `onSave`, `onFinish`) and a Zod schema for configuration validation. Concrete strategies extend this to implement trading logic. The pattern cleanly separates state management, configuration, and market interaction, making it reusable in any trading system that needs a modular, stateful strategy framework.
Provides static methods to aggregate sub-minute or sub-hour candle streams into higher timeframes (e.g., 1-minute to 1-hour). Handles missing candles gracefully by adjusting open/high/low/close. Uses an EventEmitter pattern with topic IDs for integration with both broker WebSocket streams and strategy timeframes. Self-contained and reusable for any application that needs to resample or batch time-series data into fixed intervals.