hedgequantx 2.6.163 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -88
- package/bin/cli.js +0 -11
- package/dist/lib/api.jsc +0 -0
- package/dist/lib/api2.jsc +0 -0
- package/dist/lib/core.jsc +0 -0
- package/dist/lib/core2.jsc +0 -0
- package/dist/lib/data.js +1 -1
- package/dist/lib/data.jsc +0 -0
- package/dist/lib/data2.jsc +0 -0
- package/dist/lib/decoder.jsc +0 -0
- package/dist/lib/m/mod1.jsc +0 -0
- package/dist/lib/m/mod2.jsc +0 -0
- package/dist/lib/n/r1.jsc +0 -0
- package/dist/lib/n/r2.jsc +0 -0
- package/dist/lib/n/r3.jsc +0 -0
- package/dist/lib/n/r4.jsc +0 -0
- package/dist/lib/n/r5.jsc +0 -0
- package/dist/lib/n/r6.jsc +0 -0
- package/dist/lib/n/r7.jsc +0 -0
- package/dist/lib/o/util1.jsc +0 -0
- package/dist/lib/o/util2.jsc +0 -0
- package/package.json +6 -3
- package/src/app.js +40 -162
- package/src/config/constants.js +31 -33
- package/src/config/propfirms.js +13 -217
- package/src/config/settings.js +0 -43
- package/src/lib/api.js +198 -0
- package/src/lib/api2.js +353 -0
- package/src/lib/core.js +539 -0
- package/src/lib/core2.js +341 -0
- package/src/lib/data.js +555 -0
- package/src/lib/data2.js +492 -0
- package/src/lib/decoder.js +599 -0
- package/src/lib/m/s1.js +804 -0
- package/src/lib/m/s2.js +34 -0
- package/src/lib/n/r1.js +454 -0
- package/src/lib/n/r2.js +514 -0
- package/src/lib/n/r3.js +631 -0
- package/src/lib/n/r4.js +401 -0
- package/src/lib/n/r5.js +335 -0
- package/src/lib/n/r6.js +425 -0
- package/src/lib/n/r7.js +530 -0
- package/src/lib/o/l1.js +44 -0
- package/src/lib/o/l2.js +427 -0
- package/src/lib/python-bridge.js +206 -0
- package/src/menus/connect.js +14 -176
- package/src/menus/dashboard.js +65 -110
- package/src/pages/accounts.js +18 -18
- package/src/pages/algo/copy-trading.js +210 -240
- package/src/pages/algo/index.js +41 -104
- package/src/pages/algo/one-account.js +386 -33
- package/src/pages/algo/ui.js +312 -151
- package/src/pages/orders.js +3 -3
- package/src/pages/positions.js +3 -3
- package/src/pages/stats/chart.js +74 -0
- package/src/pages/stats/display.js +228 -0
- package/src/pages/stats/index.js +236 -0
- package/src/pages/stats/metrics.js +213 -0
- package/src/pages/user.js +6 -6
- package/src/services/hqx-server/constants.js +55 -0
- package/src/services/hqx-server/index.js +401 -0
- package/src/services/hqx-server/latency.js +81 -0
- package/src/services/index.js +12 -3
- package/src/services/rithmic/accounts.js +7 -32
- package/src/services/rithmic/connection.js +1 -204
- package/src/services/rithmic/contracts.js +116 -99
- package/src/services/rithmic/handlers.js +21 -196
- package/src/services/rithmic/index.js +63 -120
- package/src/services/rithmic/market.js +31 -0
- package/src/services/rithmic/orders.js +5 -111
- package/src/services/rithmic/protobuf.js +384 -138
- package/src/services/session.js +22 -173
- package/src/ui/box.js +10 -18
- package/src/ui/index.js +1 -3
- package/src/ui/menu.js +1 -1
- package/src/utils/prompts.js +2 -2
- package/dist/lib/m/s1.js +0 -1
- package/src/menus/ai-agent-connect.js +0 -181
- package/src/menus/ai-agent-models.js +0 -219
- package/src/menus/ai-agent-oauth.js +0 -292
- package/src/menus/ai-agent-ui.js +0 -141
- package/src/menus/ai-agent.js +0 -484
- package/src/pages/algo/algo-config.js +0 -195
- package/src/pages/algo/algo-multi.js +0 -801
- package/src/pages/algo/algo-utils.js +0 -58
- package/src/pages/algo/copy-engine.js +0 -449
- package/src/pages/algo/custom-strategy.js +0 -459
- package/src/pages/algo/logger.js +0 -245
- package/src/pages/algo/smart-logs-data.js +0 -218
- package/src/pages/algo/smart-logs.js +0 -387
- package/src/pages/algo/ui-constants.js +0 -144
- package/src/pages/algo/ui-summary.js +0 -184
- package/src/pages/stats-calculations.js +0 -191
- package/src/pages/stats-ui.js +0 -381
- package/src/pages/stats.js +0 -339
- package/src/services/ai/client-analysis.js +0 -194
- package/src/services/ai/client-models.js +0 -333
- package/src/services/ai/client.js +0 -343
- package/src/services/ai/index.js +0 -384
- package/src/services/ai/oauth-anthropic.js +0 -265
- package/src/services/ai/oauth-gemini.js +0 -223
- package/src/services/ai/oauth-iflow.js +0 -269
- package/src/services/ai/oauth-openai.js +0 -233
- package/src/services/ai/oauth-qwen.js +0 -279
- package/src/services/ai/providers/direct-providers.js +0 -323
- package/src/services/ai/providers/index.js +0 -62
- package/src/services/ai/providers/other-providers.js +0 -104
- package/src/services/ai/proxy-install.js +0 -249
- package/src/services/ai/proxy-manager.js +0 -494
- package/src/services/ai/proxy-remote.js +0 -161
- package/src/services/ai/strategy-supervisor.js +0 -1312
- package/src/services/ai/supervisor-data.js +0 -195
- package/src/services/ai/supervisor-optimize.js +0 -215
- package/src/services/ai/supervisor-sync.js +0 -178
- package/src/services/ai/supervisor-utils.js +0 -158
- package/src/services/ai/supervisor.js +0 -484
- package/src/services/ai/validation.js +0 -250
- package/src/services/hqx-server-events.js +0 -110
- package/src/services/hqx-server-handlers.js +0 -217
- package/src/services/hqx-server-latency.js +0 -136
- package/src/services/hqx-server.js +0 -403
- package/src/services/position-constants.js +0 -28
- package/src/services/position-exit-logic.js +0 -174
- package/src/services/position-manager.js +0 -438
- package/src/services/position-momentum.js +0 -206
- package/src/services/projectx/accounts.js +0 -142
- package/src/services/projectx/index.js +0 -443
- package/src/services/projectx/market.js +0 -172
- package/src/services/projectx/stats.js +0 -110
- package/src/services/projectx/trading.js +0 -180
- package/src/services/rithmic/latency-tracker.js +0 -182
- package/src/services/rithmic/market-data-decoders.js +0 -229
- package/src/services/rithmic/market-data.js +0 -272
- package/src/services/rithmic/orders-fast.js +0 -246
- package/src/services/rithmic/proto-decoders.js +0 -403
- package/src/services/rithmic/specs.js +0 -146
- package/src/services/rithmic/trade-history.js +0 -254
- package/src/services/session-history.js +0 -475
- package/src/services/strategy/hft-signal-calc.js +0 -147
- package/src/services/strategy/hft-tick.js +0 -407
- package/src/services/strategy/recovery-math.js +0 -402
- package/src/services/tradovate/constants.js +0 -109
- package/src/services/tradovate/index.js +0 -392
- package/src/services/tradovate/market.js +0 -47
- package/src/services/tradovate/orders.js +0 -145
- package/src/services/tradovate/websocket.js +0 -97
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smart Logs Message Pools and State
|
|
3
|
-
* @module pages/algo/smart-logs-data
|
|
4
|
-
*
|
|
5
|
-
* HF-grade message pools for institutional logging.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
// State tracking
|
|
11
|
-
const recentMessages = new Map();
|
|
12
|
-
const MAX_RECENT = 5;
|
|
13
|
-
|
|
14
|
-
// Market microstructure state
|
|
15
|
-
const microstructure = {
|
|
16
|
-
ofi: 0,
|
|
17
|
-
cumDelta: 0,
|
|
18
|
-
delta: 0,
|
|
19
|
-
zscore: 0,
|
|
20
|
-
momentum: 0,
|
|
21
|
-
acceleration: 0,
|
|
22
|
-
spread: 0,
|
|
23
|
-
bidDepth: 0,
|
|
24
|
-
askDepth: 0,
|
|
25
|
-
imbalance: 0,
|
|
26
|
-
vwap: 0,
|
|
27
|
-
poc: 0,
|
|
28
|
-
atr: 0,
|
|
29
|
-
tps: 0,
|
|
30
|
-
buyVol: 0,
|
|
31
|
-
sellVol: 0,
|
|
32
|
-
lastUpdate: Date.now(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Position state
|
|
36
|
-
const position = {
|
|
37
|
-
side: null,
|
|
38
|
-
symbol: '',
|
|
39
|
-
size: 0,
|
|
40
|
-
entryPrice: 0,
|
|
41
|
-
currentPrice: 0,
|
|
42
|
-
stopLoss: 0,
|
|
43
|
-
takeProfit: 0,
|
|
44
|
-
entryTime: 0,
|
|
45
|
-
unrealizedPnl: 0,
|
|
46
|
-
tickSize: 0.25,
|
|
47
|
-
tickValue: 12.50,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Message pools - HF Grade
|
|
51
|
-
const FLOW_AGGRESSIVE_BUY = [
|
|
52
|
-
'Aggressive lifting offers',
|
|
53
|
-
'Heavy buy-side absorption',
|
|
54
|
-
'Institutional accumulation',
|
|
55
|
-
'Delta surge positive',
|
|
56
|
-
'Bid stacking detected',
|
|
57
|
-
'Buy programs sweeping',
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
const FLOW_AGGRESSIVE_SELL = [
|
|
61
|
-
'Aggressive hitting bids',
|
|
62
|
-
'Heavy sell-side distribution',
|
|
63
|
-
'Institutional liquidation',
|
|
64
|
-
'Delta surge negative',
|
|
65
|
-
'Offer stacking detected',
|
|
66
|
-
'Sell programs sweeping',
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const FLOW_BALANCED = [
|
|
70
|
-
'Two-sided flow equilibrium',
|
|
71
|
-
'Balanced book rotation',
|
|
72
|
-
'Fair value discovery',
|
|
73
|
-
'Neutral order flow',
|
|
74
|
-
'Market making zone',
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
const MR_OVERBOUGHT = [
|
|
78
|
-
'Extended above VWAP band',
|
|
79
|
-
'Z-score overbought extreme',
|
|
80
|
-
'Mean reversion fade setup',
|
|
81
|
-
'Exhaustion at upper band',
|
|
82
|
-
'Stretched deviation short',
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
const MR_OVERSOLD = [
|
|
86
|
-
'Extended below VWAP band',
|
|
87
|
-
'Z-score oversold extreme',
|
|
88
|
-
'Mean reversion bounce setup',
|
|
89
|
-
'Capitulation at lower band',
|
|
90
|
-
'Stretched deviation long',
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
const MOM_ACCELERATING_UP = [
|
|
94
|
-
'Momentum acceleration +',
|
|
95
|
-
'Velocity vector bullish',
|
|
96
|
-
'Trend thrust positive',
|
|
97
|
-
'Breakout momentum confirmed',
|
|
98
|
-
'Impulse wave up',
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
const MOM_ACCELERATING_DOWN = [
|
|
102
|
-
'Momentum acceleration -',
|
|
103
|
-
'Velocity vector bearish',
|
|
104
|
-
'Trend thrust negative',
|
|
105
|
-
'Breakdown momentum confirmed',
|
|
106
|
-
'Impulse wave down',
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
const VOL_EXPANSION = [
|
|
110
|
-
'Volatility expansion cycle',
|
|
111
|
-
'ATR breakout detected',
|
|
112
|
-
'Range expansion phase',
|
|
113
|
-
'Vol regime shift high',
|
|
114
|
-
'Gamma event potential',
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
const VOL_COMPRESSION = [
|
|
118
|
-
'Volatility compression cycle',
|
|
119
|
-
'ATR contraction detected',
|
|
120
|
-
'Range compression phase',
|
|
121
|
-
'Vol regime shift low',
|
|
122
|
-
'Coiling for breakout',
|
|
123
|
-
];
|
|
124
|
-
|
|
125
|
-
const POS_PROFIT_RUNNING = [
|
|
126
|
-
'P&L positive running',
|
|
127
|
-
'Trade thesis confirmed',
|
|
128
|
-
'Alpha capture in progress',
|
|
129
|
-
'Edge realization phase',
|
|
130
|
-
'Position working target',
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
const POS_LOSS_MANAGING = [
|
|
134
|
-
'Adverse excursion mgmt',
|
|
135
|
-
'Drawdown within params',
|
|
136
|
-
'Risk budget consuming',
|
|
137
|
-
'Position under pressure',
|
|
138
|
-
'Defending stop level',
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
const POS_NEAR_TARGET = [
|
|
142
|
-
'Approaching profit target',
|
|
143
|
-
'Near TP execution zone',
|
|
144
|
-
'Exit liquidity scanning',
|
|
145
|
-
'Target strike imminent',
|
|
146
|
-
'Profit capture pending',
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
const POS_NEAR_STOP = [
|
|
150
|
-
'Near stop execution zone',
|
|
151
|
-
'SL liquidity scanning',
|
|
152
|
-
'Risk threshold proximity',
|
|
153
|
-
'Stop strike imminent',
|
|
154
|
-
'Loss containment pending',
|
|
155
|
-
];
|
|
156
|
-
|
|
157
|
-
const SCANNING_ACTIVE = [
|
|
158
|
-
'Scanning microstructure',
|
|
159
|
-
'Analyzing order book',
|
|
160
|
-
'Evaluating flow signals',
|
|
161
|
-
'Pattern recognition active',
|
|
162
|
-
'Setup detection running',
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
// Helper functions
|
|
166
|
-
function getVariedMessage(category, pool, defaultMsg) {
|
|
167
|
-
const recent = recentMessages.get(category) || [];
|
|
168
|
-
const available = pool.filter(msg => !recent.includes(msg));
|
|
169
|
-
if (available.length === 0) {
|
|
170
|
-
recentMessages.set(category, []);
|
|
171
|
-
return pool[Math.floor(Math.random() * pool.length)] || defaultMsg;
|
|
172
|
-
}
|
|
173
|
-
const chosen = available[Math.floor(Math.random() * available.length)] || defaultMsg;
|
|
174
|
-
recent.push(chosen);
|
|
175
|
-
if (recent.length > MAX_RECENT) recent.shift();
|
|
176
|
-
recentMessages.set(category, recent);
|
|
177
|
-
return chosen;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function formatNumber(n, decimals = 2) {
|
|
181
|
-
if (n === undefined || n === null || isNaN(n)) return '--';
|
|
182
|
-
const num = parseFloat(n);
|
|
183
|
-
const sign = num >= 0 ? '+' : '';
|
|
184
|
-
return sign + num.toFixed(decimals);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function formatPnl(pnl) {
|
|
188
|
-
if (pnl === undefined || pnl === null) return '--';
|
|
189
|
-
return pnl >= 0 ? `+$${pnl.toFixed(2)}` : `-$${Math.abs(pnl).toFixed(2)}`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
module.exports = {
|
|
193
|
-
// State
|
|
194
|
-
microstructure,
|
|
195
|
-
position,
|
|
196
|
-
recentMessages,
|
|
197
|
-
|
|
198
|
-
// Pools
|
|
199
|
-
FLOW_AGGRESSIVE_BUY,
|
|
200
|
-
FLOW_AGGRESSIVE_SELL,
|
|
201
|
-
FLOW_BALANCED,
|
|
202
|
-
MR_OVERBOUGHT,
|
|
203
|
-
MR_OVERSOLD,
|
|
204
|
-
MOM_ACCELERATING_UP,
|
|
205
|
-
MOM_ACCELERATING_DOWN,
|
|
206
|
-
VOL_EXPANSION,
|
|
207
|
-
VOL_COMPRESSION,
|
|
208
|
-
POS_PROFIT_RUNNING,
|
|
209
|
-
POS_LOSS_MANAGING,
|
|
210
|
-
POS_NEAR_TARGET,
|
|
211
|
-
POS_NEAR_STOP,
|
|
212
|
-
SCANNING_ACTIVE,
|
|
213
|
-
|
|
214
|
-
// Helpers
|
|
215
|
-
getVariedMessage,
|
|
216
|
-
formatNumber,
|
|
217
|
-
formatPnl,
|
|
218
|
-
};
|
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HQX Institutional Smart Logging System
|
|
3
|
-
* HedgeFund-grade execution logs with market microstructure context
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
microstructure, position, getVariedMessage, formatNumber, formatPnl,
|
|
10
|
-
FLOW_AGGRESSIVE_BUY, FLOW_AGGRESSIVE_SELL, FLOW_BALANCED,
|
|
11
|
-
MR_OVERBOUGHT, MR_OVERSOLD, MOM_ACCELERATING_UP, MOM_ACCELERATING_DOWN,
|
|
12
|
-
VOL_EXPANSION, VOL_COMPRESSION, POS_PROFIT_RUNNING, POS_LOSS_MANAGING,
|
|
13
|
-
POS_NEAR_TARGET, POS_NEAR_STOP, SCANNING_ACTIVE,
|
|
14
|
-
} = require('./smart-logs-data');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Update microstructure state from strategy model values
|
|
18
|
-
*/
|
|
19
|
-
function updateMicrostructure(data) {
|
|
20
|
-
if (data.ofi !== undefined) microstructure.ofi = data.ofi;
|
|
21
|
-
if (data.delta !== undefined) microstructure.delta = data.delta;
|
|
22
|
-
if (data.cumDelta !== undefined) microstructure.cumDelta = data.cumDelta;
|
|
23
|
-
if (data.zscore !== undefined) microstructure.zscore = data.zscore;
|
|
24
|
-
if (data.momentum !== undefined) {
|
|
25
|
-
microstructure.acceleration = data.momentum - microstructure.momentum;
|
|
26
|
-
microstructure.momentum = data.momentum;
|
|
27
|
-
}
|
|
28
|
-
if (data.spread !== undefined) microstructure.spread = data.spread;
|
|
29
|
-
if (data.atr !== undefined) microstructure.atr = data.atr;
|
|
30
|
-
if (data.tps !== undefined) microstructure.tps = data.tps;
|
|
31
|
-
if (data.buyVol !== undefined) microstructure.buyVol = data.buyVol;
|
|
32
|
-
if (data.sellVol !== undefined) microstructure.sellVol = data.sellVol;
|
|
33
|
-
if (data.vwap !== undefined) microstructure.vwap = data.vwap;
|
|
34
|
-
microstructure.lastUpdate = Date.now();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Update position state
|
|
39
|
-
*/
|
|
40
|
-
function updatePosition(data) {
|
|
41
|
-
if (data.side !== undefined) position.side = data.side;
|
|
42
|
-
if (data.symbol !== undefined) position.symbol = data.symbol;
|
|
43
|
-
if (data.size !== undefined) position.size = data.size;
|
|
44
|
-
if (data.entryPrice !== undefined) position.entryPrice = data.entryPrice;
|
|
45
|
-
if (data.currentPrice !== undefined) position.currentPrice = data.currentPrice;
|
|
46
|
-
if (data.stopLoss !== undefined) position.stopLoss = data.stopLoss;
|
|
47
|
-
if (data.takeProfit !== undefined) position.takeProfit = data.takeProfit;
|
|
48
|
-
if (data.entryTime !== undefined) position.entryTime = data.entryTime;
|
|
49
|
-
if (data.unrealizedPnl !== undefined) position.unrealizedPnl = data.unrealizedPnl;
|
|
50
|
-
if (data.tickSize !== undefined) position.tickSize = data.tickSize;
|
|
51
|
-
if (data.tickValue !== undefined) position.tickValue = data.tickValue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Clear position state when flat
|
|
56
|
-
*/
|
|
57
|
-
function clearPosition() {
|
|
58
|
-
position.side = null;
|
|
59
|
-
position.symbol = '';
|
|
60
|
-
position.size = 0;
|
|
61
|
-
position.entryPrice = 0;
|
|
62
|
-
position.currentPrice = 0;
|
|
63
|
-
position.stopLoss = 0;
|
|
64
|
-
position.takeProfit = 0;
|
|
65
|
-
position.entryTime = 0;
|
|
66
|
-
position.unrealizedPnl = 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* GET MARKET FLOW LOG - When NOT in position
|
|
71
|
-
* Shows: OFI | Delta | Z-Score | Momentum | Volume Ratio
|
|
72
|
-
*/
|
|
73
|
-
function getMarketFlowLog() {
|
|
74
|
-
const { ofi, delta, zscore, momentum, buyVol, sellVol, tps, atr } = microstructure;
|
|
75
|
-
|
|
76
|
-
const absOfi = Math.abs(ofi || 0);
|
|
77
|
-
const absZ = Math.abs(zscore || 0);
|
|
78
|
-
const absMom = Math.abs(momentum || 0);
|
|
79
|
-
|
|
80
|
-
// Determine primary signal
|
|
81
|
-
let pool, category, signal;
|
|
82
|
-
|
|
83
|
-
// Priority: Mean Reversion > OFI > Momentum
|
|
84
|
-
if (absZ > 2.0) {
|
|
85
|
-
pool = zscore > 0 ? MR_OVERBOUGHT : MR_OVERSOLD;
|
|
86
|
-
category = zscore > 0 ? 'mr_short' : 'mr_long';
|
|
87
|
-
signal = 'MEAN_REV';
|
|
88
|
-
} else if (absOfi > 0.4) {
|
|
89
|
-
pool = ofi > 0 ? FLOW_AGGRESSIVE_BUY : FLOW_AGGRESSIVE_SELL;
|
|
90
|
-
category = ofi > 0 ? 'flow_buy' : 'flow_sell';
|
|
91
|
-
signal = ofi > 0 ? 'BUY_FLOW' : 'SELL_FLOW';
|
|
92
|
-
} else if (absMom > 3) {
|
|
93
|
-
pool = momentum > 0 ? MOM_ACCELERATING_UP : MOM_ACCELERATING_DOWN;
|
|
94
|
-
category = momentum > 0 ? 'mom_up' : 'mom_down';
|
|
95
|
-
signal = momentum > 0 ? 'MOM_UP' : 'MOM_DOWN';
|
|
96
|
-
} else {
|
|
97
|
-
pool = SCANNING_ACTIVE;
|
|
98
|
-
category = 'scanning';
|
|
99
|
-
signal = 'SCANNING';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const message = getVariedMessage(category, pool, 'Analyzing...');
|
|
103
|
-
|
|
104
|
-
// Build HF-grade metrics string
|
|
105
|
-
const ofiStr = `OFI:${formatNumber(ofi, 2)}`;
|
|
106
|
-
const deltaStr = `Δ:${formatNumber(delta, 0)}`;
|
|
107
|
-
const zStr = `Z:${formatNumber(zscore, 2)}`;
|
|
108
|
-
const momStr = `Mom:${formatNumber(momentum, 1)}`;
|
|
109
|
-
|
|
110
|
-
// Volume ratio
|
|
111
|
-
const totalVol = (buyVol || 0) + (sellVol || 0);
|
|
112
|
-
const buyPct = totalVol > 0 ? Math.round((buyVol / totalVol) * 100) : 50;
|
|
113
|
-
const volStr = `B/S:${buyPct}/${100 - buyPct}`;
|
|
114
|
-
|
|
115
|
-
const details = `${ofiStr} | ${deltaStr} | ${zStr} | ${momStr} | ${volStr}`;
|
|
116
|
-
|
|
117
|
-
return { message, details, signal };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* GET POSITION CONTEXT LOG - When IN position
|
|
122
|
-
* Shows: Side | P&L | Ticks to SL/TP | Hold Time | R-Multiple | Flow Alignment
|
|
123
|
-
*/
|
|
124
|
-
function getPositionContextLog() {
|
|
125
|
-
const { side, size, entryPrice, currentPrice, stopLoss, takeProfit, entryTime, unrealizedPnl, tickSize, tickValue } = position;
|
|
126
|
-
const { ofi, momentum, delta } = microstructure;
|
|
127
|
-
|
|
128
|
-
if (!side) return getMarketFlowLog();
|
|
129
|
-
|
|
130
|
-
// Calculate position Greeks
|
|
131
|
-
const holdMs = Date.now() - (entryTime || Date.now());
|
|
132
|
-
const holdSec = Math.floor(holdMs / 1000);
|
|
133
|
-
const holdStr = holdSec >= 60 ? `${Math.floor(holdSec / 60)}m${holdSec % 60}s` : `${holdSec}s`;
|
|
134
|
-
|
|
135
|
-
// Ticks from entry
|
|
136
|
-
const ticksFromEntry = tickSize > 0
|
|
137
|
-
? Math.round((currentPrice - entryPrice) / tickSize) * (side === 'LONG' ? 1 : -1)
|
|
138
|
-
: 0;
|
|
139
|
-
|
|
140
|
-
// Distance to SL/TP in ticks
|
|
141
|
-
let ticksToSL = 0, ticksToTP = 0, riskTicks = 0, rewardTicks = 0;
|
|
142
|
-
if (side === 'LONG' && stopLoss && takeProfit && tickSize > 0) {
|
|
143
|
-
ticksToSL = Math.round((currentPrice - stopLoss) / tickSize);
|
|
144
|
-
ticksToTP = Math.round((takeProfit - currentPrice) / tickSize);
|
|
145
|
-
riskTicks = Math.round((entryPrice - stopLoss) / tickSize);
|
|
146
|
-
rewardTicks = Math.round((takeProfit - entryPrice) / tickSize);
|
|
147
|
-
} else if (side === 'SHORT' && stopLoss && takeProfit && tickSize > 0) {
|
|
148
|
-
ticksToSL = Math.round((stopLoss - currentPrice) / tickSize);
|
|
149
|
-
ticksToTP = Math.round((currentPrice - takeProfit) / tickSize);
|
|
150
|
-
riskTicks = Math.round((stopLoss - entryPrice) / tickSize);
|
|
151
|
-
rewardTicks = Math.round((entryPrice - takeProfit) / tickSize);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// R-Multiple (how many R's of profit/loss)
|
|
155
|
-
const rMultiple = riskTicks > 0 ? (ticksFromEntry / riskTicks) : 0;
|
|
156
|
-
|
|
157
|
-
// Flow alignment score (-1 to +1)
|
|
158
|
-
let flowScore = 0;
|
|
159
|
-
if (side === 'LONG') {
|
|
160
|
-
flowScore = ((ofi || 0) + (momentum > 0 ? 0.3 : momentum < 0 ? -0.3 : 0) + (delta > 0 ? 0.2 : delta < 0 ? -0.2 : 0));
|
|
161
|
-
} else {
|
|
162
|
-
flowScore = (-(ofi || 0) + (momentum < 0 ? 0.3 : momentum > 0 ? -0.3 : 0) + (delta < 0 ? 0.2 : delta > 0 ? -0.2 : 0));
|
|
163
|
-
}
|
|
164
|
-
flowScore = Math.max(-1, Math.min(1, flowScore));
|
|
165
|
-
|
|
166
|
-
// Determine status message
|
|
167
|
-
let pool, category;
|
|
168
|
-
const pnl = unrealizedPnl || 0;
|
|
169
|
-
|
|
170
|
-
if (ticksToTP > 0 && ticksToTP <= 4) {
|
|
171
|
-
pool = POS_NEAR_TARGET;
|
|
172
|
-
category = 'near_tp';
|
|
173
|
-
} else if (ticksToSL > 0 && ticksToSL <= 4) {
|
|
174
|
-
pool = POS_NEAR_STOP;
|
|
175
|
-
category = 'near_sl';
|
|
176
|
-
} else if (pnl > 0) {
|
|
177
|
-
pool = POS_PROFIT_RUNNING;
|
|
178
|
-
category = 'pos_profit';
|
|
179
|
-
} else {
|
|
180
|
-
pool = POS_LOSS_MANAGING;
|
|
181
|
-
category = 'pos_loss';
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const statusMsg = getVariedMessage(category, pool, pnl >= 0 ? 'Running profit' : 'Managing risk');
|
|
185
|
-
|
|
186
|
-
// Build message
|
|
187
|
-
const arrow = side === 'LONG' ? '▲' : '▼';
|
|
188
|
-
const message = `${arrow} ${side} ${size}x | ${statusMsg}`;
|
|
189
|
-
|
|
190
|
-
// Build HF-grade details
|
|
191
|
-
const pnlStr = formatPnl(pnl);
|
|
192
|
-
const ticksStr = ticksFromEntry >= 0 ? `+${ticksFromEntry}t` : `${ticksFromEntry}t`;
|
|
193
|
-
const slStr = ticksToSL > 0 ? `SL:${ticksToSL}t` : 'SL:--';
|
|
194
|
-
const tpStr = ticksToTP > 0 ? `TP:${ticksToTP}t` : 'TP:--';
|
|
195
|
-
const rStr = `R:${rMultiple >= 0 ? '+' : ''}${rMultiple.toFixed(2)}`;
|
|
196
|
-
const flowStr = `Flow:${flowScore >= 0 ? '+' : ''}${flowScore.toFixed(2)}`;
|
|
197
|
-
|
|
198
|
-
const details = `${pnlStr} (${ticksStr}) | ${slStr} ${tpStr} | ${rStr} | ${flowStr} | ${holdStr}`;
|
|
199
|
-
|
|
200
|
-
return { message, details };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* GET VOLATILITY LOG
|
|
205
|
-
* Shows: ATR | Volatility Regime | Range Context
|
|
206
|
-
*/
|
|
207
|
-
function getVolatilityLog() {
|
|
208
|
-
const { atr, tps } = microstructure;
|
|
209
|
-
|
|
210
|
-
const isHigh = tps > 40 || atr > 2.0;
|
|
211
|
-
const isLow = tps < 10 || atr < 0.5;
|
|
212
|
-
|
|
213
|
-
let pool, category;
|
|
214
|
-
if (isHigh) {
|
|
215
|
-
pool = VOL_EXPANSION;
|
|
216
|
-
category = 'vol_high';
|
|
217
|
-
} else if (isLow) {
|
|
218
|
-
pool = VOL_COMPRESSION;
|
|
219
|
-
category = 'vol_low';
|
|
220
|
-
} else {
|
|
221
|
-
return { message: 'Normal volatility regime', details: `ATR:${atr?.toFixed(2) || '--'} | ${tps || '--'} tps` };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const message = getVariedMessage(category, pool, isHigh ? 'Vol expansion' : 'Vol compression');
|
|
225
|
-
const details = `ATR:${atr?.toFixed(2) || '--'} | ${tps || '--'} ticks/sec`;
|
|
226
|
-
|
|
227
|
-
return { message, details };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* GET FLOW ANALYSIS LOG - Detailed order flow breakdown
|
|
232
|
-
* Shows: OFI | Delta | Cumulative Delta | Volume Breakdown
|
|
233
|
-
*/
|
|
234
|
-
function getFlowAnalysisLog() {
|
|
235
|
-
const { ofi, delta, cumDelta, buyVol, sellVol } = microstructure;
|
|
236
|
-
|
|
237
|
-
const absOfi = Math.abs(ofi || 0);
|
|
238
|
-
let pool, category;
|
|
239
|
-
|
|
240
|
-
if (absOfi > 0.5) {
|
|
241
|
-
pool = ofi > 0 ? FLOW_AGGRESSIVE_BUY : FLOW_AGGRESSIVE_SELL;
|
|
242
|
-
category = ofi > 0 ? 'flow_agg_buy' : 'flow_agg_sell';
|
|
243
|
-
} else if (absOfi > 0.2) {
|
|
244
|
-
pool = ofi > 0 ? FLOW_AGGRESSIVE_BUY : FLOW_AGGRESSIVE_SELL;
|
|
245
|
-
category = ofi > 0 ? 'flow_mod_buy' : 'flow_mod_sell';
|
|
246
|
-
} else {
|
|
247
|
-
pool = FLOW_BALANCED;
|
|
248
|
-
category = 'flow_balanced';
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const message = getVariedMessage(category, pool, 'Analyzing flow');
|
|
252
|
-
|
|
253
|
-
// Volume breakdown
|
|
254
|
-
const totalVol = (buyVol || 0) + (sellVol || 0);
|
|
255
|
-
const buyPct = totalVol > 0 ? Math.round((buyVol / totalVol) * 100) : 50;
|
|
256
|
-
|
|
257
|
-
const ofiStr = `OFI:${formatNumber(ofi, 2)}`;
|
|
258
|
-
const deltaStr = `Δ:${formatNumber(delta, 0)}`;
|
|
259
|
-
const cumStr = `ΣΔ:${formatNumber(cumDelta, 0)}`;
|
|
260
|
-
const volStr = `Vol B/S:${buyPct}/${100 - buyPct}%`;
|
|
261
|
-
|
|
262
|
-
const details = `${ofiStr} | ${deltaStr} | ${cumStr} | ${volStr}`;
|
|
263
|
-
|
|
264
|
-
return { message, details };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* GET SCANNING LOG
|
|
269
|
-
*/
|
|
270
|
-
function getScanningLog(isScanning = true) {
|
|
271
|
-
const pool = SCANNING_ACTIVE;
|
|
272
|
-
const message = getVariedMessage('scanning', pool, 'Scanning...');
|
|
273
|
-
return { message, details: undefined };
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* MAIN ENTRY POINT: getSmartLog
|
|
278
|
-
* Automatically determines context and returns appropriate HF-grade log
|
|
279
|
-
*/
|
|
280
|
-
function getSmartLog(data = {}) {
|
|
281
|
-
// Update states if data provided
|
|
282
|
-
if (data.ofi !== undefined || data.delta !== undefined || data.zscore !== undefined) {
|
|
283
|
-
updateMicrostructure(data);
|
|
284
|
-
}
|
|
285
|
-
if (data.side !== undefined || data.entryPrice !== undefined) {
|
|
286
|
-
updatePosition(data);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Return appropriate log based on position state
|
|
290
|
-
if (data.inPosition || position.side) {
|
|
291
|
-
return getPositionContextLog();
|
|
292
|
-
} else {
|
|
293
|
-
return getMarketFlowLog();
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* GET MARKET STATE LOG - Legacy compatibility
|
|
299
|
-
* Wrapper around getMarketFlowLog
|
|
300
|
-
*/
|
|
301
|
-
function getMarketStateLog(ofi, zscore, momentum, delta) {
|
|
302
|
-
updateMicrostructure({ ofi, zscore, momentum, delta });
|
|
303
|
-
return getMarketFlowLog();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// =============================================================================
|
|
307
|
-
// LEGACY API - Backward Compatibility
|
|
308
|
-
// =============================================================================
|
|
309
|
-
|
|
310
|
-
const getMarketBiasLog = (direction, delta, ofi) => {
|
|
311
|
-
updateMicrostructure({ delta, ofi });
|
|
312
|
-
return getMarketFlowLog();
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
const getMomentumLog = (momentum, zscore) => {
|
|
316
|
-
updateMicrostructure({ momentum, zscore });
|
|
317
|
-
return getMarketFlowLog();
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
const getMeanReversionLog = (zscore) => {
|
|
321
|
-
updateMicrostructure({ zscore: zscore * 2.5 }); // Amplify to trigger MR message
|
|
322
|
-
return getMarketFlowLog();
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const getPositionUpdateLog = (side, size, unrealizedPnL, entryPrice, currentPrice, holdTime) => {
|
|
326
|
-
updatePosition({ side, size, unrealizedPnl: unrealizedPnL, entryPrice, currentPrice, entryTime: Date.now() - holdTime * 1000 });
|
|
327
|
-
return getPositionContextLog();
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const getSignalLog = (direction, symbol, confidence, strategy) => {
|
|
331
|
-
const pool = direction === 'LONG' ? FLOW_AGGRESSIVE_BUY : FLOW_AGGRESSIVE_SELL;
|
|
332
|
-
const message = getVariedMessage(`signal_${direction}`, pool, `${direction} signal`);
|
|
333
|
-
const arrow = direction === 'LONG' ? '▲' : '▼';
|
|
334
|
-
return {
|
|
335
|
-
message: `${arrow} ${message}`,
|
|
336
|
-
details: `${symbol} | Conf:${confidence.toFixed(0)}% | ${strategy}`,
|
|
337
|
-
};
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const getEntryLog = (direction, symbol, size, price) => {
|
|
341
|
-
const arrow = direction === 'LONG' ? '▲' : '▼';
|
|
342
|
-
return {
|
|
343
|
-
message: `${arrow} ${direction} initiated`,
|
|
344
|
-
details: `${size}x ${symbol} @ ${price.toFixed(2)}`,
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const getExitLog = (isProfit, symbol, size, price, pnl) => {
|
|
349
|
-
return {
|
|
350
|
-
message: isProfit ? 'Profit captured' : 'Loss contained',
|
|
351
|
-
details: `${size}x ${symbol} @ ${price.toFixed(2)} | ${formatPnl(pnl)}`,
|
|
352
|
-
};
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const getVolatilityLog_legacy = (isHigh, atr) => {
|
|
356
|
-
updateMicrostructure({ atr });
|
|
357
|
-
return getVolatilityLog();
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
// =============================================================================
|
|
361
|
-
// EXPORTS
|
|
362
|
-
// =============================================================================
|
|
363
|
-
|
|
364
|
-
module.exports = {
|
|
365
|
-
// HF-Grade API
|
|
366
|
-
getSmartLog,
|
|
367
|
-
getMarketFlowLog,
|
|
368
|
-
getPositionContextLog,
|
|
369
|
-
getFlowAnalysisLog,
|
|
370
|
-
getVolatilityLog,
|
|
371
|
-
getScanningLog,
|
|
372
|
-
|
|
373
|
-
// State management
|
|
374
|
-
updateMicrostructure,
|
|
375
|
-
updatePosition,
|
|
376
|
-
clearPosition,
|
|
377
|
-
|
|
378
|
-
// Legacy API (backward compatible)
|
|
379
|
-
getMarketStateLog,
|
|
380
|
-
getMarketBiasLog,
|
|
381
|
-
getMomentumLog,
|
|
382
|
-
getMeanReversionLog,
|
|
383
|
-
getPositionUpdateLog,
|
|
384
|
-
getSignalLog,
|
|
385
|
-
getEntryLog,
|
|
386
|
-
getExitLog,
|
|
387
|
-
};
|