hedgequantx 2.6.160 → 2.6.162

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.
Files changed (45) hide show
  1. package/package.json +1 -1
  2. package/src/menus/ai-agent-connect.js +181 -0
  3. package/src/menus/ai-agent-models.js +219 -0
  4. package/src/menus/ai-agent-oauth.js +292 -0
  5. package/src/menus/ai-agent-ui.js +141 -0
  6. package/src/menus/ai-agent.js +88 -1489
  7. package/src/pages/algo/copy-engine.js +449 -0
  8. package/src/pages/algo/copy-trading.js +11 -543
  9. package/src/pages/algo/smart-logs-data.js +218 -0
  10. package/src/pages/algo/smart-logs.js +9 -214
  11. package/src/pages/algo/ui-constants.js +144 -0
  12. package/src/pages/algo/ui-summary.js +184 -0
  13. package/src/pages/algo/ui.js +42 -526
  14. package/src/pages/stats-calculations.js +191 -0
  15. package/src/pages/stats-ui.js +381 -0
  16. package/src/pages/stats.js +14 -507
  17. package/src/services/ai/client-analysis.js +194 -0
  18. package/src/services/ai/client-models.js +333 -0
  19. package/src/services/ai/client.js +6 -489
  20. package/src/services/ai/index.js +2 -257
  21. package/src/services/ai/proxy-install.js +249 -0
  22. package/src/services/ai/proxy-manager.js +29 -411
  23. package/src/services/ai/proxy-remote.js +161 -0
  24. package/src/services/ai/strategy-supervisor.js +10 -765
  25. package/src/services/ai/supervisor-data.js +195 -0
  26. package/src/services/ai/supervisor-optimize.js +215 -0
  27. package/src/services/ai/supervisor-sync.js +178 -0
  28. package/src/services/ai/supervisor-utils.js +158 -0
  29. package/src/services/ai/supervisor.js +50 -515
  30. package/src/services/ai/validation.js +250 -0
  31. package/src/services/hqx-server-events.js +110 -0
  32. package/src/services/hqx-server-handlers.js +217 -0
  33. package/src/services/hqx-server-latency.js +136 -0
  34. package/src/services/hqx-server.js +51 -403
  35. package/src/services/position-constants.js +28 -0
  36. package/src/services/position-manager.js +105 -554
  37. package/src/services/position-momentum.js +206 -0
  38. package/src/services/projectx/accounts.js +142 -0
  39. package/src/services/projectx/index.js +40 -289
  40. package/src/services/projectx/trading.js +180 -0
  41. package/src/services/rithmic/handlers.js +2 -208
  42. package/src/services/rithmic/index.js +32 -542
  43. package/src/services/rithmic/latency-tracker.js +182 -0
  44. package/src/services/rithmic/specs.js +146 -0
  45. package/src/services/rithmic/trade-history.js +254 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @fileoverview Algo UI Session Summary Renderers
3
+ * Functions to render session summary screens
4
+ */
5
+
6
+ const chalk = require('chalk');
7
+ const { BOX, center } = require('./ui-constants');
8
+
9
+ /**
10
+ * Render Session Summary - Same style as dashboard
11
+ */
12
+ const renderSessionSummary = (stats, stopReason) => {
13
+ const W = 96;
14
+ const colL = Math.floor(W / 2) - 1;
15
+ const colR = W - colL - 1;
16
+ const version = require('../../../package.json').version;
17
+
18
+ console.clear();
19
+ console.log();
20
+
21
+ console.log(chalk.cyan(BOX.TOP + BOX.H.repeat(W) + BOX.TR));
22
+
23
+ // Logo
24
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██╗ ██╗███████╗██████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ █████╗ ███╗ ██╗████████╗') + chalk.yellow('██╗ ██╗') + ' ' + chalk.cyan(BOX.V));
25
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██║ ██║██╔════╝██╔══██╗██╔════╝ ██╔════╝██╔═══██╗██║ ██║██╔══██╗████╗ ██║╚══██╔══╝') + chalk.yellow('╚██╗██╔╝') + ' ' + chalk.cyan(BOX.V));
26
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ███████║█████╗ ██║ ██║██║ ███╗█████╗ ██║ ██║██║ ██║███████║██╔██╗ ██║ ██║ ') + chalk.yellow(' ╚███╔╝ ') + ' ' + chalk.cyan(BOX.V));
27
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██╔══██║██╔══╝ ██║ ██║██║ ██║██╔══╝ ██║▄▄ ██║██║ ██║██╔══██║██║╚██╗██║ ██║ ') + chalk.yellow(' ██╔██╗ ') + ' ' + chalk.cyan(BOX.V));
28
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██║ ██║███████╗██████╔╝╚██████╔╝███████╗╚██████╔╝╚██████╔╝██║ ██║██║ ╚████║ ██║ ') + chalk.yellow('██╔╝ ██╗') + ' ' + chalk.cyan(BOX.V));
29
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ') + chalk.yellow('╚═╝ ╚═╝') + ' ' + chalk.cyan(BOX.V));
30
+
31
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
32
+ console.log(chalk.cyan(BOX.V) + chalk.white(center(`PROP FUTURES ALGO TRADING v${version}`, W)) + chalk.cyan(BOX.V));
33
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
34
+ console.log(chalk.cyan(BOX.V) + chalk.yellow.bold(center('SESSION SUMMARY', W)) + chalk.cyan(BOX.V));
35
+
36
+ const GT = BOX.ML + BOX.H.repeat(colL) + BOX.TM + BOX.H.repeat(colR) + BOX.MR;
37
+ const GM = BOX.ML + BOX.H.repeat(colL) + BOX.MM + BOX.H.repeat(colR) + BOX.MR;
38
+
39
+ const row = (label1, value1, color1, label2, value2, color2) => {
40
+ const upperLabel1 = label1.toUpperCase();
41
+ const upperLabel2 = label2.toUpperCase();
42
+ const upperValue1 = String(value1).toUpperCase();
43
+ const upperValue2 = String(value2).toUpperCase();
44
+ const c1 = ` ${chalk.bold(upperLabel1)}: ${color1.bold(upperValue1)}`;
45
+ const c2 = ` ${chalk.bold(upperLabel2)}: ${color2.bold(upperValue2)}`;
46
+ const p1 = ` ${upperLabel1}: ${upperValue1}`;
47
+ const p2 = ` ${upperLabel2}: ${upperValue2}`;
48
+ const padded1 = c1 + ' '.repeat(Math.max(0, colL - p1.length));
49
+ const padded2 = c2 + ' '.repeat(Math.max(0, colR - p2.length));
50
+ console.log(chalk.cyan(BOX.V) + padded1 + chalk.cyan(BOX.VS) + padded2 + chalk.cyan(BOX.V));
51
+ };
52
+
53
+ console.log(chalk.cyan(GT));
54
+
55
+ const duration = stats.duration || '--';
56
+ const reasonColor = stopReason === 'target' ? chalk.green : stopReason === 'risk' ? chalk.red : chalk.yellow;
57
+ row('Stop Reason', (stopReason || 'manual').toUpperCase(), reasonColor, 'Duration', duration, chalk.white);
58
+
59
+ console.log(chalk.cyan(GM));
60
+
61
+ const winRate = stats.trades > 0 ? ((stats.wins / stats.trades) * 100).toFixed(1) + '%' : '0%';
62
+ row('Trades', String(stats.trades || 0), chalk.white, 'Win Rate', winRate, stats.wins >= stats.losses ? chalk.green : chalk.red);
63
+
64
+ console.log(chalk.cyan(GM));
65
+ row('Wins', String(stats.wins || 0), chalk.green, 'Losses', String(stats.losses || 0), chalk.red);
66
+
67
+ console.log(chalk.cyan(GM));
68
+
69
+ const pnl = stats.sessionPnl !== undefined ? stats.sessionPnl : (stats.pnl || 0);
70
+ const pnlStr = `${pnl >= 0 ? '+' : ''}$${Math.abs(pnl).toFixed(2)}`;
71
+ const pnlColor = pnl >= 0 ? chalk.green : chalk.red;
72
+ const targetStr = `$${(stats.target || 0).toFixed(2)}`;
73
+ row('Session P&L', pnlStr, pnlColor, 'TARGET', targetStr, chalk.cyan);
74
+
75
+ console.log(chalk.cyan(BOX.BOT + BOX.H.repeat(W) + BOX.BR));
76
+ console.log();
77
+ };
78
+
79
+ /**
80
+ * Render Multi-Symbol Session Summary
81
+ */
82
+ const renderMultiSymbolSummary = (stats, stopReason, symbolStats) => {
83
+ const W = 96;
84
+ const version = require('../../../package.json').version;
85
+
86
+ const centerCol = (text, width) => {
87
+ const pad = Math.floor((width - text.length) / 2);
88
+ return ' '.repeat(pad) + text + ' '.repeat(width - pad - text.length);
89
+ };
90
+
91
+ console.clear();
92
+ console.log();
93
+
94
+ console.log(chalk.cyan(BOX.TOP + BOX.H.repeat(W) + BOX.TR));
95
+
96
+ // Logo
97
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██╗ ██╗███████╗██████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ █████╗ ███╗ ██╗████████╗') + chalk.yellow('██╗ ██╗') + ' ' + chalk.cyan(BOX.V));
98
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██║ ██║██╔════╝██╔══██╗██╔════╝ ██╔════╝██╔═══██╗██║ ██║██╔══██╗████╗ ██║╚══██╔══╝') + chalk.yellow('╚██╗██╔╝') + ' ' + chalk.cyan(BOX.V));
99
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ███████║█████╗ ██║ ██║██║ ███╗█████╗ ██║ ██║██║ ██║███████║██╔██╗ ██║ ██║ ') + chalk.yellow(' ╚███╔╝ ') + ' ' + chalk.cyan(BOX.V));
100
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██╔══██║██╔══╝ ██║ ██║██║ ██║██╔══╝ ██║▄▄ ██║██║ ██║██╔══██║██║╚██╗██║ ██║ ') + chalk.yellow(' ██╔██╗ ') + ' ' + chalk.cyan(BOX.V));
101
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ██║ ██║███████╗██████╔╝╚██████╔╝███████╗╚██████╔╝╚██████╔╝██║ ██║██║ ╚████║ ██║ ') + chalk.yellow('██╔╝ ██╗') + ' ' + chalk.cyan(BOX.V));
102
+ console.log(chalk.cyan(BOX.V) + chalk.cyan(' ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ') + chalk.yellow('╚═╝ ╚═╝') + ' ' + chalk.cyan(BOX.V));
103
+
104
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
105
+ console.log(chalk.cyan(BOX.V) + chalk.white(center(`PROP FUTURES ALGO TRADING v${version}`, W)) + chalk.cyan(BOX.V));
106
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
107
+ console.log(chalk.cyan(BOX.V) + chalk.yellow.bold(center('MULTI-SYMBOL SESSION SUMMARY', W)) + chalk.cyan(BOX.V));
108
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
109
+
110
+ const colSymbol = 14;
111
+ const colTrades = 12;
112
+ const colWR = 14;
113
+ const colWins = 12;
114
+ const colLosses = 12;
115
+ const colPnL = W - colSymbol - colTrades - colWR - colWins - colLosses - 5;
116
+
117
+ const headerSymbol = centerCol('SYMBOL', colSymbol);
118
+ const headerTrades = centerCol('TRADES', colTrades);
119
+ const headerWR = centerCol('WIN RATE', colWR);
120
+ const headerWins = centerCol('WINS', colWins);
121
+ const headerLosses = centerCol('LOSSES', colLosses);
122
+ const headerPnL = centerCol('P&L', colPnL);
123
+
124
+ console.log(chalk.cyan(BOX.V) + chalk.bold.white(headerSymbol) + chalk.cyan(BOX.VS) +
125
+ chalk.bold.white(headerTrades) + chalk.cyan(BOX.VS) +
126
+ chalk.bold.white(headerWR) + chalk.cyan(BOX.VS) +
127
+ chalk.bold.white(headerWins) + chalk.cyan(BOX.VS) +
128
+ chalk.bold.white(headerLosses) + chalk.cyan(BOX.VS) +
129
+ chalk.bold.white(headerPnL) + chalk.cyan(BOX.V));
130
+
131
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
132
+
133
+ for (const [symbol, symStats] of Object.entries(symbolStats)) {
134
+ const winRate = symStats.trades > 0 ? ((symStats.wins / symStats.trades) * 100).toFixed(0) + '%' : '0%';
135
+ const pnl = symStats.pnl || 0;
136
+ const pnlStr = (pnl >= 0 ? '+$' : '-$') + Math.abs(pnl).toFixed(2);
137
+ const pnlColor = pnl >= 0 ? chalk.green : chalk.red;
138
+ const wrColor = symStats.wins >= symStats.losses ? chalk.green : chalk.red;
139
+
140
+ console.log(chalk.cyan(BOX.V) + chalk.yellow(centerCol(symbol, colSymbol)) + chalk.cyan(BOX.VS) +
141
+ chalk.white(centerCol(String(symStats.trades || 0), colTrades)) + chalk.cyan(BOX.VS) +
142
+ wrColor(centerCol(winRate, colWR)) + chalk.cyan(BOX.VS) +
143
+ chalk.green(centerCol(String(symStats.wins || 0), colWins)) + chalk.cyan(BOX.VS) +
144
+ chalk.red(centerCol(String(symStats.losses || 0), colLosses)) + chalk.cyan(BOX.VS) +
145
+ pnlColor.bold(centerCol(pnlStr, colPnL)) + chalk.cyan(BOX.V));
146
+ }
147
+
148
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
149
+
150
+ const totalWinRate = stats.trades > 0 ? ((stats.wins / stats.trades) * 100).toFixed(0) + '%' : '0%';
151
+ const totalPnl = stats.sessionPnl || 0;
152
+ const totalPnlStr = (totalPnl >= 0 ? '+$' : '-$') + Math.abs(totalPnl).toFixed(2);
153
+ const totalPnlColor = totalPnl >= 0 ? chalk.green : chalk.red;
154
+ const totalWrColor = stats.wins >= stats.losses ? chalk.green : chalk.red;
155
+
156
+ console.log(chalk.cyan(BOX.V) + chalk.bold.cyan(centerCol('TOTAL', colSymbol)) + chalk.cyan(BOX.VS) +
157
+ chalk.bold.white(centerCol(String(stats.trades || 0), colTrades)) + chalk.cyan(BOX.VS) +
158
+ totalWrColor.bold(centerCol(totalWinRate, colWR)) + chalk.cyan(BOX.VS) +
159
+ chalk.bold.green(centerCol(String(stats.wins || 0), colWins)) + chalk.cyan(BOX.VS) +
160
+ chalk.bold.red(centerCol(String(stats.losses || 0), colLosses)) + chalk.cyan(BOX.VS) +
161
+ totalPnlColor.bold(centerCol(totalPnlStr, colPnL)) + chalk.cyan(BOX.V));
162
+
163
+ console.log(chalk.cyan(BOX.ML + BOX.H.repeat(W) + BOX.MR));
164
+
165
+ const duration = stats.duration || '--';
166
+ const reasonColor = stopReason === 'target' ? chalk.green : stopReason === 'risk' ? chalk.red : chalk.yellow;
167
+ const reasonStr = (stopReason || 'manual').toUpperCase();
168
+ const infoPlain = `STOP: ${reasonStr} | DURATION: ${duration} | TARGET: $${(stats.target || 0).toFixed(2)} | RISK: $${(stats.risk || 0).toFixed(2)}`;
169
+
170
+ const padLeft = Math.floor((W - infoPlain.length) / 2);
171
+ const padRight = W - infoPlain.length - padLeft;
172
+ const infoColored = ' '.repeat(padLeft) +
173
+ chalk.bold('STOP') + ': ' + reasonColor.bold(reasonStr) + ' | ' +
174
+ chalk.bold('DURATION') + ': ' + chalk.white(duration) + ' | ' +
175
+ chalk.bold('TARGET') + ': ' + chalk.cyan('$' + (stats.target || 0).toFixed(2)) + ' | ' +
176
+ chalk.bold('RISK') + ': ' + chalk.red('$' + (stats.risk || 0).toFixed(2)) +
177
+ ' '.repeat(padRight);
178
+
179
+ console.log(chalk.cyan(BOX.V) + infoColored + chalk.cyan(BOX.V));
180
+ console.log(chalk.cyan(BOX.BOT + BOX.H.repeat(W) + BOX.BR));
181
+ console.log();
182
+ };
183
+
184
+ module.exports = { renderSessionSummary, renderMultiSymbolSummary };