hedgequantx 2.9.140 → 2.9.141
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/package.json +1 -1
- package/src/lib/smart-logs-engine.js +385 -0
- package/src/lib/smart-logs-live.js +341 -0
- package/src/lib/smart-logs-messages/bias-messages.js +432 -0
- package/src/lib/smart-logs-messages/index.js +51 -0
- package/src/lib/smart-logs-messages/strategy-messages.js +176 -0
- package/src/lib/smart-logs-messages/trade-messages.js +187 -0
- package/src/lib/smart-logs-messages.js +3 -852
- package/src/lib/smart-logs.js +70 -0
- package/src/pages/algo/algo-executor.js +47 -83
- package/src/pages/algo/multi-symbol-executor.js +55 -14
package/package.json
CHANGED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* =============================================================================
|
|
3
|
+
* Smart Logs Engine - HFT-Grade Real-Time Market Analysis
|
|
4
|
+
* =============================================================================
|
|
5
|
+
* Professional algorithmic trading logging engine
|
|
6
|
+
* - Institutional-grade market microstructure analysis
|
|
7
|
+
* - Strategy-adaptive message generation
|
|
8
|
+
* - Non-repetitive rotation with 50+ messages per context
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const chalk = require('chalk');
|
|
14
|
+
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// ENGINE CONFIGURATION
|
|
17
|
+
// =============================================================================
|
|
18
|
+
|
|
19
|
+
const CONFIG = {
|
|
20
|
+
MAX_RECENT: 50,
|
|
21
|
+
SESSION_LOG_INTERVAL: 10,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// =============================================================================
|
|
25
|
+
// HFT MARKET MICROSTRUCTURE MESSAGES
|
|
26
|
+
// =============================================================================
|
|
27
|
+
|
|
28
|
+
const MARKET = {
|
|
29
|
+
bullish: [
|
|
30
|
+
'Aggressive bid-side lifting detected on tape',
|
|
31
|
+
'Delta divergence positive - buy programs active',
|
|
32
|
+
'Institutional absorption at bid confirmed',
|
|
33
|
+
'Order flow imbalance favoring buyers 70/30',
|
|
34
|
+
'CVD trending positive with volume confirmation',
|
|
35
|
+
'Smart money accumulation footprint detected',
|
|
36
|
+
'Iceberg bids absorbing all passive supply',
|
|
37
|
+
'Block trades executing on bid side',
|
|
38
|
+
'Momentum ignition pattern to upside',
|
|
39
|
+
'Bid stack replenishing faster than offer',
|
|
40
|
+
'Large lot buyers sweeping through offers',
|
|
41
|
+
'Positive tick imbalance accelerating',
|
|
42
|
+
'Buy-side aggression ratio above threshold',
|
|
43
|
+
'Institutional footprint bullish on DOM',
|
|
44
|
+
'Passive supply exhausted at current level',
|
|
45
|
+
'Delta histogram expanding bullish',
|
|
46
|
+
'Volume-weighted momentum trending up',
|
|
47
|
+
'Bid depth outpacing offer depth 3:1',
|
|
48
|
+
'Aggressive market orders lifting offers',
|
|
49
|
+
'POC shifting higher with acceptance',
|
|
50
|
+
],
|
|
51
|
+
bearish: [
|
|
52
|
+
'Aggressive offer-side hitting detected',
|
|
53
|
+
'Delta divergence negative - sell programs active',
|
|
54
|
+
'Institutional distribution at offer confirmed',
|
|
55
|
+
'Order flow imbalance favoring sellers 70/30',
|
|
56
|
+
'CVD trending negative with volume spike',
|
|
57
|
+
'Smart money distribution footprint visible',
|
|
58
|
+
'Iceberg offers absorbing all passive demand',
|
|
59
|
+
'Block trades executing on offer side',
|
|
60
|
+
'Momentum ignition pattern to downside',
|
|
61
|
+
'Offer stack replenishing faster than bid',
|
|
62
|
+
'Large lot sellers sweeping through bids',
|
|
63
|
+
'Negative tick imbalance accelerating',
|
|
64
|
+
'Sell-side aggression ratio above threshold',
|
|
65
|
+
'Institutional footprint bearish on DOM',
|
|
66
|
+
'Passive demand exhausted at current level',
|
|
67
|
+
'Delta histogram expanding bearish',
|
|
68
|
+
'Volume-weighted momentum trending down',
|
|
69
|
+
'Offer depth outpacing bid depth 3:1',
|
|
70
|
+
'Aggressive market orders hitting bids',
|
|
71
|
+
'POC shifting lower with acceptance',
|
|
72
|
+
],
|
|
73
|
+
neutral: [
|
|
74
|
+
'Order flow in equilibrium - balanced auction',
|
|
75
|
+
'Delta oscillating around zero line',
|
|
76
|
+
'Institutional activity inconclusive',
|
|
77
|
+
'Bid/ask imbalance ratio near 50/50',
|
|
78
|
+
'CVD flat - no directional conviction',
|
|
79
|
+
'Volume profile showing balanced distribution',
|
|
80
|
+
'No significant block trade activity',
|
|
81
|
+
'Market making both sides of spread',
|
|
82
|
+
'Range-bound microstructure developing',
|
|
83
|
+
'Liquidity symmetric on bid and offer',
|
|
84
|
+
'Absorption visible on both sides',
|
|
85
|
+
'Tick imbalance neutral - no edge',
|
|
86
|
+
'Aggression ratio balanced',
|
|
87
|
+
'DOM showing no institutional bias',
|
|
88
|
+
'Price discovery in equilibrium zone',
|
|
89
|
+
'Delta histogram contracted - low conviction',
|
|
90
|
+
'Volume declining - participants waiting',
|
|
91
|
+
'POC stable - fair value accepted',
|
|
92
|
+
'Spread widening - liquidity thinning',
|
|
93
|
+
'Rotation between value area extremes',
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// =============================================================================
|
|
98
|
+
// STRATEGY-SPECIFIC HFT CONFIGURATIONS
|
|
99
|
+
// =============================================================================
|
|
100
|
+
|
|
101
|
+
const STRATEGIES = {
|
|
102
|
+
'hqx-2b': {
|
|
103
|
+
name: 'HQX-2B Liquidity Sweep',
|
|
104
|
+
desc: '2B reversal pattern with institutional liquidity sweep detection',
|
|
105
|
+
phases: {
|
|
106
|
+
building: [
|
|
107
|
+
'Constructing swing point topology from OHLC data',
|
|
108
|
+
'Mapping institutional stop cluster zones',
|
|
109
|
+
'Identifying liquidity pool concentrations',
|
|
110
|
+
'Analyzing swing failure pattern potential',
|
|
111
|
+
'Building support/resistance zone matrix',
|
|
112
|
+
'Detecting false breakout trigger levels',
|
|
113
|
+
'Processing pivot point sequence data',
|
|
114
|
+
'Mapping stop-hunt probability zones',
|
|
115
|
+
'Computing swing point strength metrics',
|
|
116
|
+
'Analyzing zone touch count statistics',
|
|
117
|
+
'Building institutional footprint map',
|
|
118
|
+
'Detecting order block formation areas',
|
|
119
|
+
'Processing market structure hierarchy',
|
|
120
|
+
'Mapping liquidity void regions',
|
|
121
|
+
'Computing zone confluence metrics',
|
|
122
|
+
'Analyzing price rejection patterns',
|
|
123
|
+
'Building sweep trigger level database',
|
|
124
|
+
'Detecting retail stop cluster areas',
|
|
125
|
+
'Processing swing momentum data',
|
|
126
|
+
'Mapping reversal probability zones',
|
|
127
|
+
],
|
|
128
|
+
scanning: [
|
|
129
|
+
'Liquidity zone proximity alert active',
|
|
130
|
+
'Monitoring stop cluster for sweep trigger',
|
|
131
|
+
'Zone boundary penetration imminent',
|
|
132
|
+
'Institutional sweep setup developing',
|
|
133
|
+
'Price approaching mapped liquidity pool',
|
|
134
|
+
'Stop-hunt zone in execution range',
|
|
135
|
+
'Monitoring for false breakout trigger',
|
|
136
|
+
'Zone touch detected - sweep probability rising',
|
|
137
|
+
'Liquidity sweep conditions aligning',
|
|
138
|
+
'Retail stops visible below/above zone',
|
|
139
|
+
'Institutional intent detected near zone',
|
|
140
|
+
'Sweep velocity threshold approaching',
|
|
141
|
+
'Zone penetration depth monitoring active',
|
|
142
|
+
'False breakout pattern probability high',
|
|
143
|
+
'Liquidity pool vulnerable to sweep',
|
|
144
|
+
'Stop cluster triggering imminent',
|
|
145
|
+
'Monitoring zone rejection momentum',
|
|
146
|
+
'Sweep confirmation criteria pending',
|
|
147
|
+
'Institutional trap setup forming',
|
|
148
|
+
'Zone defense level under pressure',
|
|
149
|
+
],
|
|
150
|
+
ready: [
|
|
151
|
+
'Liquidity sweep confirmed - reversal imminent',
|
|
152
|
+
'2B pattern triggered - institutional trap complete',
|
|
153
|
+
'Stop-hunt executed - reversal momentum building',
|
|
154
|
+
'Zone penetration + rejection = entry signal',
|
|
155
|
+
'False breakout confirmed - reversal validated',
|
|
156
|
+
'Institutional sweep complete - entry window open',
|
|
157
|
+
'Retail stops triggered - smart money reversing',
|
|
158
|
+
'2B reversal confirmation on volume',
|
|
159
|
+
'Sweep velocity threshold exceeded - signal active',
|
|
160
|
+
'Zone rejection momentum above threshold',
|
|
161
|
+
'Institutional reversal footprint confirmed',
|
|
162
|
+
'Stop-hunt + rejection = high probability entry',
|
|
163
|
+
'False breakout trap executed successfully',
|
|
164
|
+
'Reversal momentum acceleration detected',
|
|
165
|
+
'2B pattern completion - execution ready',
|
|
166
|
+
'Liquidity sweep + volume = entry criteria met',
|
|
167
|
+
'Institutional buying/selling post-sweep',
|
|
168
|
+
'Reversal confirmation candle forming',
|
|
169
|
+
'Entry trigger threshold reached',
|
|
170
|
+
'Setup validation complete - signal active',
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
'ultra-scalping': {
|
|
175
|
+
name: 'Ultra Scalping',
|
|
176
|
+
desc: 'Statistical microstructure edge detection with VPIN/Z-Score',
|
|
177
|
+
phases: {
|
|
178
|
+
building: [
|
|
179
|
+
'Computing tick-by-tick Z-Score distribution',
|
|
180
|
+
'Calculating VPIN toxicity flow metric',
|
|
181
|
+
'Building order flow imbalance model',
|
|
182
|
+
'Processing Level 2 microstructure data',
|
|
183
|
+
'Computing statistical arbitrage factors',
|
|
184
|
+
'Analyzing bid-ask spread dynamics',
|
|
185
|
+
'Building multi-factor signal matrix',
|
|
186
|
+
'Processing real-time covariance data',
|
|
187
|
+
'Computing momentum factor coefficients',
|
|
188
|
+
'Analyzing cross-asset correlation matrix',
|
|
189
|
+
'Building volatility regime classifier',
|
|
190
|
+
'Processing tick imbalance statistics',
|
|
191
|
+
'Computing mean reversion z-scores',
|
|
192
|
+
'Analyzing order arrival rate patterns',
|
|
193
|
+
'Building execution probability model',
|
|
194
|
+
'Processing quote stuffing detection',
|
|
195
|
+
'Computing adverse selection metrics',
|
|
196
|
+
'Analyzing market maker inventory',
|
|
197
|
+
'Building price impact estimator',
|
|
198
|
+
'Processing HFT signal aggregation',
|
|
199
|
+
],
|
|
200
|
+
scanning: [
|
|
201
|
+
'Z-Score approaching entry threshold',
|
|
202
|
+
'VPIN toxicity level rising - alert active',
|
|
203
|
+
'Order flow imbalance building momentum',
|
|
204
|
+
'Statistical edge probability increasing',
|
|
205
|
+
'Factor model scores converging',
|
|
206
|
+
'Microstructure anomaly developing',
|
|
207
|
+
'Volatility regime shift detected',
|
|
208
|
+
'Tick imbalance ratio above normal',
|
|
209
|
+
'Mean reversion signal strengthening',
|
|
210
|
+
'Cross-factor correlation aligning',
|
|
211
|
+
'Execution window approaching',
|
|
212
|
+
'Signal-to-noise ratio improving',
|
|
213
|
+
'Statistical threshold proximity alert',
|
|
214
|
+
'Factor consensus building',
|
|
215
|
+
'Edge detection confidence rising',
|
|
216
|
+
'Microstructure pattern forming',
|
|
217
|
+
'Quantitative signal developing',
|
|
218
|
+
'Multi-factor alignment in progress',
|
|
219
|
+
'Entry criteria approaching threshold',
|
|
220
|
+
'Statistical anomaly probability high',
|
|
221
|
+
],
|
|
222
|
+
ready: [
|
|
223
|
+
'Z-Score threshold breached - signal active',
|
|
224
|
+
'VPIN spike confirmed - toxic flow detected',
|
|
225
|
+
'Order flow imbalance confirmed - entry valid',
|
|
226
|
+
'Statistical edge threshold exceeded',
|
|
227
|
+
'Multi-factor consensus achieved - execute',
|
|
228
|
+
'Microstructure signal confirmed',
|
|
229
|
+
'Volatility regime optimal for entry',
|
|
230
|
+
'Tick imbalance ratio at extreme',
|
|
231
|
+
'Mean reversion entry criteria met',
|
|
232
|
+
'Cross-factor alignment confirmed',
|
|
233
|
+
'Execution window open - signal hot',
|
|
234
|
+
'Signal-to-noise ratio optimal',
|
|
235
|
+
'Statistical threshold exceeded',
|
|
236
|
+
'Factor model confidence maximum',
|
|
237
|
+
'Edge detection confirmed - entry',
|
|
238
|
+
'Microstructure pattern validated',
|
|
239
|
+
'Quantitative signal triggered',
|
|
240
|
+
'Multi-factor entry criteria satisfied',
|
|
241
|
+
'Statistical anomaly confirmed',
|
|
242
|
+
'HFT-grade entry opportunity active',
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Default fallback strategy
|
|
249
|
+
const DEFAULT_STRATEGY = {
|
|
250
|
+
name: 'Algorithmic Strategy',
|
|
251
|
+
desc: 'Generic algorithmic trading framework',
|
|
252
|
+
phases: {
|
|
253
|
+
building: [
|
|
254
|
+
'Processing market data feed',
|
|
255
|
+
'Building signal detection model',
|
|
256
|
+
'Analyzing price action structure',
|
|
257
|
+
'Computing entry criteria metrics',
|
|
258
|
+
'Processing indicator calculations',
|
|
259
|
+
],
|
|
260
|
+
scanning: [
|
|
261
|
+
'Monitoring entry conditions',
|
|
262
|
+
'Signal probability rising',
|
|
263
|
+
'Setup conditions developing',
|
|
264
|
+
'Entry criteria approaching',
|
|
265
|
+
'Pattern formation in progress',
|
|
266
|
+
],
|
|
267
|
+
ready: [
|
|
268
|
+
'Entry signal confirmed',
|
|
269
|
+
'Setup criteria satisfied',
|
|
270
|
+
'Execution window active',
|
|
271
|
+
'Signal validation complete',
|
|
272
|
+
'Entry conditions met',
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// =============================================================================
|
|
278
|
+
// SMART LOGS ENGINE CLASS
|
|
279
|
+
// =============================================================================
|
|
280
|
+
|
|
281
|
+
class SmartLogsEngine {
|
|
282
|
+
constructor(strategyId) {
|
|
283
|
+
this.strategyId = strategyId || 'default';
|
|
284
|
+
this.strategy = STRATEGIES[this.strategyId] || DEFAULT_STRATEGY;
|
|
285
|
+
this.recent = new Map();
|
|
286
|
+
this.counter = 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Get strategy metadata */
|
|
290
|
+
getInfo() {
|
|
291
|
+
return { id: this.strategyId, name: this.strategy.name, desc: this.strategy.desc };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Get non-repetitive message from pool */
|
|
295
|
+
_pick(category, pool) {
|
|
296
|
+
const key = `${this.strategyId}_${category}`;
|
|
297
|
+
let used = this.recent.get(key) || [];
|
|
298
|
+
let available = pool.filter(m => !used.includes(m));
|
|
299
|
+
|
|
300
|
+
if (available.length === 0) {
|
|
301
|
+
used = [];
|
|
302
|
+
available = pool;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const msg = available[Math.floor(Math.random() * available.length)];
|
|
306
|
+
used.push(msg);
|
|
307
|
+
if (used.length > CONFIG.MAX_RECENT) used.shift();
|
|
308
|
+
this.recent.set(key, used);
|
|
309
|
+
|
|
310
|
+
return msg;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Determine strategy phase from state */
|
|
314
|
+
_phase(state) {
|
|
315
|
+
const { bars = 0, swings = 0, zones = 0, setupForming = false } = state;
|
|
316
|
+
if (setupForming && zones > 0) return 'ready';
|
|
317
|
+
if (zones > 0 || swings >= 2) return 'scanning';
|
|
318
|
+
return 'building';
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Generate contextual HFT-grade log message
|
|
323
|
+
* @param {Object} state - Market/strategy state
|
|
324
|
+
* @returns {Object} { type, message, logToSession }
|
|
325
|
+
*/
|
|
326
|
+
getLog(state = {}) {
|
|
327
|
+
this.counter++;
|
|
328
|
+
const { trend = 'neutral', position = 0, zones = 0, swings = 0, bars = 0, price = 0 } = state;
|
|
329
|
+
|
|
330
|
+
let type, message;
|
|
331
|
+
|
|
332
|
+
// Position management mode
|
|
333
|
+
if (position !== 0) {
|
|
334
|
+
const side = position > 0 ? 'LONG' : 'SHORT';
|
|
335
|
+
const icon = position > 0 ? chalk.cyan('▲') : chalk.magenta('▼');
|
|
336
|
+
message = `${icon} Position active: ${side} | Monitoring P&L and exit criteria`;
|
|
337
|
+
type = 'trade';
|
|
338
|
+
} else {
|
|
339
|
+
const phase = this._phase(state);
|
|
340
|
+
|
|
341
|
+
// Alternate: 2/3 strategy messages, 1/3 market microstructure
|
|
342
|
+
if (this.counter % 3 === 0 && phase !== 'building') {
|
|
343
|
+
const trendKey = ['bullish', 'LONG'].includes(trend) ? 'bullish'
|
|
344
|
+
: ['bearish', 'SHORT'].includes(trend) ? 'bearish' : 'neutral';
|
|
345
|
+
message = this._pick(`mkt_${trendKey}`, MARKET[trendKey]);
|
|
346
|
+
type = trendKey === 'bullish' ? 'bullish' : trendKey === 'bearish' ? 'bearish' : 'analysis';
|
|
347
|
+
} else {
|
|
348
|
+
message = this._pick(`strat_${phase}`, this.strategy.phases[phase]);
|
|
349
|
+
type = phase === 'ready' ? 'signal' : phase === 'scanning' ? 'analysis' : 'debug';
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Add metrics context periodically
|
|
354
|
+
if (this.counter % 4 === 0 && price > 0) {
|
|
355
|
+
const ctx = zones > 0 ? `Z:${zones} SW:${swings}` : `B:${bars}`;
|
|
356
|
+
message = `${message} | ${ctx}`;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
type,
|
|
361
|
+
message,
|
|
362
|
+
logToSession: this.counter % CONFIG.SESSION_LOG_INTERVAL === 0,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Reset for new session */
|
|
367
|
+
reset() {
|
|
368
|
+
this.recent.clear();
|
|
369
|
+
this.counter = 0;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// =============================================================================
|
|
374
|
+
// FACTORY & EXPORTS
|
|
375
|
+
// =============================================================================
|
|
376
|
+
|
|
377
|
+
function createEngine(strategyId) {
|
|
378
|
+
return new SmartLogsEngine(strategyId);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function getStrategies() {
|
|
382
|
+
return Object.entries(STRATEGIES).map(([id, s]) => ({ id, name: s.name, desc: s.desc }));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
module.exports = { SmartLogsEngine, createEngine, getStrategies, MARKET, STRATEGIES, CONFIG };
|