@backtest-kit/signals 14.1.0 β 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -201
- package/build/index.cjs +94 -75
- package/build/index.mjs +94 -75
- package/package.json +87 -87
- package/types.d.ts +10 -11
package/README.md
CHANGED
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
<img src="https://github.com/tripolskypetr/backtest-kit/raw/refs/heads/master/assets/chronos.svg" height="45px" align="right">
|
|
2
|
-
|
|
3
|
-
# π @backtest-kit/signals
|
|
4
|
-
|
|
5
|
-
> Multi-timeframe technical analysis for AI trading on [backtest-kit](https://www.npmjs.com/package/backtest-kit). Computes 50+ indicators across four timeframes plus order-book depth, and emits LLM-ready markdown reports β drop the whole market context into an LLM prompt in one call.
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
[](https://deepwiki.com/tripolskypetr/backtest-kit)
|
|
10
|
-
[](https://npmjs.org/package/@backtest-kit/signals)
|
|
11
|
-
[]()
|
|
12
|
-
|
|
13
|
-
π **[Docs](https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html)** Β· π **[Reference implementation](https://github.com/tripolskypetr/backtest-kit/tree/master/example)** Β· π **[GitHub](https://github.com/tripolskypetr/backtest-kit)**
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @backtest-kit/signals backtest-kit
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Why
|
|
22
|
-
|
|
23
|
-
An LLM trading strategy is only as good as the market context you hand it. Computing 50+ indicators across four timeframes, formatting order-book depth, and laying it all out as clean markdown β by hand, every tick β is the unglamorous 200 lines that decides signal quality. This package is that work, pre-computed, cached, and synchronized with backtest-kit's timeline: one `commitHistorySetup(symbol, messages)` appends order book + candle history + indicators for 1m/15m/30m/1h to your LLM message array.
|
|
24
|
-
|
|
25
|
-
- π **Four synchronized timeframes** β MicroTerm 1m Β· ShortTerm 15m Β· SwingTerm 30m Β· LongTerm 1h.
|
|
26
|
-
- π― **50+ indicators** β RSI, MACD, Bollinger, Stochastic, ADX, ATR, CCI, Fibonacci, support/resistance, squeeze, volume trend.
|
|
27
|
-
- π **Order-book depth** β best bid/ask, spread, top-20 levels, liquidity imbalance.
|
|
28
|
-
- π€ **LLM-ready markdown** β formatted tables for context injection.
|
|
29
|
-
- β‘ **Cached** β per-timeframe TTL; cache cleared on error.
|
|
30
|
-
- π¦ **Zero config** β works out of the box on the engine's temporal context.
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## Quick start β one call
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
import { commitHistorySetup } from '@backtest-kit/signals';
|
|
38
|
-
|
|
39
|
-
const messages = [];
|
|
40
|
-
await commitHistorySetup('BTCUSDT', messages);
|
|
41
|
-
// messages now hold: order book + 1m/15m/30m/1h candle history
|
|
42
|
-
// + indicators for all 4 timeframes + system context (symbol, price, timestamp)
|
|
43
|
-
const signal = await llm(messages);
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
<details>
|
|
47
|
-
<summary>Complete LLM strategy</summary>
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { v4 as uuid } from 'uuid';
|
|
51
|
-
import { addStrategy, dumpSignal } from 'backtest-kit';
|
|
52
|
-
import { commitHistorySetup } from '@backtest-kit/signals';
|
|
53
|
-
import { json } from './utils/json.mjs'; // your LLM wrapper
|
|
54
|
-
|
|
55
|
-
addStrategy({
|
|
56
|
-
strategyName: 'llm-strategy', interval: '5m', riskName: 'demo',
|
|
57
|
-
getSignal: async (symbol) => {
|
|
58
|
-
const messages = [{ role: 'system', content: 'You are a trading bot. Analyze the indicators and generate a signal.' }];
|
|
59
|
-
await commitHistorySetup(symbol, messages);
|
|
60
|
-
messages.push({ role: 'user', content: [
|
|
61
|
-
'Based on the technical analysis above, generate a trading signal.',
|
|
62
|
-
'Use position: "wait" if signals are unclear or contradictory.',
|
|
63
|
-
'Return JSON: { position: "long"|"short"|"wait", priceTakeProfit: number, priceStopLoss: number }',
|
|
64
|
-
].join('\n') });
|
|
65
|
-
|
|
66
|
-
const resultId = uuid();
|
|
67
|
-
const signal = await json(messages);
|
|
68
|
-
await dumpSignal(resultId, messages, signal); // archive for debugging
|
|
69
|
-
return { ...signal, id: resultId };
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
</details>
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Granular control
|
|
79
|
-
|
|
80
|
-
Prefer to choose exactly what goes into the prompt? Call the individual report functions β each appends one markdown section to `messages`.
|
|
81
|
-
|
|
82
|
-
<details>
|
|
83
|
-
<summary>The 9 granular functions</summary>
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import {
|
|
87
|
-
commitBookDataReport, // order book: bids/asks, spread, imbalance
|
|
88
|
-
commitOneMinuteHistory, commitFifteenMinuteHistory, // candle histories (last 15 / 8 β¦)
|
|
89
|
-
commitThirtyMinuteHistory, commitHourHistory,
|
|
90
|
-
commitMicroTermMath, commitShortTermMath, // indicator tables per timeframe
|
|
91
|
-
commitSwingTermMath, commitLongTermMath,
|
|
92
|
-
} from '@backtest-kit/signals';
|
|
93
|
-
|
|
94
|
-
const messages = [];
|
|
95
|
-
await commitBookDataReport('BTCUSDT', messages);
|
|
96
|
-
await commitOneMinuteHistory('BTCUSDT', messages);
|
|
97
|
-
await commitMicroTermMath('BTCUSDT', messages);
|
|
98
|
-
// β¦add only the sections you want, then call your LLM
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
`commitHistorySetup` is simply the orchestrator that runs all of these in the right order.
|
|
102
|
-
|
|
103
|
-
</details>
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## What each timeframe computes
|
|
108
|
-
|
|
109
|
-
| Timeframe | Candles | Indicators | Use case |
|
|
110
|
-
|-----------|---------|------------|----------|
|
|
111
|
-
| **MicroTerm** (1m) | 60 | RSI(9,14), MACD(8,21,5), Stochastic, ADX(9), Bollinger(8,2), ATR, CCI, Volume, Squeeze | Scalping, ultra-short entries |
|
|
112
|
-
| **ShortTerm** (15m) | 144 | RSI(9), MACD(8,21,5), Stochastic(5,3,3), ADX(14), Bollinger(10,2), Fibonacci | Day trading |
|
|
113
|
-
| **SwingTerm** (30m) | 96 | RSI(14), MACD(12,26,9), Stochastic(14,3,3), Bollinger(20,2), Support/Resistance | Swing trading |
|
|
114
|
-
| **LongTerm** (1h) | 100 | RSI(14), MACD(12,26,9), ADX(14), Bollinger(20,2), SMA(50), DEMA, WMA, Volume Trend | Trend analysis |
|
|
115
|
-
|
|
116
|
-
<details>
|
|
117
|
-
<summary>Report structure (order book Β· candles Β· indicators)</summary>
|
|
118
|
-
|
|
119
|
-
**Order book** β symbol, best bid/ask, mid price, spread, depth imbalance (`(bid_vol β ask_vol)/(bid_vol + ask_vol)`, + = buy pressure), and top-20 bid/ask levels with `% of total`.
|
|
120
|
-
|
|
121
|
-
**Candle history** β per-candle table: timestamp, OHLC, volume, volatility, body size.
|
|
122
|
-
|
|
123
|
-
**Indicators** β a wide per-bar table; e.g. MicroTerm columns: Price, RSI(9), RSI(14), MACD, Signal, Histogram, Stoch %K/%D, ADX, +DI, βDI, BB Upper/Middle/Lower, ATR(5/9), CCI(9), Volume, Vol Trend, Momentum, ROC, Support, Resistance, Squeeze, Pressure β followed by a **Data Sources** note listing every period used.
|
|
124
|
-
|
|
125
|
-
</details>
|
|
126
|
-
|
|
127
|
-
<details>
|
|
128
|
-
<summary>Caching & key algorithms</summary>
|
|
129
|
-
|
|
130
|
-
**Cache TTL** (cleared on error): 1m data β 1 min Β· 15m β 5 min Β· 30m β 15 min Β· 1h β 30 min Β· order book β 5 min.
|
|
131
|
-
|
|
132
|
-
- **Support/Resistance** β MicroTerm/SwingTerm look back N candles for significant highs/lows (Β±0.3% threshold); LongTerm uses a 4-candle pivot method.
|
|
133
|
-
- **Fibonacci** β levels 0 / 23.6 / 38.2 / 50 / 61.8 / 78.6 / 100 %, extensions 127.2 / 161.8 / 261.8 %; nearest level to price within 1.5% tolerance.
|
|
134
|
-
- **Volume** β MicroTerm: SMA(5) with increasing/decreasing/stable trend (Β±20%); LongTerm: 6-candle average (Β±10%).
|
|
135
|
-
- **Order-book imbalance** β `(bid β ask)/(bid + ask)`, positive = buy pressure.
|
|
136
|
-
|
|
137
|
-
</details>
|
|
138
|
-
|
|
139
|
-
<details>
|
|
140
|
-
<summary>Custom logger (default is no-op)</summary>
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
import { setLogger } from '@backtest-kit/signals';
|
|
144
|
-
setLogger({ log: console.log, debug: console.debug, info: console.info, warn: console.warn });
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
</details>
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## Why not compute indicators yourself?
|
|
152
|
-
|
|
153
|
-
<details>
|
|
154
|
-
<summary>The difference</summary>
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
// β Manual β 40+ indicators, formatting, caching, all by hand
|
|
158
|
-
const candles = await getCandles('BTCUSDT', '1m', 60);
|
|
159
|
-
const rsi = calculateRSI(candles, 14);
|
|
160
|
-
const macd = calculateMACD(candles, 12, 26, 9);
|
|
161
|
-
const bb = calculateBollingerBands(candles, 20, 2);
|
|
162
|
-
// β¦and the markdown formatting, and the cache
|
|
163
|
-
messages.push({ role: 'user', content: formatToMarkdown(rsi, macd, bb /* β¦ */) });
|
|
164
|
-
|
|
165
|
-
// β
With signals
|
|
166
|
-
await commitHistorySetup('BTCUSDT', messages);
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
Pre-computed, cached, optimized Β· 50+ indicators Γ 4 timeframes Β· LLM-ready markdown Β· synchronized with the backtest timeline Β· validation & error handling built in.
|
|
170
|
-
|
|
171
|
-
</details>
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
## API reference
|
|
176
|
-
|
|
177
|
-
| Export | Description |
|
|
178
|
-
|--------|-------------|
|
|
179
|
-
| `commitHistorySetup(symbol, messages)` | Orchestrator β appends order book + all candle histories + all indicators + context |
|
|
180
|
-
| `commitBookDataReport(symbol, messages)` | Order-book depth & imbalance section |
|
|
181
|
-
| `commitOneMinuteHistory` / `commitFifteenMinuteHistory` / `commitThirtyMinuteHistory` / `commitHourHistory` | Candle-history sections per timeframe |
|
|
182
|
-
| `commitMicroTermMath` / `commitShortTermMath` / `commitSwingTermMath` / `commitLongTermMath` | Indicator-table sections (1m / 15m / 30m / 1h) |
|
|
183
|
-
| `setLogger(logger)` | Replace the default no-op logger |
|
|
184
|
-
| `lib` | Internal IoC service container (advanced use) |
|
|
185
|
-
|
|
186
|
-
<details>
|
|
187
|
-
<summary>Complete source map</summary>
|
|
188
|
-
|
|
189
|
-
- `function/history.function.ts` β the four `commit*History` functions. `function/math.function.ts` β the four `commit*Math` functions. `function/other.function.ts` β `commitBookDataReport` + `commitHistorySetup`.
|
|
190
|
-
- `tools/setup.tool.ts` β `setLogger`. `contract/{History,ReportFn}.contract.ts` β report-function contracts. `interfaces/Logger.interface.ts`.
|
|
191
|
-
- `lib/` IoC: `core/{di,provide,types}`, `services/common/LoggerService`, `services/history/{One,Fifteen,Thirty}MinuteCandleHistoryService` + `HourCandleHistoryService`, `services/math/{MicroTerm,ShortTerm,SwingTerm,LongTerm}MathService` + `BookDataMathService` (the math services are the package's bulk β 32β45 KB each). Every export maps to one of these; nothing in `src/` is undocumented.
|
|
192
|
-
|
|
193
|
-
</details>
|
|
194
|
-
|
|
195
|
-
## π€ Contribute
|
|
196
|
-
|
|
197
|
-
Fork / PR on [GitHub](https://github.com/tripolskypetr/backtest-kit).
|
|
198
|
-
|
|
199
|
-
## π License
|
|
200
|
-
|
|
201
|
-
MIT Β© [tripolskypetr](https://github.com/tripolskypetr)
|
|
1
|
+
<img src="https://github.com/tripolskypetr/backtest-kit/raw/refs/heads/master/assets/chronos.svg" height="45px" align="right">
|
|
2
|
+
|
|
3
|
+
# π @backtest-kit/signals
|
|
4
|
+
|
|
5
|
+
> Multi-timeframe technical analysis for AI trading on [backtest-kit](https://www.npmjs.com/package/backtest-kit). Computes 50+ indicators across four timeframes plus order-book depth, and emits LLM-ready markdown reports β drop the whole market context into an LLM prompt in one call.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
[](https://deepwiki.com/tripolskypetr/backtest-kit)
|
|
10
|
+
[](https://npmjs.org/package/@backtest-kit/signals)
|
|
11
|
+
[]()
|
|
12
|
+
|
|
13
|
+
π **[Docs](https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html)** Β· π **[Reference implementation](https://github.com/tripolskypetr/backtest-kit/tree/master/example)** Β· π **[GitHub](https://github.com/tripolskypetr/backtest-kit)**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @backtest-kit/signals backtest-kit
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Why
|
|
22
|
+
|
|
23
|
+
An LLM trading strategy is only as good as the market context you hand it. Computing 50+ indicators across four timeframes, formatting order-book depth, and laying it all out as clean markdown β by hand, every tick β is the unglamorous 200 lines that decides signal quality. This package is that work, pre-computed, cached, and synchronized with backtest-kit's timeline: one `commitHistorySetup(symbol, messages)` appends order book + candle history + indicators for 1m/15m/30m/1h to your LLM message array.
|
|
24
|
+
|
|
25
|
+
- π **Four synchronized timeframes** β MicroTerm 1m Β· ShortTerm 15m Β· SwingTerm 30m Β· LongTerm 1h.
|
|
26
|
+
- π― **50+ indicators** β RSI, MACD, Bollinger, Stochastic, ADX, ATR, CCI, Fibonacci, support/resistance, squeeze, volume trend.
|
|
27
|
+
- π **Order-book depth** β best bid/ask, spread, top-20 levels, liquidity imbalance.
|
|
28
|
+
- π€ **LLM-ready markdown** β formatted tables for context injection.
|
|
29
|
+
- β‘ **Cached** β per-timeframe TTL; cache cleared on error.
|
|
30
|
+
- π¦ **Zero config** β works out of the box on the engine's temporal context.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quick start β one call
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { commitHistorySetup } from '@backtest-kit/signals';
|
|
38
|
+
|
|
39
|
+
const messages = [];
|
|
40
|
+
await commitHistorySetup('BTCUSDT', messages);
|
|
41
|
+
// messages now hold: order book + 1m/15m/30m/1h candle history
|
|
42
|
+
// + indicators for all 4 timeframes + system context (symbol, price, timestamp)
|
|
43
|
+
const signal = await llm(messages);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
<details>
|
|
47
|
+
<summary>Complete LLM strategy</summary>
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { v4 as uuid } from 'uuid';
|
|
51
|
+
import { addStrategy, dumpSignal } from 'backtest-kit';
|
|
52
|
+
import { commitHistorySetup } from '@backtest-kit/signals';
|
|
53
|
+
import { json } from './utils/json.mjs'; // your LLM wrapper
|
|
54
|
+
|
|
55
|
+
addStrategy({
|
|
56
|
+
strategyName: 'llm-strategy', interval: '5m', riskName: 'demo',
|
|
57
|
+
getSignal: async (symbol) => {
|
|
58
|
+
const messages = [{ role: 'system', content: 'You are a trading bot. Analyze the indicators and generate a signal.' }];
|
|
59
|
+
await commitHistorySetup(symbol, messages);
|
|
60
|
+
messages.push({ role: 'user', content: [
|
|
61
|
+
'Based on the technical analysis above, generate a trading signal.',
|
|
62
|
+
'Use position: "wait" if signals are unclear or contradictory.',
|
|
63
|
+
'Return JSON: { position: "long"|"short"|"wait", priceTakeProfit: number, priceStopLoss: number }',
|
|
64
|
+
].join('\n') });
|
|
65
|
+
|
|
66
|
+
const resultId = uuid();
|
|
67
|
+
const signal = await json(messages);
|
|
68
|
+
await dumpSignal(resultId, messages, signal); // archive for debugging
|
|
69
|
+
return { ...signal, id: resultId };
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
</details>
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Granular control
|
|
79
|
+
|
|
80
|
+
Prefer to choose exactly what goes into the prompt? Call the individual report functions β each appends one markdown section to `messages`.
|
|
81
|
+
|
|
82
|
+
<details>
|
|
83
|
+
<summary>The 9 granular functions</summary>
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import {
|
|
87
|
+
commitBookDataReport, // order book: bids/asks, spread, imbalance
|
|
88
|
+
commitOneMinuteHistory, commitFifteenMinuteHistory, // candle histories (last 15 / 8 β¦)
|
|
89
|
+
commitThirtyMinuteHistory, commitHourHistory,
|
|
90
|
+
commitMicroTermMath, commitShortTermMath, // indicator tables per timeframe
|
|
91
|
+
commitSwingTermMath, commitLongTermMath,
|
|
92
|
+
} from '@backtest-kit/signals';
|
|
93
|
+
|
|
94
|
+
const messages = [];
|
|
95
|
+
await commitBookDataReport('BTCUSDT', messages);
|
|
96
|
+
await commitOneMinuteHistory('BTCUSDT', messages);
|
|
97
|
+
await commitMicroTermMath('BTCUSDT', messages);
|
|
98
|
+
// β¦add only the sections you want, then call your LLM
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`commitHistorySetup` is simply the orchestrator that runs all of these in the right order.
|
|
102
|
+
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## What each timeframe computes
|
|
108
|
+
|
|
109
|
+
| Timeframe | Candles | Indicators | Use case |
|
|
110
|
+
|-----------|---------|------------|----------|
|
|
111
|
+
| **MicroTerm** (1m) | 60 | RSI(9,14), MACD(8,21,5), Stochastic, ADX(9), Bollinger(8,2), ATR, CCI, Volume, Squeeze | Scalping, ultra-short entries |
|
|
112
|
+
| **ShortTerm** (15m) | 144 | RSI(9), MACD(8,21,5), Stochastic(5,3,3), ADX(14), Bollinger(10,2), Fibonacci | Day trading |
|
|
113
|
+
| **SwingTerm** (30m) | 96 | RSI(14), MACD(12,26,9), Stochastic(14,3,3), Bollinger(20,2), Support/Resistance | Swing trading |
|
|
114
|
+
| **LongTerm** (1h) | 100 | RSI(14), MACD(12,26,9), ADX(14), Bollinger(20,2), SMA(50), DEMA, WMA, Volume Trend | Trend analysis |
|
|
115
|
+
|
|
116
|
+
<details>
|
|
117
|
+
<summary>Report structure (order book Β· candles Β· indicators)</summary>
|
|
118
|
+
|
|
119
|
+
**Order book** β symbol, best bid/ask, mid price, spread, depth imbalance (`(bid_vol β ask_vol)/(bid_vol + ask_vol)`, + = buy pressure), and top-20 bid/ask levels with `% of total`.
|
|
120
|
+
|
|
121
|
+
**Candle history** β per-candle table: timestamp, OHLC, volume, volatility, body size.
|
|
122
|
+
|
|
123
|
+
**Indicators** β a wide per-bar table; e.g. MicroTerm columns: Price, RSI(9), RSI(14), MACD, Signal, Histogram, Stoch %K/%D, ADX, +DI, βDI, BB Upper/Middle/Lower, ATR(5/9), CCI(9), Volume, Vol Trend, Momentum, ROC, Support, Resistance, Squeeze, Pressure β followed by a **Data Sources** note listing every period used.
|
|
124
|
+
|
|
125
|
+
</details>
|
|
126
|
+
|
|
127
|
+
<details>
|
|
128
|
+
<summary>Caching & key algorithms</summary>
|
|
129
|
+
|
|
130
|
+
**Cache TTL** (cleared on error): 1m data β 1 min Β· 15m β 5 min Β· 30m β 15 min Β· 1h β 30 min Β· order book β 5 min.
|
|
131
|
+
|
|
132
|
+
- **Support/Resistance** β MicroTerm/SwingTerm look back N candles for significant highs/lows (Β±0.3% threshold); LongTerm uses a 4-candle pivot method.
|
|
133
|
+
- **Fibonacci** β levels 0 / 23.6 / 38.2 / 50 / 61.8 / 78.6 / 100 %, extensions 127.2 / 161.8 / 261.8 %; nearest level to price within 1.5% tolerance.
|
|
134
|
+
- **Volume** β MicroTerm: SMA(5) with increasing/decreasing/stable trend (Β±20%); LongTerm: 6-candle average (Β±10%).
|
|
135
|
+
- **Order-book imbalance** β `(bid β ask)/(bid + ask)`, positive = buy pressure.
|
|
136
|
+
|
|
137
|
+
</details>
|
|
138
|
+
|
|
139
|
+
<details>
|
|
140
|
+
<summary>Custom logger (default is no-op)</summary>
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { setLogger } from '@backtest-kit/signals';
|
|
144
|
+
setLogger({ log: console.log, debug: console.debug, info: console.info, warn: console.warn });
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
</details>
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Why not compute indicators yourself?
|
|
152
|
+
|
|
153
|
+
<details>
|
|
154
|
+
<summary>The difference</summary>
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// β Manual β 40+ indicators, formatting, caching, all by hand
|
|
158
|
+
const candles = await getCandles('BTCUSDT', '1m', 60);
|
|
159
|
+
const rsi = calculateRSI(candles, 14);
|
|
160
|
+
const macd = calculateMACD(candles, 12, 26, 9);
|
|
161
|
+
const bb = calculateBollingerBands(candles, 20, 2);
|
|
162
|
+
// β¦and the markdown formatting, and the cache
|
|
163
|
+
messages.push({ role: 'user', content: formatToMarkdown(rsi, macd, bb /* β¦ */) });
|
|
164
|
+
|
|
165
|
+
// β
With signals
|
|
166
|
+
await commitHistorySetup('BTCUSDT', messages);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Pre-computed, cached, optimized Β· 50+ indicators Γ 4 timeframes Β· LLM-ready markdown Β· synchronized with the backtest timeline Β· validation & error handling built in.
|
|
170
|
+
|
|
171
|
+
</details>
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## API reference
|
|
176
|
+
|
|
177
|
+
| Export | Description |
|
|
178
|
+
|--------|-------------|
|
|
179
|
+
| `commitHistorySetup(symbol, messages)` | Orchestrator β appends order book + all candle histories + all indicators + context |
|
|
180
|
+
| `commitBookDataReport(symbol, messages)` | Order-book depth & imbalance section |
|
|
181
|
+
| `commitOneMinuteHistory` / `commitFifteenMinuteHistory` / `commitThirtyMinuteHistory` / `commitHourHistory` | Candle-history sections per timeframe |
|
|
182
|
+
| `commitMicroTermMath` / `commitShortTermMath` / `commitSwingTermMath` / `commitLongTermMath` | Indicator-table sections (1m / 15m / 30m / 1h) |
|
|
183
|
+
| `setLogger(logger)` | Replace the default no-op logger |
|
|
184
|
+
| `lib` | Internal IoC service container (advanced use) |
|
|
185
|
+
|
|
186
|
+
<details>
|
|
187
|
+
<summary>Complete source map</summary>
|
|
188
|
+
|
|
189
|
+
- `function/history.function.ts` β the four `commit*History` functions. `function/math.function.ts` β the four `commit*Math` functions. `function/other.function.ts` β `commitBookDataReport` + `commitHistorySetup`.
|
|
190
|
+
- `tools/setup.tool.ts` β `setLogger`. `contract/{History,ReportFn}.contract.ts` β report-function contracts. `interfaces/Logger.interface.ts`.
|
|
191
|
+
- `lib/` IoC: `core/{di,provide,types}`, `services/common/LoggerService`, `services/history/{One,Fifteen,Thirty}MinuteCandleHistoryService` + `HourCandleHistoryService`, `services/math/{MicroTerm,ShortTerm,SwingTerm,LongTerm}MathService` + `BookDataMathService` (the math services are the package's bulk β 32β45 KB each). Every export maps to one of these; nothing in `src/` is undocumented.
|
|
192
|
+
|
|
193
|
+
</details>
|
|
194
|
+
|
|
195
|
+
## π€ Contribute
|
|
196
|
+
|
|
197
|
+
Fork / PR on [GitHub](https://github.com/tripolskypetr/backtest-kit).
|
|
198
|
+
|
|
199
|
+
## π License
|
|
200
|
+
|
|
201
|
+
MIT Β© [tripolskypetr](https://github.com/tripolskypetr)
|