@backtest-kit/signals 0.0.1 → 0.0.2
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 +1 -0
- package/package.json +16 -11
- package/types.d.ts +1806 -294
- package/build/index.cjs +0 -3004
- package/build/index.mjs +0 -2991
package/types.d.ts
CHANGED
|
@@ -1,294 +1,1806 @@
|
|
|
1
|
-
import { IBaseMessage, IOutlineHistory } from 'agent-swarm-kit';
|
|
2
|
-
import { ICandleData } from 'backtest-kit';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
declare
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
1
|
+
import { IBaseMessage, IOutlineHistory } from 'agent-swarm-kit';
|
|
2
|
+
import { ICandleData } from 'backtest-kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type representing the history container for technical analysis reports.
|
|
6
|
+
*
|
|
7
|
+
* Defines the contract for accumulating and organizing market analysis data
|
|
8
|
+
* for consumption by LLM-based trading strategies. Supports both message array
|
|
9
|
+
* format and outline history format from agent-swarm-kit.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { commitHistorySetup } from '@backtest-kit/signals';
|
|
14
|
+
*
|
|
15
|
+
* // Using as message array
|
|
16
|
+
* const messages: IBaseMessage[] = [];
|
|
17
|
+
* await commitHistorySetup('BTCUSDT', messages);
|
|
18
|
+
* // messages now contains all technical analysis reports
|
|
19
|
+
*
|
|
20
|
+
* // Using with outline history
|
|
21
|
+
* const outline: IOutlineHistory = createOutline();
|
|
22
|
+
* await commitMicroTermMath('BTCUSDT', outline);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
type HistoryContract = IBaseMessage[] | IOutlineHistory;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Type representing a report generation function for technical analysis.
|
|
29
|
+
*
|
|
30
|
+
* Standard signature for all report commit functions in the signals library.
|
|
31
|
+
* Each function generates a specific type of market analysis (candle history,
|
|
32
|
+
* technical indicators, order book data) and appends it to the history container
|
|
33
|
+
* as formatted markdown.
|
|
34
|
+
*
|
|
35
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT')
|
|
36
|
+
* @param history - History container (message array or outline) to append report to
|
|
37
|
+
* @returns Promise that resolves when report is successfully committed
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { commitMicroTermMath } from '@backtest-kit/signals';
|
|
42
|
+
*
|
|
43
|
+
* const messages = [];
|
|
44
|
+
*
|
|
45
|
+
* // Function signature matches ReportFn
|
|
46
|
+
* await commitMicroTermMath('BTCUSDT', messages);
|
|
47
|
+
*
|
|
48
|
+
* // messages[0].content now contains 1-minute technical analysis table
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
type ReportFn = (symbol: string, history: HistoryContract) => Promise<void>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Candle history report generation functions for multi-timeframe analysis.
|
|
55
|
+
*
|
|
56
|
+
* Provides cached functions to fetch and commit OHLCV candle history reports
|
|
57
|
+
* across 4 timeframes (1m, 15m, 30m, 1h) formatted as markdown for LLM consumption.
|
|
58
|
+
* Each function automatically handles caching, error recovery, and report formatting.
|
|
59
|
+
*
|
|
60
|
+
* Key features:
|
|
61
|
+
* - Intelligent caching with timeframe-specific TTL (1m: 1min, 15m: 5min, 30m: 15min, 1h: 30min)
|
|
62
|
+
* - Automatic cache clearing on errors for data freshness
|
|
63
|
+
* - Formatted markdown tables with candle details (OHLCV, volatility, body size, candle type)
|
|
64
|
+
* - User/assistant message pair format for LLM context
|
|
65
|
+
*
|
|
66
|
+
* @module function/history
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Commits 1-hour candle history report to history container.
|
|
71
|
+
*
|
|
72
|
+
* Fetches and appends a markdown-formatted report of the last 6 hourly candles
|
|
73
|
+
* including OHLCV data, volatility, body size, and candle type (Green/Red/Doji).
|
|
74
|
+
* Automatically clears cache on errors to ensure data freshness.
|
|
75
|
+
*
|
|
76
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
77
|
+
* @param history - History container to append report to
|
|
78
|
+
* @returns Promise that resolves when report is committed
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { commitHourHistory } from '@backtest-kit/signals';
|
|
83
|
+
*
|
|
84
|
+
* const messages = [];
|
|
85
|
+
* await commitHourHistory('BTCUSDT', messages);
|
|
86
|
+
*
|
|
87
|
+
* // messages now contains:
|
|
88
|
+
* // [
|
|
89
|
+
* // { role: 'user', content: '=== HOURLY CANDLES HISTORY (LAST 6) ===\n\n...' },
|
|
90
|
+
* // { role: 'assistant', content: 'Hourly candles history received.' }
|
|
91
|
+
* // ]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare const commitHourHistory: ReportFn;
|
|
95
|
+
/**
|
|
96
|
+
* Commits 30-minute candle history report to history container.
|
|
97
|
+
*
|
|
98
|
+
* Fetches and appends a markdown-formatted report of the last 6 thirty-minute candles
|
|
99
|
+
* including OHLCV data, volatility, body size, and candle type (Green/Red/Doji).
|
|
100
|
+
* Automatically clears cache on errors to ensure data freshness.
|
|
101
|
+
*
|
|
102
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
103
|
+
* @param history - History container to append report to
|
|
104
|
+
* @returns Promise that resolves when report is committed
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import { commitThirtyMinuteHistory } from '@backtest-kit/signals';
|
|
109
|
+
*
|
|
110
|
+
* const messages = [];
|
|
111
|
+
* await commitThirtyMinuteHistory('ETHUSDT', messages);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare const commitThirtyMinuteHistory: ReportFn;
|
|
115
|
+
/**
|
|
116
|
+
* Commits 15-minute candle history report to history container.
|
|
117
|
+
*
|
|
118
|
+
* Fetches and appends a markdown-formatted report of the last 8 fifteen-minute candles
|
|
119
|
+
* including OHLCV data, volatility, body size, and candle type (Green/Red/Doji).
|
|
120
|
+
* Automatically clears cache on errors to ensure data freshness.
|
|
121
|
+
*
|
|
122
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
123
|
+
* @param history - History container to append report to
|
|
124
|
+
* @returns Promise that resolves when report is committed
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { commitFifteenMinuteHistory } from '@backtest-kit/signals';
|
|
129
|
+
*
|
|
130
|
+
* const messages = [];
|
|
131
|
+
* await commitFifteenMinuteHistory('BTCUSDT', messages);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare const commitFifteenMinuteHistory: ReportFn;
|
|
135
|
+
/**
|
|
136
|
+
* Commits 1-minute candle history report to history container.
|
|
137
|
+
*
|
|
138
|
+
* Fetches and appends a markdown-formatted report of the last 15 one-minute candles
|
|
139
|
+
* including OHLCV data, volatility, body size, and candle type (Green/Red/Doji).
|
|
140
|
+
* Automatically clears cache on errors to ensure data freshness.
|
|
141
|
+
*
|
|
142
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
143
|
+
* @param history - History container to append report to
|
|
144
|
+
* @returns Promise that resolves when report is committed
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* import { commitOneMinuteHistory } from '@backtest-kit/signals';
|
|
149
|
+
*
|
|
150
|
+
* const messages = [];
|
|
151
|
+
* await commitOneMinuteHistory('BTCUSDT', messages);
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare const commitOneMinuteHistory: ReportFn;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Technical indicator report generation functions for multi-timeframe trading analysis.
|
|
158
|
+
*
|
|
159
|
+
* Provides cached functions to fetch and commit comprehensive technical indicator reports
|
|
160
|
+
* across 4 trading timeframes (MicroTerm: 1m, ShortTerm: 15m, SwingTerm: 30m, LongTerm: 1h).
|
|
161
|
+
* Each report includes 50+ indicators formatted as markdown tables for LLM consumption.
|
|
162
|
+
*
|
|
163
|
+
* Key features:
|
|
164
|
+
* - MicroTerm (1m): RSI(9,14), MACD(8,21,5), Stochastic, ADX(9), Bollinger(8,2), ATR, CCI, Volume analysis, Squeeze momentum
|
|
165
|
+
* - ShortTerm (15m): RSI(9), MACD(8,21,5), Stochastic(5,3,3), ADX(14), Bollinger(10,2), Fibonacci levels
|
|
166
|
+
* - SwingTerm (30m): RSI(14), MACD(12,26,9), Stochastic(14,3,3), Bollinger(20,2), Support/Resistance, Fibonacci
|
|
167
|
+
* - LongTerm (1h): RSI(14), MACD(12,26,9), ADX(14), Bollinger(20,2), SMA(50), DEMA, WMA, Volume trends
|
|
168
|
+
* - Intelligent caching with timeframe-specific TTL
|
|
169
|
+
* - Automatic cache clearing on errors
|
|
170
|
+
*
|
|
171
|
+
* @module function/math
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Commits MicroTerm (1-minute) technical analysis report to history container.
|
|
176
|
+
*
|
|
177
|
+
* Generates comprehensive technical analysis for scalping and ultra-short term trading.
|
|
178
|
+
* Includes 40+ indicators optimized for 1-minute timeframe with 60-candle lookback.
|
|
179
|
+
*
|
|
180
|
+
* Indicators included:
|
|
181
|
+
* - Momentum: RSI(9,14), Stochastic RSI(9,14), MACD(8,21,5), Momentum(5,10), ROC(1,3,5)
|
|
182
|
+
* - Trend: ADX(9), +DI/-DI(9), EMA(3,8,13,21), SMA(8), DEMA(8), WMA(5)
|
|
183
|
+
* - Volatility: ATR(5,9), Bollinger Bands(8,2) with width/position, Squeeze momentum
|
|
184
|
+
* - Volume: SMA(5), volume ratio, volume trend (increasing/decreasing/stable)
|
|
185
|
+
* - Support/Resistance: Dynamic levels from 30-candle window
|
|
186
|
+
* - Price Analysis: 1m/3m/5m price changes, volatility, true range, pressure index
|
|
187
|
+
*
|
|
188
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
189
|
+
* @param history - History container to append report to
|
|
190
|
+
* @returns Promise that resolves when report is committed
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* import { commitMicroTermMath } from '@backtest-kit/signals';
|
|
195
|
+
*
|
|
196
|
+
* const messages = [];
|
|
197
|
+
* await commitMicroTermMath('BTCUSDT', messages);
|
|
198
|
+
*
|
|
199
|
+
* // Use in LLM strategy for scalping signals
|
|
200
|
+
* const signal = await llm([
|
|
201
|
+
* { role: 'system', content: 'Analyze for scalping opportunities' },
|
|
202
|
+
* ...messages
|
|
203
|
+
* ]);
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare const commitMicroTermMath: ReportFn;
|
|
207
|
+
/**
|
|
208
|
+
* Commits LongTerm (1-hour) technical analysis report to history container.
|
|
209
|
+
*
|
|
210
|
+
* Generates comprehensive technical analysis for trend identification and position management.
|
|
211
|
+
* Includes 30+ indicators optimized for 1-hour timeframe with 48-candle lookback (48 hours).
|
|
212
|
+
*
|
|
213
|
+
* Indicators included:
|
|
214
|
+
* - Momentum: RSI(14), Stochastic RSI(14), MACD(12,26,9), Stochastic(14,3,3), Momentum(10)
|
|
215
|
+
* - Trend: ADX(14), +DI/-DI(14), SMA(50), EMA(20,34), DEMA(21), WMA(20)
|
|
216
|
+
* - Volatility: ATR(14,20), Bollinger Bands(20,2), CCI(20)
|
|
217
|
+
* - Support/Resistance: 4-candle pivot detection
|
|
218
|
+
* - Fibonacci: Retracement levels (0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%, 100%) with nearest level
|
|
219
|
+
* - Volume: Trend analysis (increasing/decreasing/stable)
|
|
220
|
+
*
|
|
221
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
222
|
+
* @param history - History container to append report to
|
|
223
|
+
* @returns Promise that resolves when report is committed
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* import { commitLongTermMath } from '@backtest-kit/signals';
|
|
228
|
+
*
|
|
229
|
+
* const messages = [];
|
|
230
|
+
* await commitLongTermMath('ETHUSDT', messages);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare const commitLongTermMath: ReportFn;
|
|
234
|
+
/**
|
|
235
|
+
* Commits ShortTerm (15-minute) technical analysis report to history container.
|
|
236
|
+
*
|
|
237
|
+
* Generates comprehensive technical analysis for day trading strategies.
|
|
238
|
+
* Includes 30+ indicators optimized for 15-minute timeframe with 144-candle lookback (36 hours).
|
|
239
|
+
*
|
|
240
|
+
* Indicators included:
|
|
241
|
+
* - Momentum: RSI(9), Stochastic RSI(9), MACD(8,21,5), Stochastic(5,3,3), Momentum(8), ROC(5,10)
|
|
242
|
+
* - Trend: ADX(14), +DI/-DI(14), SMA(50), EMA(8,21), DEMA(21), WMA(20)
|
|
243
|
+
* - Volatility: ATR(9), Bollinger Bands(10,2) with width, CCI(14)
|
|
244
|
+
* - Support/Resistance: 48-candle window with 0.3% threshold
|
|
245
|
+
* - Fibonacci: Retracement levels over 288-candle lookback (72 hours)
|
|
246
|
+
* - Volume: Trend analysis over 16-candle window
|
|
247
|
+
*
|
|
248
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
249
|
+
* @param history - History container to append report to
|
|
250
|
+
* @returns Promise that resolves when report is committed
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* import { commitShortTermMath } from '@backtest-kit/signals';
|
|
255
|
+
*
|
|
256
|
+
* const messages = [];
|
|
257
|
+
* await commitShortTermMath('BTCUSDT', messages);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
declare const commitShortTermMath: ReportFn;
|
|
261
|
+
/**
|
|
262
|
+
* Commits SwingTerm (30-minute) technical analysis report to history container.
|
|
263
|
+
*
|
|
264
|
+
* Generates comprehensive technical analysis for swing trading strategies.
|
|
265
|
+
* Includes 30+ indicators optimized for 30-minute timeframe with 96-candle lookback (48 hours).
|
|
266
|
+
*
|
|
267
|
+
* Indicators included:
|
|
268
|
+
* - Momentum: RSI(14), Stochastic RSI(14), MACD(12,26,9), Stochastic(14,3,3), Momentum(8)
|
|
269
|
+
* - Trend: ADX(14), +DI/-DI(14), SMA(20), EMA(13,34), DEMA(21), WMA(20)
|
|
270
|
+
* - Volatility: ATR(14), Bollinger Bands(20,2) with width, CCI(20), Basic volatility
|
|
271
|
+
* - Support/Resistance: 20-candle window detection
|
|
272
|
+
* - Fibonacci: Support/resistance levels with current level identification
|
|
273
|
+
* - Volume: Trading volume analysis
|
|
274
|
+
* - Price Momentum: 6-period momentum indicator
|
|
275
|
+
*
|
|
276
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
277
|
+
* @param history - History container to append report to
|
|
278
|
+
* @returns Promise that resolves when report is committed
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* import { commitSwingTermMath } from '@backtest-kit/signals';
|
|
283
|
+
*
|
|
284
|
+
* const messages = [];
|
|
285
|
+
* await commitSwingTermMath('BTCUSDT', messages);
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
declare const commitSwingTermMath: ReportFn;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Orchestrator functions for complete market analysis setup.
|
|
292
|
+
*
|
|
293
|
+
* Provides high-level functions that combine multiple analysis types
|
|
294
|
+
* (order book, candle history, technical indicators) into comprehensive
|
|
295
|
+
* market reports for LLM-based trading strategies.
|
|
296
|
+
*
|
|
297
|
+
* Key features:
|
|
298
|
+
* - commitBookDataReport: Order book analysis with top 20 levels by volume
|
|
299
|
+
* - commitHistorySetup: All-in-one setup with full multi-timeframe analysis
|
|
300
|
+
* - Automatic mode detection (skips order book in backtest mode)
|
|
301
|
+
* - System context injection (symbol, price, timestamp)
|
|
302
|
+
*
|
|
303
|
+
* @module function/other
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Commits order book analysis report to history container.
|
|
308
|
+
*
|
|
309
|
+
* Fetches and appends real-time order book data including top 20 price levels
|
|
310
|
+
* by volume percentage, best bid/ask, mid price, spread, and depth imbalance.
|
|
311
|
+
* Automatically skipped in backtest mode (order book data unavailable).
|
|
312
|
+
*
|
|
313
|
+
* Order book metrics:
|
|
314
|
+
* - Best Bid/Ask: Top buy and sell prices
|
|
315
|
+
* - Mid Price: (Best Bid + Best Ask) / 2
|
|
316
|
+
* - Spread: Best Ask - Best Bid
|
|
317
|
+
* - Depth Imbalance: (Bid Volume - Ask Volume) / (Bid Volume + Ask Volume)
|
|
318
|
+
* - Positive = buying pressure
|
|
319
|
+
* - Negative = selling pressure
|
|
320
|
+
* - Top 20 Levels: Sorted by volume percentage on each side
|
|
321
|
+
*
|
|
322
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
323
|
+
* @param history - History container to append report to
|
|
324
|
+
* @returns Promise that resolves when report is committed (or immediately in backtest mode)
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* import { commitBookDataReport } from '@backtest-kit/signals';
|
|
329
|
+
*
|
|
330
|
+
* const messages = [];
|
|
331
|
+
* await commitBookDataReport('BTCUSDT', messages);
|
|
332
|
+
*
|
|
333
|
+
* // In live mode: messages contains order book analysis
|
|
334
|
+
* // In backtest mode: messages unchanged (order book skipped)
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare const commitBookDataReport: ReportFn;
|
|
338
|
+
/**
|
|
339
|
+
* Commits complete multi-timeframe market analysis setup to history container.
|
|
340
|
+
*
|
|
341
|
+
* All-in-one function that orchestrates the full technical analysis pipeline.
|
|
342
|
+
* Sequentially commits order book data, candle histories, technical indicators,
|
|
343
|
+
* and system context for comprehensive LLM-based trading analysis.
|
|
344
|
+
*
|
|
345
|
+
* Analysis pipeline:
|
|
346
|
+
* 1. Order Book: Top 20 levels, bid/ask depth, spread, imbalance (live mode only)
|
|
347
|
+
* 2. Candle Histories: 1m (15 candles), 15m (8 candles), 30m (6 candles), 1h (6 candles)
|
|
348
|
+
* 3. Technical Indicators:
|
|
349
|
+
* - MicroTerm (1m): 40+ scalping indicators
|
|
350
|
+
* - ShortTerm (15m): 30+ day trading indicators
|
|
351
|
+
* - SwingTerm (30m): 30+ swing trading indicators
|
|
352
|
+
* - LongTerm (1h): 30+ trend indicators
|
|
353
|
+
* 4. System Context: Symbol, current price (VWAP), timestamp
|
|
354
|
+
*
|
|
355
|
+
* Total output: 150+ indicators across 4 timeframes + order book + candle data
|
|
356
|
+
*
|
|
357
|
+
* @param symbol - Trading pair symbol (e.g., 'BTCUSDT')
|
|
358
|
+
* @param history - History container to append all reports to
|
|
359
|
+
* @returns Promise that resolves when all reports are committed
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* import { commitHistorySetup } from '@backtest-kit/signals';
|
|
364
|
+
* import { json } from './llm-wrapper';
|
|
365
|
+
*
|
|
366
|
+
* // Complete LLM strategy setup
|
|
367
|
+
* const messages = [
|
|
368
|
+
* { role: 'system', content: 'You are a trading bot. Analyze and generate signals.' }
|
|
369
|
+
* ];
|
|
370
|
+
*
|
|
371
|
+
* // Inject all technical analysis
|
|
372
|
+
* await commitHistorySetup('BTCUSDT', messages);
|
|
373
|
+
*
|
|
374
|
+
* // Generate trading signal
|
|
375
|
+
* const signal = await json(messages);
|
|
376
|
+
* console.log(signal); // { position: 'long', priceTakeProfit: 50500, priceStopLoss: 49500 }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare const commitHistorySetup: (symbol: string, history: HistoryContract) => Promise<void>;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Logger interface for diagnostic output in signals library.
|
|
383
|
+
*
|
|
384
|
+
* Defines the contract for custom logging implementations.
|
|
385
|
+
* By default, signals uses a no-op logger (all methods do nothing).
|
|
386
|
+
* Use setLogger() to provide a custom implementation for debugging and monitoring.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { setLogger } from '@backtest-kit/signals';
|
|
391
|
+
*
|
|
392
|
+
* // Enable console logging
|
|
393
|
+
* setLogger({
|
|
394
|
+
* log: console.log,
|
|
395
|
+
* debug: console.debug,
|
|
396
|
+
* info: console.info,
|
|
397
|
+
* warn: console.warn,
|
|
398
|
+
* });
|
|
399
|
+
*
|
|
400
|
+
* // Or custom logger
|
|
401
|
+
* setLogger({
|
|
402
|
+
* log: (topic, ...args) => myLogger.log(`[SIGNALS] ${topic}`, args),
|
|
403
|
+
* debug: (topic, ...args) => myLogger.debug(`[SIGNALS] ${topic}`, args),
|
|
404
|
+
* info: (topic, ...args) => myLogger.info(`[SIGNALS] ${topic}`, args),
|
|
405
|
+
* warn: (topic, ...args) => myLogger.warn(`[SIGNALS] ${topic}`, args),
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
interface ILogger {
|
|
410
|
+
/**
|
|
411
|
+
* Log general information.
|
|
412
|
+
* @param topic - Log category or topic
|
|
413
|
+
* @param args - Additional arguments to log
|
|
414
|
+
*/
|
|
415
|
+
log(topic: string, ...args: any[]): void;
|
|
416
|
+
/**
|
|
417
|
+
* Log debug information.
|
|
418
|
+
* @param topic - Log category or topic
|
|
419
|
+
* @param args - Additional arguments to log
|
|
420
|
+
*/
|
|
421
|
+
debug(topic: string, ...args: any[]): void;
|
|
422
|
+
/**
|
|
423
|
+
* Log informational messages.
|
|
424
|
+
* @param topic - Log category or topic
|
|
425
|
+
* @param args - Additional arguments to log
|
|
426
|
+
*/
|
|
427
|
+
info(topic: string, ...args: any[]): void;
|
|
428
|
+
/**
|
|
429
|
+
* Log warning messages.
|
|
430
|
+
* @param topic - Log category or topic
|
|
431
|
+
* @param args - Additional arguments to log
|
|
432
|
+
*/
|
|
433
|
+
warn(topic: string, ...args: any[]): void;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Configuration utilities for signals library.
|
|
438
|
+
*
|
|
439
|
+
* Provides functions to customize library behavior, primarily logging configuration.
|
|
440
|
+
*
|
|
441
|
+
* @module tools/setup
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Sets custom logger implementation for signals library.
|
|
446
|
+
*
|
|
447
|
+
* By default, signals uses a no-op logger (no output).
|
|
448
|
+
* Use this function to enable logging for debugging and monitoring.
|
|
449
|
+
*
|
|
450
|
+
* @param logger - Custom logger implementation conforming to ILogger interface
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```typescript
|
|
454
|
+
* import { setLogger } from '@backtest-kit/signals';
|
|
455
|
+
*
|
|
456
|
+
* // Enable console logging
|
|
457
|
+
* setLogger({
|
|
458
|
+
* log: console.log,
|
|
459
|
+
* debug: console.debug,
|
|
460
|
+
* info: console.info,
|
|
461
|
+
* warn: console.warn,
|
|
462
|
+
* });
|
|
463
|
+
*
|
|
464
|
+
* // Or use custom logger
|
|
465
|
+
* import winston from 'winston';
|
|
466
|
+
* setLogger({
|
|
467
|
+
* log: (topic, ...args) => winston.log('info', topic, args),
|
|
468
|
+
* debug: (topic, ...args) => winston.debug(topic, args),
|
|
469
|
+
* info: (topic, ...args) => winston.info(topic, args),
|
|
470
|
+
* warn: (topic, ...args) => winston.warn(topic, args),
|
|
471
|
+
* });
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
declare const setLogger: (logger: ILogger) => void;
|
|
475
|
+
|
|
476
|
+
interface ISwingTermRow {
|
|
477
|
+
symbol: string;
|
|
478
|
+
rsi14: number | null;
|
|
479
|
+
stochasticRSI14: number | null;
|
|
480
|
+
macd12_26_9: number | null;
|
|
481
|
+
signal9: number | null;
|
|
482
|
+
bollingerUpper20_2: number | null;
|
|
483
|
+
bollingerMiddle20_2: number | null;
|
|
484
|
+
bollingerLower20_2: number | null;
|
|
485
|
+
bollingerWidth20_2: number | null;
|
|
486
|
+
stochasticK14_3_3: number | null;
|
|
487
|
+
stochasticD14_3_3: number | null;
|
|
488
|
+
adx14: number | null;
|
|
489
|
+
plusDI14: number | null;
|
|
490
|
+
minusDI14: number | null;
|
|
491
|
+
cci20: number | null;
|
|
492
|
+
atr14: number | null;
|
|
493
|
+
sma20: number | null;
|
|
494
|
+
ema13: number | null;
|
|
495
|
+
ema34: number | null;
|
|
496
|
+
dema21: number | null;
|
|
497
|
+
wma20: number | null;
|
|
498
|
+
momentum8: number | null;
|
|
499
|
+
support: number;
|
|
500
|
+
resistance: number;
|
|
501
|
+
currentPrice: number;
|
|
502
|
+
volume: number;
|
|
503
|
+
volatility: number | null;
|
|
504
|
+
priceMomentum6: number | null;
|
|
505
|
+
fibonacciNearestSupport: number | null;
|
|
506
|
+
fibonacciNearestResistance: number | null;
|
|
507
|
+
fibonacciCurrentLevel: string;
|
|
508
|
+
bodySize: number;
|
|
509
|
+
closePrice: number;
|
|
510
|
+
date: Date;
|
|
511
|
+
lookbackPeriod: string;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Service for swing-term (30-minute) technical analysis and markdown report generation.
|
|
515
|
+
*
|
|
516
|
+
* Provides comprehensive technical analysis for 30-minute candles with 25+ indicators
|
|
517
|
+
* including momentum (RSI, MACD), trend (EMA, SMA), volatility (ATR, Bollinger Bands),
|
|
518
|
+
* support/resistance levels, and Fibonacci analysis with nearest support/resistance.
|
|
519
|
+
*
|
|
520
|
+
* Key features:
|
|
521
|
+
* - 25+ technical indicators (RSI, MACD, Bollinger Bands, Stochastic, ADX, etc.)
|
|
522
|
+
* - Support/resistance level detection
|
|
523
|
+
* - Fibonacci retracement and extension analysis with nearest levels
|
|
524
|
+
* - Volume and volatility analysis
|
|
525
|
+
* - Price momentum tracking
|
|
526
|
+
* - Markdown table generation for LLM consumption
|
|
527
|
+
* - Intelligent indicator warmup (skips first 34 candles)
|
|
528
|
+
* - Memory-efficient output (last 30 rows only)
|
|
529
|
+
* - Dependency injection support
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* import { SwingTermHistoryService } from '@backtest-kit/signals';
|
|
534
|
+
*
|
|
535
|
+
* const service = new SwingTermHistoryService();
|
|
536
|
+
*
|
|
537
|
+
* // Get markdown report for symbol (fetches candles internally)
|
|
538
|
+
* const report = await service.getReport('BTCUSDT');
|
|
539
|
+
* console.log(report); // Markdown table with all indicators
|
|
540
|
+
*
|
|
541
|
+
* // Or analyze custom candles
|
|
542
|
+
* const candles = await getCandles('ETHUSDT', '30m', 96);
|
|
543
|
+
* const rows = await service.getData('ETHUSDT', candles);
|
|
544
|
+
* console.log(rows[0].rsi14); // 52.45
|
|
545
|
+
* console.log(rows[0].fibonacciCurrentLevel); // "50.0% Retracement"
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
declare class SwingTermHistoryService {
|
|
549
|
+
private loggerService;
|
|
550
|
+
/**
|
|
551
|
+
* Analyzes candle data and returns technical indicator rows.
|
|
552
|
+
*
|
|
553
|
+
* Calculates all technical indicators for provided candles, skips first WARMUP_PERIOD
|
|
554
|
+
* rows to ensure stability, and returns last TABLE_ROWS_LIMIT rows.
|
|
555
|
+
*
|
|
556
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
557
|
+
* @param candles - Array of 30-minute candle data
|
|
558
|
+
* @returns Array of technical analysis rows with all indicators
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* const candles = await getCandles('BTCUSDT', '30m', 96);
|
|
563
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
564
|
+
* console.log(rows.length); // Up to 30 rows
|
|
565
|
+
* console.log(rows[0].rsi14); // 52.45
|
|
566
|
+
* console.log(rows[0].fibonacciNearestSupport); // 42000.50
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
getData: (symbol: string, candles: ICandleData[]) => Promise<ISwingTermRow[]>;
|
|
570
|
+
/**
|
|
571
|
+
* Generates complete markdown technical analysis report for a symbol.
|
|
572
|
+
*
|
|
573
|
+
* Fetches 96 30-minute candles (48 hours) from exchange, calculates all indicators,
|
|
574
|
+
* and formats results as markdown table optimized for LLM consumption.
|
|
575
|
+
*
|
|
576
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
577
|
+
* @returns Markdown-formatted technical analysis report with table and explanations
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* const report = await service.getReport('BTCUSDT');
|
|
582
|
+
* console.log(report);
|
|
583
|
+
* // # 30-Min Candles Analysis for BTCUSDT (Historical Data)
|
|
584
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
585
|
+
* //
|
|
586
|
+
* // | RSI(14) | MACD(12,26,9) | Fibonacci Current Level | ...
|
|
587
|
+
* // | 52.45 | 0.0023 | 50.0% Retracement | ...
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
getReport: (symbol: string) => Promise<string>;
|
|
591
|
+
/**
|
|
592
|
+
* Converts analysis rows into markdown table format.
|
|
593
|
+
*
|
|
594
|
+
* Takes pre-calculated indicator rows and formats them as markdown table
|
|
595
|
+
* with column headers, formatted values, and data source explanations.
|
|
596
|
+
*
|
|
597
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
598
|
+
* @param rows - Array of technical analysis rows from getData()
|
|
599
|
+
* @returns Markdown-formatted table with all indicators
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* const candles = await getCandles('BTCUSDT', '30m', 96);
|
|
604
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
605
|
+
* const markdown = await service.generateHistoryTable('BTCUSDT', rows);
|
|
606
|
+
* console.log(markdown); // Markdown table
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
generateHistoryTable: (symbol: string, rows: ISwingTermRow[]) => Promise<string>;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* LongTerm (1-hour) technical analysis service for trend trading.
|
|
614
|
+
*
|
|
615
|
+
* Generates 30+ indicators on 1-hour candles with 48-candle lookback (48 hours).
|
|
616
|
+
* Optimized for multi-day trend trading and position management.
|
|
617
|
+
*
|
|
618
|
+
* Indicators: RSI(14), StochRSI(14), MACD(12,26,9), Bollinger(20,2), Stochastic(14,3,3),
|
|
619
|
+
* ADX(14), ATR(14,20), CCI(20), Momentum(10), SMA(50), EMA(20,34), DEMA(21), WMA(20),
|
|
620
|
+
* Support/Resistance, Fibonacci levels, Volume trends.
|
|
621
|
+
*
|
|
622
|
+
* Used by commitLongTermMath().
|
|
623
|
+
*/
|
|
624
|
+
|
|
625
|
+
interface ILongTermRow {
|
|
626
|
+
symbol: string;
|
|
627
|
+
rsi14: number | null;
|
|
628
|
+
stochasticRSI14: number | null;
|
|
629
|
+
macd12_26_9: number | null;
|
|
630
|
+
signal9: number | null;
|
|
631
|
+
adx14: number | null;
|
|
632
|
+
pdi14: number | null;
|
|
633
|
+
ndi14: number | null;
|
|
634
|
+
atr14: number | null;
|
|
635
|
+
atr14_raw: number | null;
|
|
636
|
+
atr20: number | null;
|
|
637
|
+
cci20: number | null;
|
|
638
|
+
bollinger20_2_upper: number | null;
|
|
639
|
+
bollinger20_2_middle: number | null;
|
|
640
|
+
bollinger20_2_lower: number | null;
|
|
641
|
+
stochastic14_3_3_K: number | null;
|
|
642
|
+
stochastic14_3_3_D: number | null;
|
|
643
|
+
momentum10: number | null;
|
|
644
|
+
dema21: number | null;
|
|
645
|
+
wma20: number | null;
|
|
646
|
+
sma50: number | null;
|
|
647
|
+
ema20: number | null;
|
|
648
|
+
ema34: number | null;
|
|
649
|
+
currentPrice: number;
|
|
650
|
+
support: number;
|
|
651
|
+
resistance: number;
|
|
652
|
+
volumeTrend: string;
|
|
653
|
+
fibonacciNearestLevel: string;
|
|
654
|
+
fibonacciNearestPrice: number;
|
|
655
|
+
fibonacciDistance: number;
|
|
656
|
+
bodySize: number;
|
|
657
|
+
closePrice: number;
|
|
658
|
+
date: Date;
|
|
659
|
+
lookbackPeriod: string;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Service for long-term (1-hour) technical analysis and markdown report generation.
|
|
663
|
+
*
|
|
664
|
+
* Provides comprehensive technical analysis for 1-hour candles with 30+ indicators
|
|
665
|
+
* including momentum (RSI, MACD), trend (EMA, SMA), volatility (ATR, Bollinger Bands),
|
|
666
|
+
* support/resistance levels, and Fibonacci retracements.
|
|
667
|
+
*
|
|
668
|
+
* Key features:
|
|
669
|
+
* - 30+ technical indicators (RSI, MACD, Bollinger Bands, Stochastic, ADX, etc.)
|
|
670
|
+
* - Support/resistance level detection
|
|
671
|
+
* - Fibonacci retracement analysis
|
|
672
|
+
* - Volume trend analysis
|
|
673
|
+
* - Markdown table generation for LLM consumption
|
|
674
|
+
* - Intelligent indicator warmup (skips first 50 candles)
|
|
675
|
+
* - Memory-efficient output (last 48 rows only)
|
|
676
|
+
* - Dependency injection support
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* import { LongTermHistoryService } from '@backtest-kit/signals';
|
|
681
|
+
*
|
|
682
|
+
* const service = new LongTermHistoryService();
|
|
683
|
+
*
|
|
684
|
+
* // Get markdown report for symbol (fetches candles internally)
|
|
685
|
+
* const report = await service.getReport('BTCUSDT');
|
|
686
|
+
* console.log(report); // Markdown table with all indicators
|
|
687
|
+
*
|
|
688
|
+
* // Or analyze custom candles
|
|
689
|
+
* const candles = await getCandles('ETHUSDT', '1h', 100);
|
|
690
|
+
* const rows = await service.getData('ETHUSDT', candles);
|
|
691
|
+
* console.log(rows[0].rsi14); // 52.45
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
declare class LongTermHistoryService {
|
|
695
|
+
private loggerService;
|
|
696
|
+
/**
|
|
697
|
+
* Analyzes candle data and returns technical indicator rows.
|
|
698
|
+
*
|
|
699
|
+
* Calculates all technical indicators for provided candles, skips first WARMUP_PERIOD
|
|
700
|
+
* rows to ensure stability, and returns last TABLE_ROWS_LIMIT rows.
|
|
701
|
+
*
|
|
702
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
703
|
+
* @param candles - Array of 1-hour candle data
|
|
704
|
+
* @returns Array of technical analysis rows with all indicators
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* const candles = await getCandles('BTCUSDT', '1h', 100);
|
|
709
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
710
|
+
* console.log(rows.length); // Up to 48 rows
|
|
711
|
+
* console.log(rows[0].rsi14); // 52.45
|
|
712
|
+
* console.log(rows[0].support); // 42000.50
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
getData: (symbol: string, candles: ICandleData[]) => Promise<ILongTermRow[]>;
|
|
716
|
+
/**
|
|
717
|
+
* Generates complete markdown technical analysis report for a symbol.
|
|
718
|
+
*
|
|
719
|
+
* Fetches 100 1-hour candles (100 hours) from exchange, calculates all indicators,
|
|
720
|
+
* and formats last 48 rows as markdown table optimized for LLM consumption.
|
|
721
|
+
*
|
|
722
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
723
|
+
* @returns Markdown-formatted technical analysis report with table and explanations
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```typescript
|
|
727
|
+
* const report = await service.getReport('BTCUSDT');
|
|
728
|
+
* console.log(report);
|
|
729
|
+
* // # 1-Hour Candles Trading Analysis for BTCUSDT (Historical Data)
|
|
730
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
731
|
+
* //
|
|
732
|
+
* // | RSI(14) | MACD(12,26,9) | Support Level | ...
|
|
733
|
+
* // | 52.45 | 0.0023 | 42000.50 USD | ...
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
getReport: (symbol: string) => Promise<string>;
|
|
737
|
+
/**
|
|
738
|
+
* Converts analysis rows into markdown table format.
|
|
739
|
+
*
|
|
740
|
+
* Takes pre-calculated indicator rows and formats them as markdown table
|
|
741
|
+
* with column headers, formatted values, and data source explanations.
|
|
742
|
+
*
|
|
743
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
744
|
+
* @param rows - Array of technical analysis rows from getData()
|
|
745
|
+
* @returns Markdown-formatted table with all indicators
|
|
746
|
+
*
|
|
747
|
+
* @example
|
|
748
|
+
* ```typescript
|
|
749
|
+
* const candles = await getCandles('BTCUSDT', '1h', 100);
|
|
750
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
751
|
+
* const markdown = await service.generateHistoryTable('BTCUSDT', rows);
|
|
752
|
+
* console.log(markdown); // Markdown table
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
generateHistoryTable: (symbol: string, rows: ILongTermRow[]) => Promise<string>;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
interface IShortTermRow {
|
|
759
|
+
symbol: string;
|
|
760
|
+
rsi9: number | null;
|
|
761
|
+
stochasticRSI9: number | null;
|
|
762
|
+
macd8_21_5: number | null;
|
|
763
|
+
signal5: number | null;
|
|
764
|
+
bollingerUpper10_2: number | null;
|
|
765
|
+
bollingerMiddle10_2: number | null;
|
|
766
|
+
bollingerLower10_2: number | null;
|
|
767
|
+
bollingerWidth10_2: number | null;
|
|
768
|
+
stochasticK5_3_3: number | null;
|
|
769
|
+
stochasticD5_3_3: number | null;
|
|
770
|
+
adx14: number | null;
|
|
771
|
+
plusDI14: number | null;
|
|
772
|
+
minusDI14: number | null;
|
|
773
|
+
atr9: number | null;
|
|
774
|
+
cci14: number | null;
|
|
775
|
+
sma50: number | null;
|
|
776
|
+
ema8: number | null;
|
|
777
|
+
ema21: number | null;
|
|
778
|
+
dema21: number | null;
|
|
779
|
+
wma20: number | null;
|
|
780
|
+
momentum8: number | null;
|
|
781
|
+
roc5: number | null;
|
|
782
|
+
roc10: number | null;
|
|
783
|
+
volumeTrend: string;
|
|
784
|
+
support: number;
|
|
785
|
+
resistance: number;
|
|
786
|
+
currentPrice: number;
|
|
787
|
+
fibonacciNearestLevel: string;
|
|
788
|
+
fibonacciNearestPrice: number;
|
|
789
|
+
fibonacciDistance: number;
|
|
790
|
+
bodySize: number;
|
|
791
|
+
closePrice: number;
|
|
792
|
+
date: Date;
|
|
793
|
+
lookbackPeriod: string;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Service for short-term (15-minute) technical analysis and markdown report generation.
|
|
797
|
+
*
|
|
798
|
+
* Provides comprehensive technical analysis for 15-minute candles with 30+ indicators
|
|
799
|
+
* including momentum (RSI, MACD), trend (EMA, SMA), volatility (ATR, Bollinger Bands),
|
|
800
|
+
* support/resistance levels, and Fibonacci retracements.
|
|
801
|
+
*
|
|
802
|
+
* Key features:
|
|
803
|
+
* - 30+ technical indicators (RSI, MACD, Bollinger Bands, Stochastic, ADX, etc.)
|
|
804
|
+
* - Support/resistance level detection
|
|
805
|
+
* - Fibonacci retracement analysis
|
|
806
|
+
* - Volume trend analysis
|
|
807
|
+
* - Markdown table generation for LLM consumption
|
|
808
|
+
* - Intelligent indicator warmup (skips first 50 candles)
|
|
809
|
+
* - Memory-efficient output (last 48 rows only)
|
|
810
|
+
* - Dependency injection support
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* import { ShortTermHistoryService } from '@backtest-kit/signals';
|
|
815
|
+
*
|
|
816
|
+
* const service = new ShortTermHistoryService();
|
|
817
|
+
*
|
|
818
|
+
* // Get markdown report for symbol (fetches candles internally)
|
|
819
|
+
* const report = await service.getReport('BTCUSDT');
|
|
820
|
+
* console.log(report); // Markdown table with all indicators
|
|
821
|
+
*
|
|
822
|
+
* // Or analyze custom candles
|
|
823
|
+
* const candles = await getCandles('ETHUSDT', '15m', 144);
|
|
824
|
+
* const rows = await service.getData('ETHUSDT', candles);
|
|
825
|
+
* console.log(rows[0].rsi9); // 45.23
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
declare class ShortTermHistoryService {
|
|
829
|
+
private loggerService;
|
|
830
|
+
/**
|
|
831
|
+
* Analyzes candle data and returns technical indicator rows.
|
|
832
|
+
*
|
|
833
|
+
* Calculates all technical indicators for provided candles, skips first WARMUP_PERIOD
|
|
834
|
+
* rows to ensure stability, and returns last TABLE_ROWS_LIMIT rows.
|
|
835
|
+
*
|
|
836
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
837
|
+
* @param candles - Array of 15-minute candle data
|
|
838
|
+
* @returns Array of technical analysis rows with all indicators
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* const candles = await getCandles('BTCUSDT', '15m', 144);
|
|
843
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
844
|
+
* console.log(rows.length); // Up to 48 rows
|
|
845
|
+
* console.log(rows[0].rsi9); // 45.23
|
|
846
|
+
* console.log(rows[0].support); // 42000.50
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
getData: (symbol: string, candles: ICandleData[]) => Promise<IShortTermRow[]>;
|
|
850
|
+
/**
|
|
851
|
+
* Generates complete markdown technical analysis report for a symbol.
|
|
852
|
+
*
|
|
853
|
+
* Fetches 144 15-minute candles (36 hours) from exchange, calculates all indicators,
|
|
854
|
+
* and formats results as markdown table optimized for LLM consumption.
|
|
855
|
+
*
|
|
856
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
857
|
+
* @returns Markdown-formatted technical analysis report with table and explanations
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```typescript
|
|
861
|
+
* const report = await service.getReport('BTCUSDT');
|
|
862
|
+
* console.log(report);
|
|
863
|
+
* // # 15-Minute Candles Trading Analysis for BTCUSDT (Historical Data)
|
|
864
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
865
|
+
* //
|
|
866
|
+
* // | RSI(9) | MACD(8,21,5) | Support Level | ...
|
|
867
|
+
* // | 45.23 | 0.0012 | 42000.50 USD | ...
|
|
868
|
+
* ```
|
|
869
|
+
*/
|
|
870
|
+
getReport: (symbol: string) => Promise<string>;
|
|
871
|
+
/**
|
|
872
|
+
* Converts analysis rows into markdown table format.
|
|
873
|
+
*
|
|
874
|
+
* Takes pre-calculated indicator rows and formats them as markdown table
|
|
875
|
+
* with column headers, formatted values, and data source explanations.
|
|
876
|
+
*
|
|
877
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
878
|
+
* @param rows - Array of technical analysis rows from getData()
|
|
879
|
+
* @returns Markdown-formatted table with all indicators
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```typescript
|
|
883
|
+
* const candles = await getCandles('BTCUSDT', '15m', 144);
|
|
884
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
885
|
+
* const markdown = await service.generateHistoryTable('BTCUSDT', rows);
|
|
886
|
+
* console.log(markdown); // Markdown table
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
generateHistoryTable: (symbol: string, rows: IShortTermRow[]) => Promise<string>;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* MicroTerm (1-minute) technical analysis service for scalping strategies.
|
|
894
|
+
*
|
|
895
|
+
* Generates 40+ indicators on 1-minute candles with 60-candle lookback.
|
|
896
|
+
* Optimized for high-frequency trading and sub-5 minute positions.
|
|
897
|
+
*
|
|
898
|
+
* Indicators: RSI(9,14), StochRSI(9,14), MACD(8,21,5), Bollinger(8,2), Stochastic(3,5),
|
|
899
|
+
* ADX(9), ATR(5,9), CCI(9), Momentum(5,10), ROC(1,3,5), EMA(3,8,13,21), SMA(8), DEMA(8),
|
|
900
|
+
* WMA(5), Support/Resistance, Volume analysis, Squeeze momentum.
|
|
901
|
+
*
|
|
902
|
+
* Used by commitMicroTermMath().
|
|
903
|
+
*/
|
|
904
|
+
|
|
905
|
+
interface IMicroTermRow {
|
|
906
|
+
symbol: string;
|
|
907
|
+
rsi9: number | null;
|
|
908
|
+
rsi14: number | null;
|
|
909
|
+
stochasticRSI9: number | null;
|
|
910
|
+
stochasticRSI14: number | null;
|
|
911
|
+
macd8_21_5: number | null;
|
|
912
|
+
signal5: number | null;
|
|
913
|
+
macdHistogram: number | null;
|
|
914
|
+
bollingerUpper8_2: number | null;
|
|
915
|
+
bollingerMiddle8_2: number | null;
|
|
916
|
+
bollingerLower8_2: number | null;
|
|
917
|
+
bollingerWidth8_2: number | null;
|
|
918
|
+
bollingerPosition: number | null;
|
|
919
|
+
stochasticK3_3_3: number | null;
|
|
920
|
+
stochasticD3_3_3: number | null;
|
|
921
|
+
stochasticK5_3_3: number | null;
|
|
922
|
+
stochasticD5_3_3: number | null;
|
|
923
|
+
adx9: number | null;
|
|
924
|
+
plusDI9: number | null;
|
|
925
|
+
minusDI9: number | null;
|
|
926
|
+
atr5: number | null;
|
|
927
|
+
atr9: number | null;
|
|
928
|
+
cci9: number | null;
|
|
929
|
+
momentum5: number | null;
|
|
930
|
+
momentum10: number | null;
|
|
931
|
+
roc1: number | null;
|
|
932
|
+
roc3: number | null;
|
|
933
|
+
roc5: number | null;
|
|
934
|
+
ema3: number | null;
|
|
935
|
+
ema8: number | null;
|
|
936
|
+
ema13: number | null;
|
|
937
|
+
ema21: number | null;
|
|
938
|
+
sma8: number | null;
|
|
939
|
+
dema8: number | null;
|
|
940
|
+
wma5: number | null;
|
|
941
|
+
volumeSma5: number | null;
|
|
942
|
+
volumeRatio: number | null;
|
|
943
|
+
volumeTrend: string;
|
|
944
|
+
currentPrice: number;
|
|
945
|
+
priceChange1m: number | null;
|
|
946
|
+
priceChange3m: number | null;
|
|
947
|
+
priceChange5m: number | null;
|
|
948
|
+
volatility5: number | null;
|
|
949
|
+
trueRange: number | null;
|
|
950
|
+
support: number;
|
|
951
|
+
resistance: number;
|
|
952
|
+
squeezeMomentum: number | null;
|
|
953
|
+
pressureIndex: number | null;
|
|
954
|
+
closePrice: number;
|
|
955
|
+
date: Date;
|
|
956
|
+
lookbackPeriod: string;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Service for micro-term (1-minute) technical analysis and markdown report generation.
|
|
960
|
+
*
|
|
961
|
+
* Provides comprehensive technical analysis for 1-minute candles with 40+ indicators
|
|
962
|
+
* including momentum (RSI, MACD), trend (EMA, SMA), volatility (ATR, Bollinger Bands),
|
|
963
|
+
* support/resistance levels, volume analysis, and specialized scalping indicators.
|
|
964
|
+
*
|
|
965
|
+
* Key features:
|
|
966
|
+
* - 40+ technical indicators (RSI, MACD, Bollinger Bands, Stochastic, ADX, etc.)
|
|
967
|
+
* - Support/resistance level detection (30-candle lookback)
|
|
968
|
+
* - Volume analysis (SMA, ratio, trend)
|
|
969
|
+
* - Price change tracking (1m, 3m, 5m)
|
|
970
|
+
* - Specialized scalping indicators (squeeze momentum, pressure index, Bollinger position)
|
|
971
|
+
* - Volatility and true range calculations
|
|
972
|
+
* - Markdown table generation for LLM consumption
|
|
973
|
+
* - Intelligent indicator warmup (skips first 21 candles)
|
|
974
|
+
* - Memory-efficient output (last 40 rows only)
|
|
975
|
+
* - Dependency injection support
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
978
|
+
* ```typescript
|
|
979
|
+
* import { MicroTermHistoryService } from '@backtest-kit/signals';
|
|
980
|
+
*
|
|
981
|
+
* const service = new MicroTermHistoryService();
|
|
982
|
+
*
|
|
983
|
+
* // Get markdown report for symbol (fetches candles internally)
|
|
984
|
+
* const report = await service.getReport('BTCUSDT');
|
|
985
|
+
* console.log(report); // Markdown table with all indicators
|
|
986
|
+
*
|
|
987
|
+
* // Or analyze custom candles
|
|
988
|
+
* const candles = await getCandles('ETHUSDT', '1m', 60);
|
|
989
|
+
* const rows = await service.getData('ETHUSDT', candles);
|
|
990
|
+
* console.log(rows[0].rsi9); // 45.23
|
|
991
|
+
* console.log(rows[0].squeezeMomentum); // 1.25
|
|
992
|
+
* ```
|
|
993
|
+
*/
|
|
994
|
+
declare class MicroTermHistoryService {
|
|
995
|
+
private loggerService;
|
|
996
|
+
/**
|
|
997
|
+
* Analyzes candle data and returns technical indicator rows.
|
|
998
|
+
*
|
|
999
|
+
* Calculates all technical indicators for provided candles, skips first WARMUP_PERIOD
|
|
1000
|
+
* rows to ensure stability, and returns last TABLE_ROWS_LIMIT rows.
|
|
1001
|
+
*
|
|
1002
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1003
|
+
* @param candles - Array of 1-minute candle data
|
|
1004
|
+
* @returns Array of technical analysis rows with all indicators
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```typescript
|
|
1008
|
+
* const candles = await getCandles('BTCUSDT', '1m', 60);
|
|
1009
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
1010
|
+
* console.log(rows.length); // Up to 40 rows
|
|
1011
|
+
* console.log(rows[0].rsi9); // 45.23
|
|
1012
|
+
* console.log(rows[0].volumeRatio); // 1.25
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
getData: (symbol: string, candles: ICandleData[]) => Promise<IMicroTermRow[]>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Generates complete markdown technical analysis report for a symbol.
|
|
1018
|
+
*
|
|
1019
|
+
* Fetches 60 1-minute candles (60 minutes) from exchange, calculates all indicators,
|
|
1020
|
+
* and formats results as markdown table optimized for LLM consumption.
|
|
1021
|
+
*
|
|
1022
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1023
|
+
* @returns Markdown-formatted technical analysis report with table and explanations
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```typescript
|
|
1027
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1028
|
+
* console.log(report);
|
|
1029
|
+
* // # 1-Minute Candles Trading Analysis for BTCUSDT (Historical Data)
|
|
1030
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1031
|
+
* //
|
|
1032
|
+
* // | RSI(9) | MACD(8,21,5) | Squeeze Momentum | ...
|
|
1033
|
+
* // | 45.23 | 0.0012 | 1.25 | ...
|
|
1034
|
+
* ```
|
|
1035
|
+
*/
|
|
1036
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Converts analysis rows into markdown table format.
|
|
1039
|
+
*
|
|
1040
|
+
* Takes pre-calculated indicator rows and formats them as markdown table
|
|
1041
|
+
* with column headers, formatted values, and data source explanations.
|
|
1042
|
+
*
|
|
1043
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
1044
|
+
* @param rows - Array of technical analysis rows from getData()
|
|
1045
|
+
* @returns Markdown-formatted table with all indicators
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```typescript
|
|
1049
|
+
* const candles = await getCandles('BTCUSDT', '1m', 60);
|
|
1050
|
+
* const rows = await service.getData('BTCUSDT', candles);
|
|
1051
|
+
* const markdown = await service.generateHistoryTable('BTCUSDT', rows);
|
|
1052
|
+
* console.log(markdown); // Markdown table
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
generateHistoryTable: (symbol: string, rows: IMicroTermRow[]) => Promise<string>;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* Fifteen-minute candle history service for day trading analysis.
|
|
1060
|
+
*
|
|
1061
|
+
* Generates markdown reports of the last 8 fifteen-minute candles including:
|
|
1062
|
+
* - OHLCV data with high-volatility detection
|
|
1063
|
+
* - Candle type (Green/Red/Doji)
|
|
1064
|
+
* - Volatility percentage (flagged if >1.5x average)
|
|
1065
|
+
* - Body size percentage
|
|
1066
|
+
* - Timestamp
|
|
1067
|
+
*
|
|
1068
|
+
* Used by commitFifteenMinuteHistory() for LLM context injection.
|
|
1069
|
+
*/
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* Service for generating 15-minute candle history reports for day trading analysis.
|
|
1073
|
+
*
|
|
1074
|
+
* Provides detailed OHLCV analysis for the last 8 fifteen-minute candles with
|
|
1075
|
+
* candle pattern identification, volatility metrics, high-volatility detection,
|
|
1076
|
+
* and body size calculations.
|
|
1077
|
+
*
|
|
1078
|
+
* Key features:
|
|
1079
|
+
* - Last 8 fifteen-minute candles (2 hours of price action)
|
|
1080
|
+
* - OHLCV data with formatted prices and volumes
|
|
1081
|
+
* - Candle type identification (Green/Red/Doji)
|
|
1082
|
+
* - Volatility percentage calculations
|
|
1083
|
+
* - High-volatility detection (>1.5x average volatility)
|
|
1084
|
+
* - Body size percentage relative to candle range
|
|
1085
|
+
* - ISO timestamp formatting
|
|
1086
|
+
* - Dependency injection support
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* import { FifteenMinuteCandleHistoryService } from '@backtest-kit/signals';
|
|
1091
|
+
*
|
|
1092
|
+
* const service = new FifteenMinuteCandleHistoryService();
|
|
1093
|
+
*
|
|
1094
|
+
* // Get markdown report
|
|
1095
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1096
|
+
* console.log(report);
|
|
1097
|
+
* // ## 15-Minute Candles History (Last 8)
|
|
1098
|
+
* // ### 15m Candle 1 (Green) HIGH-VOLATILITY
|
|
1099
|
+
* // - **Open**: 42000.50 USD
|
|
1100
|
+
* // - **15m Volatility**: 0.85%
|
|
1101
|
+
*
|
|
1102
|
+
* // Or get raw candle data
|
|
1103
|
+
* const candles = await service.getData('ETHUSDT');
|
|
1104
|
+
* console.log(candles.length); // 8
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
declare class FifteenMinuteCandleHistoryService {
|
|
1108
|
+
private loggerService;
|
|
1109
|
+
/**
|
|
1110
|
+
* Fetches last 8 fifteen-minute candles for a symbol.
|
|
1111
|
+
*
|
|
1112
|
+
* Retrieves recent 15-minute candles from exchange for day trading analysis.
|
|
1113
|
+
*
|
|
1114
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1115
|
+
* @returns Array of 8 fifteen-minute candles
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```typescript
|
|
1119
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1120
|
+
* console.log(candles.length); // 8
|
|
1121
|
+
* console.log(candles[0].close); // Latest candle close price
|
|
1122
|
+
* ```
|
|
1123
|
+
*/
|
|
1124
|
+
getData: (symbol: string) => Promise<ICandleData[]>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Generates markdown report from candle data with volatility detection.
|
|
1127
|
+
*
|
|
1128
|
+
* Creates detailed markdown report with OHLCV data, candle patterns,
|
|
1129
|
+
* volatility metrics, and HIGH-VOLATILITY flags for candles exceeding
|
|
1130
|
+
* 1.5x the average volatility of all candles.
|
|
1131
|
+
*
|
|
1132
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
1133
|
+
* @param candles - Array of candle data to analyze
|
|
1134
|
+
* @returns Markdown-formatted candle history report with volatility flags
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1139
|
+
* const report = await service.generateReport('BTCUSDT', candles);
|
|
1140
|
+
* console.log(report);
|
|
1141
|
+
* // ## 15-Minute Candles History (Last 8)
|
|
1142
|
+
* // ### 15m Candle 1 (Green) HIGH-VOLATILITY
|
|
1143
|
+
* // - **Open**: 42000.50 USD
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
generateReport: (symbol: string, candles: ICandleData[]) => Promise<string>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Generates complete markdown candle history report for a symbol.
|
|
1149
|
+
*
|
|
1150
|
+
* Fetches last 8 fifteen-minute candles and formats them as markdown report
|
|
1151
|
+
* with OHLCV data, patterns, volatility flags, and metrics.
|
|
1152
|
+
*
|
|
1153
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1154
|
+
* @returns Markdown-formatted candle history report with high-volatility detection
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```typescript
|
|
1158
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1159
|
+
* console.log(report);
|
|
1160
|
+
* // ## 15-Minute Candles History (Last 8)
|
|
1161
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1162
|
+
* //
|
|
1163
|
+
* // ### 15m Candle 1 (Green) HIGH-VOLATILITY
|
|
1164
|
+
* // - **Time**: 2025-01-14T10:15:00.000Z
|
|
1165
|
+
* // - **Open**: 42000.50 USD
|
|
1166
|
+
* // - **15m Volatility**: 0.85%
|
|
1167
|
+
* ```
|
|
1168
|
+
*/
|
|
1169
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Hourly candle history service for trend analysis.
|
|
1174
|
+
*
|
|
1175
|
+
* Generates markdown reports of the last 6 hourly candles including:
|
|
1176
|
+
* - OHLCV data
|
|
1177
|
+
* - Candle type (Green/Red/Doji)
|
|
1178
|
+
* - Volatility percentage
|
|
1179
|
+
* - Body size percentage
|
|
1180
|
+
* - Timestamp
|
|
1181
|
+
*
|
|
1182
|
+
* Used by commitHourHistory() for LLM context injection.
|
|
1183
|
+
*/
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* Service for generating 1-hour candle history reports for trend analysis.
|
|
1187
|
+
*
|
|
1188
|
+
* Provides detailed OHLCV analysis for the last 6 hourly candles with
|
|
1189
|
+
* candle pattern identification, volatility metrics, and body size calculations.
|
|
1190
|
+
*
|
|
1191
|
+
* Key features:
|
|
1192
|
+
* - Last 6 hourly candles (6 hours of price action)
|
|
1193
|
+
* - OHLCV data with formatted prices and volumes
|
|
1194
|
+
* - Candle type identification (Green/Red/Doji)
|
|
1195
|
+
* - Volatility percentage calculations
|
|
1196
|
+
* - Body size percentage relative to candle range
|
|
1197
|
+
* - ISO timestamp formatting
|
|
1198
|
+
* - Dependency injection support
|
|
1199
|
+
*
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```typescript
|
|
1202
|
+
* import { HourCandleHistoryService } from '@backtest-kit/signals';
|
|
1203
|
+
*
|
|
1204
|
+
* const service = new HourCandleHistoryService();
|
|
1205
|
+
*
|
|
1206
|
+
* // Get markdown report
|
|
1207
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1208
|
+
* console.log(report);
|
|
1209
|
+
* // ## Hourly Candles History (Last 6)
|
|
1210
|
+
* // ### 1h Candle 1 (Green)
|
|
1211
|
+
* // - **Open**: 42000.50 USD
|
|
1212
|
+
* // - **1h Volatility**: 2.15%
|
|
1213
|
+
*
|
|
1214
|
+
* // Or get raw candle data
|
|
1215
|
+
* const candles = await service.getData('ETHUSDT');
|
|
1216
|
+
* console.log(candles.length); // 6
|
|
1217
|
+
* ```
|
|
1218
|
+
*/
|
|
1219
|
+
declare class HourCandleHistoryService {
|
|
1220
|
+
private loggerService;
|
|
1221
|
+
/**
|
|
1222
|
+
* Fetches last 6 hourly candles for a symbol.
|
|
1223
|
+
*
|
|
1224
|
+
* Retrieves recent 1-hour candles from exchange for trend analysis.
|
|
1225
|
+
*
|
|
1226
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1227
|
+
* @returns Array of 6 hourly candles
|
|
1228
|
+
*
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1232
|
+
* console.log(candles.length); // 6
|
|
1233
|
+
* console.log(candles[0].close); // Latest candle close price
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
getData: (symbol: string) => Promise<ICandleData[]>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Generates markdown report from candle data.
|
|
1239
|
+
*
|
|
1240
|
+
* Creates detailed markdown report with OHLCV data, candle patterns,
|
|
1241
|
+
* volatility metrics, and body size percentages for each candle.
|
|
1242
|
+
*
|
|
1243
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
1244
|
+
* @param candles - Array of candle data to analyze
|
|
1245
|
+
* @returns Markdown-formatted candle history report
|
|
1246
|
+
*
|
|
1247
|
+
* @example
|
|
1248
|
+
* ```typescript
|
|
1249
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1250
|
+
* const report = await service.generateReport('BTCUSDT', candles);
|
|
1251
|
+
* console.log(report);
|
|
1252
|
+
* // ## Hourly Candles History (Last 6)
|
|
1253
|
+
* // ### 1h Candle 1 (Green)
|
|
1254
|
+
* // - **Open**: 42000.50 USD
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
generateReport: (symbol: string, candles: ICandleData[]) => Promise<string>;
|
|
1258
|
+
/**
|
|
1259
|
+
* Generates complete markdown candle history report for a symbol.
|
|
1260
|
+
*
|
|
1261
|
+
* Fetches last 6 hourly candles and formats them as markdown report
|
|
1262
|
+
* with OHLCV data, patterns, and metrics.
|
|
1263
|
+
*
|
|
1264
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1265
|
+
* @returns Markdown-formatted candle history report
|
|
1266
|
+
*
|
|
1267
|
+
* @example
|
|
1268
|
+
* ```typescript
|
|
1269
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1270
|
+
* console.log(report);
|
|
1271
|
+
* // ## Hourly Candles History (Last 6)
|
|
1272
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1273
|
+
* //
|
|
1274
|
+
* // ### 1h Candle 1 (Green)
|
|
1275
|
+
* // - **Time**: 2025-01-14T10:00:00.000Z
|
|
1276
|
+
* // - **Open**: 42000.50 USD
|
|
1277
|
+
* // - **1h Volatility**: 2.15%
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* One-minute candle history service for ultra-short term analysis.
|
|
1285
|
+
*
|
|
1286
|
+
* Generates markdown reports of the last 15 one-minute candles including:
|
|
1287
|
+
* - OHLCV data (Open, High, Low, Close, Volume)
|
|
1288
|
+
* - Candle type (Green/Red/Doji)
|
|
1289
|
+
* - Volatility percentage
|
|
1290
|
+
* - Body size percentage
|
|
1291
|
+
* - Timestamp
|
|
1292
|
+
*
|
|
1293
|
+
* Used by commitOneMinuteHistory() for LLM context injection.
|
|
1294
|
+
*/
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Service for generating 1-minute candle history reports for scalping analysis.
|
|
1298
|
+
*
|
|
1299
|
+
* Provides detailed OHLCV analysis for the last 15 one-minute candles with
|
|
1300
|
+
* candle pattern identification, volatility metrics, and body size calculations.
|
|
1301
|
+
*
|
|
1302
|
+
* Key features:
|
|
1303
|
+
* - Last 15 one-minute candles (15 minutes of price action)
|
|
1304
|
+
* - OHLCV data with formatted prices and volumes
|
|
1305
|
+
* - Candle type identification (Green/Red/Doji)
|
|
1306
|
+
* - Volatility percentage calculations
|
|
1307
|
+
* - Body size percentage relative to candle range
|
|
1308
|
+
* - ISO timestamp formatting
|
|
1309
|
+
* - Dependency injection support
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* import { OneMinuteCandleHistoryService } from '@backtest-kit/signals';
|
|
1314
|
+
*
|
|
1315
|
+
* const service = new OneMinuteCandleHistoryService();
|
|
1316
|
+
*
|
|
1317
|
+
* // Get markdown report
|
|
1318
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1319
|
+
* console.log(report);
|
|
1320
|
+
* // ## One-Minute Candles History (Last 15)
|
|
1321
|
+
* // ### 1m Candle 1 (Green)
|
|
1322
|
+
* // - **Open**: 42000.50 USD
|
|
1323
|
+
* // - **1m Volatility**: 0.15%
|
|
1324
|
+
*
|
|
1325
|
+
* // Or get raw candle data
|
|
1326
|
+
* const candles = await service.getData('ETHUSDT');
|
|
1327
|
+
* console.log(candles.length); // 15
|
|
1328
|
+
* ```
|
|
1329
|
+
*/
|
|
1330
|
+
declare class OneMinuteCandleHistoryService {
|
|
1331
|
+
private loggerService;
|
|
1332
|
+
/**
|
|
1333
|
+
* Fetches last 15 one-minute candles for a symbol.
|
|
1334
|
+
*
|
|
1335
|
+
* Retrieves recent 1-minute candles from exchange for scalping analysis.
|
|
1336
|
+
*
|
|
1337
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1338
|
+
* @returns Array of 15 one-minute candles
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```typescript
|
|
1342
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1343
|
+
* console.log(candles.length); // 15
|
|
1344
|
+
* console.log(candles[0].close); // Latest candle close price
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
getData: (symbol: string) => Promise<ICandleData[]>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Generates markdown report from candle data.
|
|
1350
|
+
*
|
|
1351
|
+
* Creates detailed markdown report with OHLCV data, candle patterns,
|
|
1352
|
+
* volatility metrics, and body size percentages for each candle.
|
|
1353
|
+
*
|
|
1354
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
1355
|
+
* @param candles - Array of candle data to analyze
|
|
1356
|
+
* @returns Markdown-formatted candle history report
|
|
1357
|
+
*
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```typescript
|
|
1360
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1361
|
+
* const report = await service.generateReport('BTCUSDT', candles);
|
|
1362
|
+
* console.log(report);
|
|
1363
|
+
* // ## One-Minute Candles History (Last 15)
|
|
1364
|
+
* // ### 1m Candle 1 (Green)
|
|
1365
|
+
* // - **Open**: 42000.50 USD
|
|
1366
|
+
* ```
|
|
1367
|
+
*/
|
|
1368
|
+
generateReport: (symbol: string, candles: ICandleData[]) => Promise<string>;
|
|
1369
|
+
/**
|
|
1370
|
+
* Generates complete markdown candle history report for a symbol.
|
|
1371
|
+
*
|
|
1372
|
+
* Fetches last 15 one-minute candles and formats them as markdown report
|
|
1373
|
+
* with OHLCV data, patterns, and metrics.
|
|
1374
|
+
*
|
|
1375
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1376
|
+
* @returns Markdown-formatted candle history report
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* ```typescript
|
|
1380
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1381
|
+
* console.log(report);
|
|
1382
|
+
* // ## One-Minute Candles History (Last 15)
|
|
1383
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1384
|
+
* //
|
|
1385
|
+
* // ### 1m Candle 1 (Green)
|
|
1386
|
+
* // - **Time**: 2025-01-14T10:29:00.000Z
|
|
1387
|
+
* // - **Open**: 42000.50 USD
|
|
1388
|
+
* // - **1m Volatility**: 0.15%
|
|
1389
|
+
* ```
|
|
1390
|
+
*/
|
|
1391
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* Thirty-minute candle history service for swing trading analysis.
|
|
1396
|
+
*
|
|
1397
|
+
* Generates markdown reports of the last 6 thirty-minute candles including:
|
|
1398
|
+
* - OHLCV data
|
|
1399
|
+
* - Candle type (Green/Red/Doji)
|
|
1400
|
+
* - Volatility percentage
|
|
1401
|
+
* - Body size percentage
|
|
1402
|
+
* - Timestamp
|
|
1403
|
+
*
|
|
1404
|
+
* Used by commitThirtyMinuteHistory() for LLM context injection.
|
|
1405
|
+
*/
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* Service for generating 30-minute candle history reports for swing trading analysis.
|
|
1409
|
+
*
|
|
1410
|
+
* Provides detailed OHLCV analysis for the last 6 thirty-minute candles with
|
|
1411
|
+
* candle pattern identification, volatility metrics, and body size calculations.
|
|
1412
|
+
*
|
|
1413
|
+
* Key features:
|
|
1414
|
+
* - Last 6 thirty-minute candles (3 hours of price action)
|
|
1415
|
+
* - OHLCV data with formatted prices and volumes
|
|
1416
|
+
* - Candle type identification (Green/Red/Doji)
|
|
1417
|
+
* - Volatility percentage calculations
|
|
1418
|
+
* - Body size percentage relative to candle range
|
|
1419
|
+
* - ISO timestamp formatting
|
|
1420
|
+
* - Dependency injection support
|
|
1421
|
+
*
|
|
1422
|
+
* @example
|
|
1423
|
+
* ```typescript
|
|
1424
|
+
* import { ThirtyMinuteCandleHistoryService } from '@backtest-kit/signals';
|
|
1425
|
+
*
|
|
1426
|
+
* const service = new ThirtyMinuteCandleHistoryService();
|
|
1427
|
+
*
|
|
1428
|
+
* // Get markdown report
|
|
1429
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1430
|
+
* console.log(report);
|
|
1431
|
+
* // ## 30-Min Candles History (Last 6)
|
|
1432
|
+
* // ### 30m Candle 1 (Green)
|
|
1433
|
+
* // - **Open**: 42000.50 USD
|
|
1434
|
+
* // - **30m Volatility**: 1.25%
|
|
1435
|
+
*
|
|
1436
|
+
* // Or get raw candle data
|
|
1437
|
+
* const candles = await service.getData('ETHUSDT');
|
|
1438
|
+
* console.log(candles.length); // 6
|
|
1439
|
+
* ```
|
|
1440
|
+
*/
|
|
1441
|
+
declare class ThirtyMinuteCandleHistoryService {
|
|
1442
|
+
private loggerService;
|
|
1443
|
+
/**
|
|
1444
|
+
* Fetches last 6 thirty-minute candles for a symbol.
|
|
1445
|
+
*
|
|
1446
|
+
* Retrieves recent 30-minute candles from exchange for analysis.
|
|
1447
|
+
*
|
|
1448
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1449
|
+
* @returns Array of 6 thirty-minute candles
|
|
1450
|
+
*
|
|
1451
|
+
* @example
|
|
1452
|
+
* ```typescript
|
|
1453
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1454
|
+
* console.log(candles.length); // 6
|
|
1455
|
+
* console.log(candles[0].close); // Latest candle close price
|
|
1456
|
+
* ```
|
|
1457
|
+
*/
|
|
1458
|
+
getData: (symbol: string) => Promise<ICandleData[]>;
|
|
1459
|
+
/**
|
|
1460
|
+
* Generates markdown report from candle data.
|
|
1461
|
+
*
|
|
1462
|
+
* Creates detailed markdown report with OHLCV data, candle patterns,
|
|
1463
|
+
* volatility metrics, and body size percentages for each candle.
|
|
1464
|
+
*
|
|
1465
|
+
* @param symbol - Trading pair symbol for price formatting
|
|
1466
|
+
* @param candles - Array of candle data to analyze
|
|
1467
|
+
* @returns Markdown-formatted candle history report
|
|
1468
|
+
*
|
|
1469
|
+
* @example
|
|
1470
|
+
* ```typescript
|
|
1471
|
+
* const candles = await service.getData('BTCUSDT');
|
|
1472
|
+
* const report = await service.generateReport('BTCUSDT', candles);
|
|
1473
|
+
* console.log(report);
|
|
1474
|
+
* // ## 30-Min Candles History (Last 6)
|
|
1475
|
+
* // ### 30m Candle 1 (Green)
|
|
1476
|
+
* // - **Open**: 42000.50 USD
|
|
1477
|
+
* ```
|
|
1478
|
+
*/
|
|
1479
|
+
generateReport: (symbol: string, candles: ICandleData[]) => Promise<string>;
|
|
1480
|
+
/**
|
|
1481
|
+
* Generates complete markdown candle history report for a symbol.
|
|
1482
|
+
*
|
|
1483
|
+
* Fetches last 6 thirty-minute candles and formats them as markdown report
|
|
1484
|
+
* with OHLCV data, patterns, and metrics.
|
|
1485
|
+
*
|
|
1486
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1487
|
+
* @returns Markdown-formatted candle history report
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* ```typescript
|
|
1491
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1492
|
+
* console.log(report);
|
|
1493
|
+
* // ## 30-Min Candles History (Last 6)
|
|
1494
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1495
|
+
* //
|
|
1496
|
+
* // ### 30m Candle 1 (Green)
|
|
1497
|
+
* // - **Time**: 2025-01-14T10:00:00.000Z
|
|
1498
|
+
* // - **Open**: 42000.50 USD
|
|
1499
|
+
* // - **30m Volatility**: 1.25%
|
|
1500
|
+
* ```
|
|
1501
|
+
*/
|
|
1502
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
/**
|
|
1506
|
+
* Order book analysis service for real-time market depth and liquidity assessment.
|
|
1507
|
+
*
|
|
1508
|
+
* Generates comprehensive order book reports including:
|
|
1509
|
+
* - Top 20 bid/ask levels sorted by volume percentage
|
|
1510
|
+
* - Best bid/ask prices
|
|
1511
|
+
* - Mid price and spread
|
|
1512
|
+
* - Depth imbalance (buy vs sell pressure indicator)
|
|
1513
|
+
*
|
|
1514
|
+
* Depth Imbalance Formula:
|
|
1515
|
+
* (Total Bid Volume - Total Ask Volume) / (Total Bid Volume + Total Ask Volume)
|
|
1516
|
+
* - Positive: Buy pressure (more bids)
|
|
1517
|
+
* - Negative: Sell pressure (more asks)
|
|
1518
|
+
* - Zero: Balanced market
|
|
1519
|
+
*
|
|
1520
|
+
* Used by commitBookDataReport() for LLM context injection.
|
|
1521
|
+
* Only available in live mode (skipped in backtest mode).
|
|
1522
|
+
*/
|
|
1523
|
+
/**
|
|
1524
|
+
* Order book entry with volume percentage.
|
|
1525
|
+
*/
|
|
1526
|
+
interface IOrderBookEntry {
|
|
1527
|
+
/** Price level */
|
|
1528
|
+
price: number;
|
|
1529
|
+
/** Total quantity at this price */
|
|
1530
|
+
quantity: number;
|
|
1531
|
+
/** Percentage of total side volume */
|
|
1532
|
+
percentage: number;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Complete order book analysis result.
|
|
1536
|
+
*/
|
|
1537
|
+
interface IBookDataAnalysis {
|
|
1538
|
+
/** Trading pair symbol */
|
|
1539
|
+
symbol: string;
|
|
1540
|
+
/** Analysis timestamp */
|
|
1541
|
+
timestamp: string;
|
|
1542
|
+
/** Bid (buy) levels with percentages */
|
|
1543
|
+
bids: IOrderBookEntry[];
|
|
1544
|
+
/** Ask (sell) levels with percentages */
|
|
1545
|
+
asks: IOrderBookEntry[];
|
|
1546
|
+
/** Highest bid price */
|
|
1547
|
+
bestBid: number;
|
|
1548
|
+
/** Lowest ask price */
|
|
1549
|
+
bestAsk: number;
|
|
1550
|
+
/** Mid price: (bestBid + bestAsk) / 2 */
|
|
1551
|
+
midPrice: number;
|
|
1552
|
+
/** Spread: bestAsk - bestBid */
|
|
1553
|
+
spread: number;
|
|
1554
|
+
/** Depth imbalance: (bidVol - askVol) / (bidVol + askVol) */
|
|
1555
|
+
depthImbalance: number;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Service for order book analysis and markdown report generation.
|
|
1559
|
+
*
|
|
1560
|
+
* Provides real-time order book depth analysis with market liquidity metrics
|
|
1561
|
+
* including bid/ask levels, depth imbalance, spread, and volume distribution.
|
|
1562
|
+
*
|
|
1563
|
+
* Key features:
|
|
1564
|
+
* - Fetches up to 1000 order book depth levels
|
|
1565
|
+
* - Calculates best bid/ask, mid price, and spread
|
|
1566
|
+
* - Computes depth imbalance (buy vs sell pressure)
|
|
1567
|
+
* - Analyzes volume distribution with percentage calculations
|
|
1568
|
+
* - Generates markdown reports with top 20 levels
|
|
1569
|
+
* - Only available in live mode (skipped in backtest)
|
|
1570
|
+
* - Dependency injection support
|
|
1571
|
+
*
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```typescript
|
|
1574
|
+
* import { BookDataMathService } from '@backtest-kit/signals';
|
|
1575
|
+
*
|
|
1576
|
+
* const service = new BookDataMathService();
|
|
1577
|
+
*
|
|
1578
|
+
* // Get markdown report (fetches order book internally)
|
|
1579
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1580
|
+
* console.log(report); // Markdown with top 20 bid/ask levels
|
|
1581
|
+
*
|
|
1582
|
+
* // Or analyze custom order book data
|
|
1583
|
+
* const analysis = await service.getData('ETHUSDT');
|
|
1584
|
+
* console.log(analysis.depthImbalance); // 0.125 (12.5% buy pressure)
|
|
1585
|
+
* console.log(analysis.bestBid); // 2300.50
|
|
1586
|
+
* ```
|
|
1587
|
+
*/
|
|
1588
|
+
declare class BookDataMathService {
|
|
1589
|
+
private loggerService;
|
|
1590
|
+
/**
|
|
1591
|
+
* Converts order book analysis into markdown report format.
|
|
1592
|
+
*
|
|
1593
|
+
* Takes pre-calculated order book analysis and formats it as markdown
|
|
1594
|
+
* with summary metrics and top 20 bid/ask levels sorted by volume.
|
|
1595
|
+
*
|
|
1596
|
+
* @param symbol - Trading pair symbol for header
|
|
1597
|
+
* @param bookData - Order book analysis from getData()
|
|
1598
|
+
* @returns Markdown-formatted order book report
|
|
1599
|
+
*
|
|
1600
|
+
* @example
|
|
1601
|
+
* ```typescript
|
|
1602
|
+
* const analysis = await service.getData('BTCUSDT');
|
|
1603
|
+
* const report = await service.generateReport('BTCUSDT', analysis);
|
|
1604
|
+
* console.log(report); // Markdown table with order book data
|
|
1605
|
+
* ```
|
|
1606
|
+
*/
|
|
1607
|
+
generateReport: (symbol: string, bookData: IBookDataAnalysis) => Promise<string>;
|
|
1608
|
+
/**
|
|
1609
|
+
* Generates complete markdown order book report for a symbol.
|
|
1610
|
+
*
|
|
1611
|
+
* Fetches order book depth (up to 1000 levels) from exchange, calculates all metrics,
|
|
1612
|
+
* and formats results as markdown report optimized for LLM consumption.
|
|
1613
|
+
*
|
|
1614
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1615
|
+
* @returns Markdown-formatted order book report with depth analysis
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```typescript
|
|
1619
|
+
* const report = await service.getReport('BTCUSDT');
|
|
1620
|
+
* console.log(report);
|
|
1621
|
+
* // # Order Book Analysis for BTCUSDT
|
|
1622
|
+
* // > Current time: 2025-01-14T10:30:00.000Z
|
|
1623
|
+
* //
|
|
1624
|
+
* // ## Order Book Summary
|
|
1625
|
+
* // - **Best Bid**: 42000.50 USD
|
|
1626
|
+
* // - **Depth Imbalance**: 12.5%
|
|
1627
|
+
* //
|
|
1628
|
+
* // ## Top 20 Order Book Levels
|
|
1629
|
+
* // ### Bids (Buy Orders)
|
|
1630
|
+
* // | Price | Quantity | % of Total |
|
|
1631
|
+
* ```
|
|
1632
|
+
*/
|
|
1633
|
+
getReport: (symbol: string) => Promise<string>;
|
|
1634
|
+
/**
|
|
1635
|
+
* Fetches and analyzes order book data with depth metrics.
|
|
1636
|
+
*
|
|
1637
|
+
* Retrieves up to 1000 depth levels from exchange, processes bid/ask data,
|
|
1638
|
+
* calculates volume percentages, and computes market depth metrics including
|
|
1639
|
+
* best bid/ask, mid price, spread, and depth imbalance.
|
|
1640
|
+
*
|
|
1641
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1642
|
+
* @returns Order book analysis with all calculated metrics
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```typescript
|
|
1646
|
+
* const analysis = await service.getData('BTCUSDT');
|
|
1647
|
+
* console.log(analysis.bestBid); // 42000.50
|
|
1648
|
+
* console.log(analysis.bestAsk); // 42001.25
|
|
1649
|
+
* console.log(analysis.spread); // 0.75
|
|
1650
|
+
* console.log(analysis.depthImbalance); // 0.125 (12.5% buy pressure)
|
|
1651
|
+
* console.log(analysis.bids.length); // Up to 1000 levels
|
|
1652
|
+
* ```
|
|
1653
|
+
*/
|
|
1654
|
+
getData: (symbol: string) => Promise<IBookDataAnalysis>;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* Logger service for signals library diagnostic output.
|
|
1659
|
+
*
|
|
1660
|
+
* Provides logging capabilities with a no-op default implementation.
|
|
1661
|
+
* Use setLogger() from the public API to enable actual logging output.
|
|
1662
|
+
*
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```typescript
|
|
1665
|
+
* import { setLogger } from '@backtest-kit/signals';
|
|
1666
|
+
*
|
|
1667
|
+
* setLogger({
|
|
1668
|
+
* log: console.log,
|
|
1669
|
+
* debug: console.debug,
|
|
1670
|
+
* info: console.info,
|
|
1671
|
+
* warn: console.warn,
|
|
1672
|
+
* });
|
|
1673
|
+
* ```
|
|
1674
|
+
*/
|
|
1675
|
+
|
|
1676
|
+
/**
|
|
1677
|
+
* Logger service implementation with configurable backend.
|
|
1678
|
+
*
|
|
1679
|
+
* Delegates all logging calls to the configured logger implementation.
|
|
1680
|
+
* Defaults to NOOP_LOGGER which discards all output.
|
|
1681
|
+
*/
|
|
1682
|
+
declare class LoggerService implements ILogger {
|
|
1683
|
+
private _commonLogger;
|
|
1684
|
+
/**
|
|
1685
|
+
* Logs general messages with topic and optional arguments.
|
|
1686
|
+
*
|
|
1687
|
+
* Delegates to configured logger implementation. Uses no-op logger by default
|
|
1688
|
+
* until setLogger() is called with custom implementation.
|
|
1689
|
+
*
|
|
1690
|
+
* @param topic - Log topic or category identifier
|
|
1691
|
+
* @param args - Additional arguments to log
|
|
1692
|
+
*
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```typescript
|
|
1695
|
+
* const logger = new LoggerService();
|
|
1696
|
+
* await logger.log('user-action', { userId: '123', action: 'login' });
|
|
1697
|
+
* // Output depends on configured logger implementation
|
|
1698
|
+
* ```
|
|
1699
|
+
*/
|
|
1700
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
1701
|
+
/**
|
|
1702
|
+
* Logs debug-level messages with topic and optional arguments.
|
|
1703
|
+
*
|
|
1704
|
+
* Typically used for detailed diagnostic information during development.
|
|
1705
|
+
* Delegates to configured logger implementation.
|
|
1706
|
+
*
|
|
1707
|
+
* @param topic - Debug topic or category identifier
|
|
1708
|
+
* @param args - Additional arguments to log
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```typescript
|
|
1712
|
+
* const logger = new LoggerService();
|
|
1713
|
+
* await logger.debug('api-call', { endpoint: '/data', params: { limit: 10 } });
|
|
1714
|
+
* ```
|
|
1715
|
+
*/
|
|
1716
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
1717
|
+
/**
|
|
1718
|
+
* Logs informational messages with topic and optional arguments.
|
|
1719
|
+
*
|
|
1720
|
+
* Used for general informational messages about application state or progress.
|
|
1721
|
+
* Delegates to configured logger implementation.
|
|
1722
|
+
*
|
|
1723
|
+
* @param topic - Info topic or category identifier
|
|
1724
|
+
* @param args - Additional arguments to log
|
|
1725
|
+
*
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```typescript
|
|
1728
|
+
* const logger = new LoggerService();
|
|
1729
|
+
* await logger.info('server-start', { port: 3000, env: 'production' });
|
|
1730
|
+
* ```
|
|
1731
|
+
*/
|
|
1732
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
1733
|
+
/**
|
|
1734
|
+
* Logs warning messages with topic and optional arguments.
|
|
1735
|
+
*
|
|
1736
|
+
* Used for potentially harmful situations that don't prevent execution.
|
|
1737
|
+
* Delegates to configured logger implementation.
|
|
1738
|
+
*
|
|
1739
|
+
* @param topic - Warning topic or category identifier
|
|
1740
|
+
* @param args - Additional arguments to log
|
|
1741
|
+
*
|
|
1742
|
+
* @example
|
|
1743
|
+
* ```typescript
|
|
1744
|
+
* const logger = new LoggerService();
|
|
1745
|
+
* await logger.warn('rate-limit', { limit: 100, current: 95 });
|
|
1746
|
+
* ```
|
|
1747
|
+
*/
|
|
1748
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
1749
|
+
/**
|
|
1750
|
+
* Sets custom logger implementation.
|
|
1751
|
+
*
|
|
1752
|
+
* Replaces the default no-op logger with a custom implementation that
|
|
1753
|
+
* conforms to the ILogger interface. Call this during application initialization
|
|
1754
|
+
* to enable actual logging output.
|
|
1755
|
+
*
|
|
1756
|
+
* @param logger - Custom logger conforming to ILogger interface
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* ```typescript
|
|
1760
|
+
* const logger = new LoggerService();
|
|
1761
|
+
* logger.setLogger({
|
|
1762
|
+
* log: console.log,
|
|
1763
|
+
* debug: console.debug,
|
|
1764
|
+
* info: console.info,
|
|
1765
|
+
* warn: console.warn,
|
|
1766
|
+
* });
|
|
1767
|
+
* await logger.log('test', 'now logging to console');
|
|
1768
|
+
* ```
|
|
1769
|
+
*/
|
|
1770
|
+
setLogger: (logger: ILogger) => void;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Service container initialization and export for signals library.
|
|
1775
|
+
*
|
|
1776
|
+
* Initializes the DI container, injects all registered services,
|
|
1777
|
+
* and exports them as a unified 'signal' object for internal use.
|
|
1778
|
+
*
|
|
1779
|
+
* This module:
|
|
1780
|
+
* 1. Imports service registrations from './core/provide'
|
|
1781
|
+
* 2. Injects all services from DI container
|
|
1782
|
+
* 3. Initializes DI container
|
|
1783
|
+
* 4. Exports combined service object
|
|
1784
|
+
* 5. Attaches to globalThis for debugging (non-production only)
|
|
1785
|
+
*
|
|
1786
|
+
* @module lib/index
|
|
1787
|
+
*/
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Combined service container for internal library use.
|
|
1791
|
+
* Contains all registered services: common, math, and history.
|
|
1792
|
+
*/
|
|
1793
|
+
declare const signal: {
|
|
1794
|
+
fifteenMinuteCandleHistoryService: FifteenMinuteCandleHistoryService;
|
|
1795
|
+
hourCandleHistoryService: HourCandleHistoryService;
|
|
1796
|
+
oneMinuteCandleHistoryService: OneMinuteCandleHistoryService;
|
|
1797
|
+
thirtyMinuteCandleHistoryService: ThirtyMinuteCandleHistoryService;
|
|
1798
|
+
swingTermMathService: SwingTermHistoryService;
|
|
1799
|
+
longTermMathService: LongTermHistoryService;
|
|
1800
|
+
shortTermMathService: ShortTermHistoryService;
|
|
1801
|
+
microTermMathService: MicroTermHistoryService;
|
|
1802
|
+
bookDataMathService: BookDataMathService;
|
|
1803
|
+
loggerService: LoggerService;
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
export { commitBookDataReport, commitFifteenMinuteHistory, commitHistorySetup, commitHourHistory, commitLongTermMath, commitMicroTermMath, commitOneMinuteHistory, commitShortTermMath, commitSwingTermMath, commitThirtyMinuteHistory, signal as lib, setLogger };
|