hedgequantx 2.6.163 → 2.7.1

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 (146) hide show
  1. package/README.md +15 -88
  2. package/bin/cli.js +0 -11
  3. package/dist/lib/api.jsc +0 -0
  4. package/dist/lib/api2.jsc +0 -0
  5. package/dist/lib/core.jsc +0 -0
  6. package/dist/lib/core2.jsc +0 -0
  7. package/dist/lib/data.js +1 -1
  8. package/dist/lib/data.jsc +0 -0
  9. package/dist/lib/data2.jsc +0 -0
  10. package/dist/lib/decoder.jsc +0 -0
  11. package/dist/lib/m/mod1.jsc +0 -0
  12. package/dist/lib/m/mod2.jsc +0 -0
  13. package/dist/lib/n/r1.jsc +0 -0
  14. package/dist/lib/n/r2.jsc +0 -0
  15. package/dist/lib/n/r3.jsc +0 -0
  16. package/dist/lib/n/r4.jsc +0 -0
  17. package/dist/lib/n/r5.jsc +0 -0
  18. package/dist/lib/n/r6.jsc +0 -0
  19. package/dist/lib/n/r7.jsc +0 -0
  20. package/dist/lib/o/util1.jsc +0 -0
  21. package/dist/lib/o/util2.jsc +0 -0
  22. package/package.json +8 -5
  23. package/src/app.js +40 -162
  24. package/src/config/constants.js +31 -33
  25. package/src/config/propfirms.js +13 -217
  26. package/src/config/settings.js +0 -43
  27. package/src/lib/api.js +198 -0
  28. package/src/lib/api2.js +353 -0
  29. package/src/lib/core.js +539 -0
  30. package/src/lib/core2.js +341 -0
  31. package/src/lib/data.js +555 -0
  32. package/src/lib/data2.js +492 -0
  33. package/src/lib/decoder.js +599 -0
  34. package/src/lib/m/s1.js +804 -0
  35. package/src/lib/m/s2.js +34 -0
  36. package/src/lib/n/r1.js +454 -0
  37. package/src/lib/n/r2.js +514 -0
  38. package/src/lib/n/r3.js +631 -0
  39. package/src/lib/n/r4.js +401 -0
  40. package/src/lib/n/r5.js +335 -0
  41. package/src/lib/n/r6.js +425 -0
  42. package/src/lib/n/r7.js +530 -0
  43. package/src/lib/o/l1.js +44 -0
  44. package/src/lib/o/l2.js +427 -0
  45. package/src/lib/python-bridge.js +206 -0
  46. package/src/menus/connect.js +14 -176
  47. package/src/menus/dashboard.js +65 -110
  48. package/src/pages/accounts.js +18 -18
  49. package/src/pages/algo/copy-trading.js +210 -240
  50. package/src/pages/algo/index.js +41 -104
  51. package/src/pages/algo/one-account.js +386 -33
  52. package/src/pages/algo/ui.js +312 -151
  53. package/src/pages/orders.js +3 -3
  54. package/src/pages/positions.js +3 -3
  55. package/src/pages/stats/chart.js +74 -0
  56. package/src/pages/stats/display.js +228 -0
  57. package/src/pages/stats/index.js +236 -0
  58. package/src/pages/stats/metrics.js +213 -0
  59. package/src/pages/user.js +6 -6
  60. package/src/services/hqx-server/constants.js +55 -0
  61. package/src/services/hqx-server/index.js +401 -0
  62. package/src/services/hqx-server/latency.js +81 -0
  63. package/src/services/index.js +12 -3
  64. package/src/services/rithmic/accounts.js +7 -32
  65. package/src/services/rithmic/connection.js +1 -204
  66. package/src/services/rithmic/contracts.js +116 -99
  67. package/src/services/rithmic/handlers.js +21 -196
  68. package/src/services/rithmic/index.js +63 -120
  69. package/src/services/rithmic/market.js +31 -0
  70. package/src/services/rithmic/orders.js +5 -111
  71. package/src/services/rithmic/protobuf.js +384 -138
  72. package/src/services/session.js +22 -173
  73. package/src/ui/box.js +10 -18
  74. package/src/ui/index.js +1 -3
  75. package/src/ui/menu.js +1 -1
  76. package/src/utils/prompts.js +2 -2
  77. package/dist/lib/m/s1.js +0 -1
  78. package/src/menus/ai-agent-connect.js +0 -181
  79. package/src/menus/ai-agent-models.js +0 -219
  80. package/src/menus/ai-agent-oauth.js +0 -292
  81. package/src/menus/ai-agent-ui.js +0 -141
  82. package/src/menus/ai-agent.js +0 -484
  83. package/src/pages/algo/algo-config.js +0 -195
  84. package/src/pages/algo/algo-multi.js +0 -801
  85. package/src/pages/algo/algo-utils.js +0 -58
  86. package/src/pages/algo/copy-engine.js +0 -449
  87. package/src/pages/algo/custom-strategy.js +0 -459
  88. package/src/pages/algo/logger.js +0 -245
  89. package/src/pages/algo/smart-logs-data.js +0 -218
  90. package/src/pages/algo/smart-logs.js +0 -387
  91. package/src/pages/algo/ui-constants.js +0 -144
  92. package/src/pages/algo/ui-summary.js +0 -184
  93. package/src/pages/stats-calculations.js +0 -191
  94. package/src/pages/stats-ui.js +0 -381
  95. package/src/pages/stats.js +0 -339
  96. package/src/services/ai/client-analysis.js +0 -194
  97. package/src/services/ai/client-models.js +0 -333
  98. package/src/services/ai/client.js +0 -343
  99. package/src/services/ai/index.js +0 -384
  100. package/src/services/ai/oauth-anthropic.js +0 -265
  101. package/src/services/ai/oauth-gemini.js +0 -223
  102. package/src/services/ai/oauth-iflow.js +0 -269
  103. package/src/services/ai/oauth-openai.js +0 -233
  104. package/src/services/ai/oauth-qwen.js +0 -279
  105. package/src/services/ai/providers/direct-providers.js +0 -323
  106. package/src/services/ai/providers/index.js +0 -62
  107. package/src/services/ai/providers/other-providers.js +0 -104
  108. package/src/services/ai/proxy-install.js +0 -249
  109. package/src/services/ai/proxy-manager.js +0 -494
  110. package/src/services/ai/proxy-remote.js +0 -161
  111. package/src/services/ai/strategy-supervisor.js +0 -1312
  112. package/src/services/ai/supervisor-data.js +0 -195
  113. package/src/services/ai/supervisor-optimize.js +0 -215
  114. package/src/services/ai/supervisor-sync.js +0 -178
  115. package/src/services/ai/supervisor-utils.js +0 -158
  116. package/src/services/ai/supervisor.js +0 -484
  117. package/src/services/ai/validation.js +0 -250
  118. package/src/services/hqx-server-events.js +0 -110
  119. package/src/services/hqx-server-handlers.js +0 -217
  120. package/src/services/hqx-server-latency.js +0 -136
  121. package/src/services/hqx-server.js +0 -403
  122. package/src/services/position-constants.js +0 -28
  123. package/src/services/position-exit-logic.js +0 -174
  124. package/src/services/position-manager.js +0 -438
  125. package/src/services/position-momentum.js +0 -206
  126. package/src/services/projectx/accounts.js +0 -142
  127. package/src/services/projectx/index.js +0 -443
  128. package/src/services/projectx/market.js +0 -172
  129. package/src/services/projectx/stats.js +0 -110
  130. package/src/services/projectx/trading.js +0 -180
  131. package/src/services/rithmic/latency-tracker.js +0 -182
  132. package/src/services/rithmic/market-data-decoders.js +0 -229
  133. package/src/services/rithmic/market-data.js +0 -272
  134. package/src/services/rithmic/orders-fast.js +0 -246
  135. package/src/services/rithmic/proto-decoders.js +0 -403
  136. package/src/services/rithmic/specs.js +0 -146
  137. package/src/services/rithmic/trade-history.js +0 -254
  138. package/src/services/session-history.js +0 -475
  139. package/src/services/strategy/hft-signal-calc.js +0 -147
  140. package/src/services/strategy/hft-tick.js +0 -407
  141. package/src/services/strategy/recovery-math.js +0 -402
  142. package/src/services/tradovate/constants.js +0 -109
  143. package/src/services/tradovate/index.js +0 -392
  144. package/src/services/tradovate/market.js +0 -47
  145. package/src/services/tradovate/orders.js +0 -145
  146. package/src/services/tradovate/websocket.js +0 -97
@@ -1,381 +0,0 @@
1
- /**
2
- * @fileoverview Stats UI Rendering
3
- * UI rendering functions for stats page
4
- */
5
-
6
- const chalk = require('chalk');
7
- const asciichart = require('asciichart');
8
- const { drawBoxHeader, drawBoxFooter, draw2ColHeader, fmtRow } = require('../ui');
9
-
10
- /**
11
- * Render AI Supervision section
12
- * @param {Array} aiAgents - Connected AI agents
13
- * @param {Array} supervisionStatus - Status from AISupervisor
14
- * @param {Object} AISupervisor - AISupervisor module
15
- * @param {number} boxWidth - Box width
16
- * @param {number} col1 - Column 1 width
17
- * @param {number} col2 - Column 2 width
18
- */
19
- const renderAISupervision = (aiAgents, supervisionStatus, AISupervisor, boxWidth, col1, col2) => {
20
- drawBoxHeader('AI SUPERVISION', boxWidth);
21
- draw2ColHeader('AGENTS', 'PERFORMANCE', boxWidth);
22
-
23
- const isConsensusMode = aiAgents.length >= 2;
24
- const agentMode = isConsensusMode ? 'CONSENSUS' : 'INDIVIDUAL';
25
- const modeColor = isConsensusMode ? chalk.magenta : chalk.cyan;
26
- const consensusData = isConsensusMode ? AISupervisor.getConsensus() : null;
27
-
28
- let totalSessionTime = 0;
29
- for (const status of supervisionStatus) {
30
- if (status.active) {
31
- totalSessionTime += status.duration || 0;
32
- }
33
- }
34
-
35
- const sessionTimeStr = totalSessionTime > 0
36
- ? Math.floor(totalSessionTime / 60000) + 'm ' + Math.floor((totalSessionTime % 60000) / 1000) + 's'
37
- : 'INACTIVE';
38
-
39
- const supervisionData = AISupervisor.getAggregatedData();
40
- const supervisedAccounts = supervisionData.totalAccounts;
41
- const supervisedPnL = supervisionData.totalPnL;
42
- const maxAgentNameLen = col1 - 20;
43
-
44
- const perfData = [
45
- { label: 'SUPERVISED ACCOUNTS:', value: chalk.white(String(supervisedAccounts)) },
46
- { label: 'SUPERVISED P&L:', value: supervisedPnL >= 0 ? chalk.green('$' + supervisedPnL.toFixed(2)) : chalk.red('$' + supervisedPnL.toFixed(2)) },
47
- { label: 'POSITIONS:', value: chalk.white(String(supervisionData.totalPositions)) },
48
- { label: 'OPEN ORDERS:', value: chalk.white(String(supervisionData.totalOrders)) },
49
- { label: 'TRADES TODAY:', value: chalk.white(String(supervisionData.totalTrades)) }
50
- ];
51
-
52
- const agentsData = [
53
- { label: 'CONNECTED:', value: chalk.green(String(aiAgents.length) + ' AGENT' + (aiAgents.length > 1 ? 'S' : '')) },
54
- { label: 'MODE:', value: modeColor(agentMode) },
55
- { label: 'SESSION:', value: sessionTimeStr === 'INACTIVE' ? chalk.yellow(sessionTimeStr) : chalk.white(sessionTimeStr) }
56
- ];
57
-
58
- if (isConsensusMode && consensusData) {
59
- const isUnanimous = consensusData.isUnanimous;
60
- const consensusAction = consensusData.action || 'PENDING';
61
- const consensusDisplay = isUnanimous
62
- ? chalk.green(consensusAction + ' (UNANIMOUS)')
63
- : chalk.yellow(consensusAction + ' (DISAGREEMENT)');
64
- agentsData.push({ label: 'DECISION:', value: consensusDisplay });
65
- } else if (isConsensusMode) {
66
- agentsData.push({ label: 'DECISION:', value: chalk.white('WAITING...') });
67
- }
68
-
69
- aiAgents.forEach((agent, idx) => {
70
- const agentLabel = idx === 0 ? 'AGENTS:' : '';
71
- const agentName = agent.name.length > maxAgentNameLen
72
- ? agent.name.substring(0, maxAgentNameLen - 4) + '..'
73
- : agent.name;
74
- const agentDisplay = chalk.green('● ') + chalk.white(agentName);
75
- agentsData.push({ label: agentLabel, value: agentDisplay });
76
- });
77
-
78
- const maxRows = Math.max(agentsData.length, perfData.length);
79
- for (let i = 0; i < maxRows; i++) {
80
- const leftData = agentsData[i] || { label: '', value: '' };
81
- const rightData = perfData[i] || { label: '', value: '' };
82
- console.log(chalk.cyan('\u2551') + fmtRow(leftData.label, leftData.value, col1) + chalk.cyan('\u2502') + fmtRow(rightData.label, rightData.value, col2) + chalk.cyan('\u2551'));
83
- }
84
-
85
- drawBoxFooter(boxWidth);
86
- };
87
-
88
- /**
89
- * Render AI Behavior section
90
- * @param {Object} StrategySupervisor - StrategySupervisor module
91
- * @param {number} boxWidth - Box width
92
- */
93
- const renderAIBehavior = (StrategySupervisor, boxWidth) => {
94
- const behaviorData = StrategySupervisor.getBehaviorHistory(100);
95
- const learningStats = StrategySupervisor.getLearningStats();
96
-
97
- console.log();
98
- drawBoxHeader('AI AGENTS BEHAVIOR', boxWidth);
99
-
100
- const behaviorInnerWidth = boxWidth - 2;
101
- const behaviorCounts = { AGGRESSIVE: 0, NORMAL: 0, CAUTIOUS: 0, PAUSE: 0 };
102
- const valueToAction = { 3: 'AGGRESSIVE', 2: 'NORMAL', 1: 'CAUTIOUS', 0: 'PAUSE' };
103
-
104
- if (behaviorData.values.length > 0) {
105
- for (const val of behaviorData.values) {
106
- const action = valueToAction[Math.round(val)] || 'NORMAL';
107
- behaviorCounts[action]++;
108
- }
109
- } else {
110
- behaviorCounts.NORMAL = 1;
111
- }
112
-
113
- const total = Object.values(behaviorCounts).reduce((a, b) => a + b, 0) || 1;
114
- const percentages = {
115
- AGGRESSIVE: Math.round((behaviorCounts.AGGRESSIVE / total) * 100),
116
- NORMAL: Math.round((behaviorCounts.NORMAL / total) * 100),
117
- CAUTIOUS: Math.round((behaviorCounts.CAUTIOUS / total) * 100),
118
- PAUSE: Math.round((behaviorCounts.PAUSE / total) * 100)
119
- };
120
-
121
- const currentValue = behaviorData.values.length > 0 ? behaviorData.values[behaviorData.values.length - 1] : 2;
122
- const currentAction = valueToAction[Math.round(currentValue)] || 'NORMAL';
123
-
124
- const barColors = {
125
- AGGRESSIVE: chalk.green,
126
- NORMAL: chalk.cyan,
127
- CAUTIOUS: chalk.yellow,
128
- PAUSE: chalk.red
129
- };
130
-
131
- const barLabels = ['AGGRESSIVE', 'NORMAL', 'CAUTIOUS', 'PAUSE'];
132
- const shortLabels = ['AGR', 'NOR', 'CAU', 'PAU'];
133
- const labelWidth = 6;
134
- const pctWidth = 6;
135
- const spacing = 4;
136
-
137
- const availableWidth = behaviorInnerWidth - (labelWidth * 4) - (pctWidth * 4) - (spacing * 3) - 4;
138
- const maxBarWidth = Math.floor(availableWidth / 4);
139
-
140
- const barWidths = {
141
- AGGRESSIVE: Math.round((percentages.AGGRESSIVE / 100) * maxBarWidth),
142
- NORMAL: Math.round((percentages.NORMAL / 100) * maxBarWidth),
143
- CAUTIOUS: Math.round((percentages.CAUTIOUS / 100) * maxBarWidth),
144
- PAUSE: Math.round((percentages.PAUSE / 100) * maxBarWidth)
145
- };
146
-
147
- for (let i = 0; i < 4; i++) {
148
- const label = barLabels[i];
149
- const shortLabel = shortLabels[i];
150
- const pct = percentages[label];
151
- const barWidth = barWidths[label];
152
- const color = barColors[label];
153
- const isCurrent = label === currentAction;
154
-
155
- const block = isCurrent ? '█' : '▓';
156
- const bar = barWidth > 0 ? color(block.repeat(barWidth)) : '';
157
- const emptySpace = ' '.repeat(Math.max(0, maxBarWidth - barWidth));
158
-
159
- const labelPart = ' ' + color(shortLabel.padEnd(labelWidth));
160
- const barPart = bar + emptySpace;
161
- const pctPart = chalk.white((pct + '%').padStart(pctWidth));
162
-
163
- let line = labelPart + barPart + pctPart;
164
- const lineLen = line.replace(/\x1b\[[0-9;]*m/g, '').length;
165
- line += ' '.repeat(Math.max(0, behaviorInnerWidth - lineLen));
166
- console.log(chalk.cyan('\u2551') + line + chalk.cyan('\u2551'));
167
- }
168
-
169
- console.log(chalk.cyan('\u2551') + ' '.repeat(behaviorInnerWidth) + chalk.cyan('\u2551'));
170
-
171
- const statsLine = ` CURRENT: ${barColors[currentAction](currentAction)} | SESSION PATTERNS: ${learningStats.patternsLearned.total} (${learningStats.patternsLearned.winning}W/${learningStats.patternsLearned.losing}L) | OPTIMIZATIONS: ${learningStats.optimizations}`;
172
- const statsLen = statsLine.replace(/\x1b\[[0-9;]*m/g, '').length;
173
- console.log(chalk.cyan('\u2551') + statsLine + ' '.repeat(Math.max(0, behaviorInnerWidth - statsLen)) + chalk.cyan('\u2551'));
174
-
175
- const lifetimeStats = StrategySupervisor.getLifetimeStats();
176
- if (lifetimeStats.totalSessions > 0) {
177
- const lifetimeLine = ` LIFETIME: ${lifetimeStats.totalSessions} sessions | ${lifetimeStats.totalTrades} trades | WR: ${lifetimeStats.lifetimeWinRate} | P&L: $${lifetimeStats.lifetimePnL.toFixed(2)} | ${lifetimeStats.patternsLearned.winning + lifetimeStats.patternsLearned.losing} patterns learned`;
178
- const lifetimeLen = lifetimeLine.length;
179
- console.log(chalk.cyan('\u2551') + chalk.magenta(lifetimeLine) + ' '.repeat(Math.max(0, behaviorInnerWidth - lifetimeLen)) + chalk.cyan('\u2551'));
180
- }
181
-
182
- drawBoxFooter(boxWidth);
183
- };
184
-
185
- /**
186
- * Render Equity Curve section
187
- * @param {Array} allTrades - All trades
188
- * @param {number} totalStartingBalance - Starting balance
189
- * @param {Object} connectionTypes - Connection type counts
190
- * @param {number} boxWidth - Box width
191
- */
192
- const renderEquityCurve = (allTrades, totalStartingBalance, connectionTypes, boxWidth) => {
193
- drawBoxHeader('EQUITY CURVE', boxWidth);
194
-
195
- const chartInnerWidth = boxWidth - 2;
196
-
197
- if (allTrades.length > 0) {
198
- const yAxisWidth = 10;
199
- const chartAreaWidth = chartInnerWidth - yAxisWidth - 4;
200
-
201
- let equityData = [totalStartingBalance || 100000];
202
- let eqVal = equityData[0];
203
- allTrades.forEach(trade => {
204
- eqVal += (trade.profitAndLoss || trade.pnl || 0);
205
- equityData.push(eqVal);
206
- });
207
-
208
- const maxDataPoints = chartAreaWidth - 5;
209
- if (equityData.length > maxDataPoints) {
210
- const step = Math.ceil(equityData.length / maxDataPoints);
211
- equityData = equityData.filter((_, i) => i % step === 0);
212
- }
213
-
214
- const chartConfig = {
215
- height: 10,
216
- colors: [equityData[equityData.length - 1] < equityData[0] ? asciichart.red : asciichart.green],
217
- format: (x) => ('$' + (x / 1000).toFixed(0) + 'K').padStart(yAxisWidth)
218
- };
219
-
220
- const chart = asciichart.plot(equityData, chartConfig);
221
- chart.split('\n').forEach(line => {
222
- let chartLine = ' ' + line;
223
- const len = chartLine.replace(/\x1b\[[0-9;]*m/g, '').length;
224
- if (len < chartInnerWidth) chartLine += ' '.repeat(chartInnerWidth - len);
225
- console.log(chalk.cyan('\u2551') + chartLine + chalk.cyan('\u2551'));
226
- });
227
- } else {
228
- const msg = connectionTypes.rithmic > 0
229
- ? ' NO TRADE HISTORY (RITHMIC DOES NOT PROVIDE TRADE HISTORY API)'
230
- : ' NO TRADE DATA AVAILABLE';
231
- console.log(chalk.cyan('\u2551') + chalk.gray(msg) + ' '.repeat(Math.max(0, chartInnerWidth - msg.length)) + chalk.cyan('\u2551'));
232
- }
233
-
234
- drawBoxFooter(boxWidth);
235
- };
236
-
237
- /**
238
- * Render Trades History section
239
- * @param {Array} completedTrades - Completed trades (P&L != 0)
240
- * @param {Object} connectionTypes - Connection type counts
241
- * @param {Function} extractSymbol - Symbol extraction function
242
- * @param {number} boxWidth - Box width
243
- */
244
- const renderTradesHistory = (completedTrades, connectionTypes, extractSymbol, boxWidth) => {
245
- drawBoxHeader('TRADES HISTORY', boxWidth);
246
-
247
- const innerWidth = boxWidth - 2;
248
-
249
- if (completedTrades.length > 0) {
250
- const colTime = 9;
251
- const colSymbol = 10;
252
- const colSide = 6;
253
- const colPnl = 10;
254
- const colFees = 8;
255
- const colNet = 10;
256
- const fixedCols = colTime + colSymbol + colSide + colPnl + colFees + colNet;
257
- const separatorChars = 6 * 2;
258
- const leadingSpace = 1;
259
- const colAccount = innerWidth - fixedCols - separatorChars - leadingSpace;
260
-
261
- const headerParts = [
262
- ' ' + 'TIME'.padEnd(colTime),
263
- 'SYMBOL'.padEnd(colSymbol),
264
- 'SIDE'.padEnd(colSide),
265
- 'P&L'.padEnd(colPnl),
266
- 'FEES'.padEnd(colFees),
267
- 'NET'.padEnd(colNet),
268
- 'ACCOUNT'.padEnd(colAccount)
269
- ];
270
- const header = headerParts.join('| ');
271
- console.log(chalk.cyan('\u2551') + chalk.white(header) + chalk.cyan('\u2551'));
272
- console.log(chalk.cyan('\u255F') + chalk.cyan('\u2500'.repeat(innerWidth)) + chalk.cyan('\u2562'));
273
-
274
- const sortedTrades = [...completedTrades].sort((a, b) => {
275
- const timeA = new Date(a.creationTimestamp || a.timestamp || 0).getTime();
276
- const timeB = new Date(b.creationTimestamp || b.timestamp || 0).getTime();
277
- return timeB - timeA;
278
- });
279
-
280
- for (const trade of sortedTrades) {
281
- const timestamp = trade.creationTimestamp || trade.timestamp;
282
- const time = timestamp ? new Date(timestamp).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true }) : '--:--';
283
- const symbol = extractSymbol(trade.contractId || trade.symbol);
284
- const pnl = trade.profitAndLoss || trade.pnl || 0;
285
- const fees = trade.fees || trade.commission || 0;
286
- const netPnl = pnl - Math.abs(fees);
287
-
288
- const pnlText = pnl >= 0 ? `+$${pnl.toFixed(0)}` : `-$${Math.abs(pnl).toFixed(0)}`;
289
- const feesText = fees !== 0 ? `-$${Math.abs(fees).toFixed(2)}` : '$0';
290
- const netText = netPnl >= 0 ? `+$${netPnl.toFixed(0)}` : `-$${Math.abs(netPnl).toFixed(0)}`;
291
-
292
- const exitSide = trade.side;
293
- const tradeSide = exitSide === 0 ? 'SHORT' : 'LONG';
294
- const accountName = (trade.accountName || 'N/A').substring(0, colAccount - 3);
295
-
296
- const timeStr = time.padEnd(colTime);
297
- const symbolStr = symbol.padEnd(colSymbol);
298
- const sideStr = tradeSide.padEnd(colSide);
299
- const pnlStr = pnlText.padEnd(colPnl);
300
- const feesStr = feesText.padEnd(colFees);
301
- const netStr = netText.padEnd(colNet);
302
- const accountStr = accountName.padEnd(colAccount);
303
-
304
- const pnlColored = pnl >= 0 ? chalk.green(pnlStr) : chalk.red(pnlStr);
305
- const feesColored = chalk.yellow(feesStr);
306
- const netColored = netPnl >= 0 ? chalk.green(netStr) : chalk.red(netStr);
307
- const sideColored = tradeSide === 'LONG' ? chalk.green(sideStr) : chalk.red(sideStr);
308
-
309
- const rowParts = [
310
- ' ' + timeStr,
311
- symbolStr,
312
- sideColored,
313
- pnlColored,
314
- feesColored,
315
- netColored,
316
- accountStr
317
- ];
318
- const row = rowParts.join('| ');
319
- console.log(chalk.cyan('\u2551') + row + chalk.cyan('\u2551'));
320
- }
321
-
322
- if (sortedTrades.length === 0) {
323
- const msg = ' NO COMPLETED TRADES YET';
324
- console.log(chalk.cyan('\u2551') + chalk.gray(msg.padEnd(innerWidth)) + chalk.cyan('\u2551'));
325
- }
326
- } else {
327
- const msg = connectionTypes.rithmic > 0
328
- ? ' NO TRADE HISTORY (RITHMIC API LIMITATION)'
329
- : ' NO TRADE HISTORY AVAILABLE';
330
- console.log(chalk.cyan('\u2551') + chalk.gray(msg.padEnd(innerWidth)) + chalk.cyan('\u2551'));
331
- }
332
-
333
- drawBoxFooter(boxWidth);
334
- };
335
-
336
- /**
337
- * Render HQX Score section
338
- * @param {Object} hqxData - HQX score data from calculateHQXScore
339
- * @param {number} boxWidth - Box width
340
- */
341
- const renderHQXScore = (hqxData, boxWidth) => {
342
- drawBoxHeader('HQX SCORE', boxWidth);
343
-
344
- const innerWidth = boxWidth - 2;
345
- const { hqxScore, scoreGrade, metrics: metricsDisplay } = hqxData;
346
- const scoreColor = hqxScore >= 70 ? chalk.green : hqxScore >= 50 ? chalk.yellow : chalk.red;
347
-
348
- const makeBar = (score, width = 20) => {
349
- const filled = Math.round((score / 100) * width);
350
- const empty = width - filled;
351
- const color = score >= 70 ? chalk.green : score >= 50 ? chalk.yellow : chalk.red;
352
- return color('\u2588'.repeat(filled)) + chalk.gray('\u2591'.repeat(empty));
353
- };
354
-
355
- const barWidth = 30;
356
- const labelWidth = 18;
357
-
358
- const overallLine = ` OVERALL SCORE: ${scoreColor(String(hqxScore))} / 100 [GRADE: ${scoreColor(scoreGrade)}]`;
359
- const overallVisLen = overallLine.replace(/\x1b\[[0-9;]*m/g, '').length;
360
- console.log(chalk.cyan('\u2551') + overallLine + ' '.repeat(innerWidth - overallVisLen) + chalk.cyan('\u2551'));
361
- console.log(chalk.cyan('\u2551') + chalk.gray('\u2500'.repeat(innerWidth)) + chalk.cyan('\u2551'));
362
-
363
- for (const metric of metricsDisplay) {
364
- const label = (' ' + metric.name + ':').padEnd(labelWidth);
365
- const bar = makeBar(metric.score, barWidth);
366
- const pct = (metric.score.toFixed(0) + '%').padStart(5);
367
- const line = label + bar + ' ' + pct;
368
- const visLen = line.replace(/\x1b\[[0-9;]*m/g, '').length;
369
- console.log(chalk.cyan('\u2551') + chalk.white(label) + bar + ' ' + chalk.white(pct) + ' '.repeat(innerWidth - visLen) + chalk.cyan('\u2551'));
370
- }
371
-
372
- drawBoxFooter(boxWidth);
373
- };
374
-
375
- module.exports = {
376
- renderAISupervision,
377
- renderAIBehavior,
378
- renderEquityCurve,
379
- renderTradesHistory,
380
- renderHQXScore,
381
- };