hedgequantx 2.6.161 → 2.6.163

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 (57) 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/providers/direct-providers.js +323 -0
  22. package/src/services/ai/providers/index.js +8 -472
  23. package/src/services/ai/providers/other-providers.js +104 -0
  24. package/src/services/ai/proxy-install.js +249 -0
  25. package/src/services/ai/proxy-manager.js +29 -411
  26. package/src/services/ai/proxy-remote.js +161 -0
  27. package/src/services/ai/supervisor-optimize.js +215 -0
  28. package/src/services/ai/supervisor-sync.js +178 -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-exit-logic.js +174 -0
  37. package/src/services/position-manager.js +90 -629
  38. package/src/services/position-momentum.js +206 -0
  39. package/src/services/projectx/accounts.js +142 -0
  40. package/src/services/projectx/index.js +40 -289
  41. package/src/services/projectx/trading.js +180 -0
  42. package/src/services/rithmic/contracts.js +218 -0
  43. package/src/services/rithmic/handlers.js +2 -208
  44. package/src/services/rithmic/index.js +28 -712
  45. package/src/services/rithmic/latency-tracker.js +182 -0
  46. package/src/services/rithmic/market-data-decoders.js +229 -0
  47. package/src/services/rithmic/market-data.js +1 -278
  48. package/src/services/rithmic/orders-fast.js +246 -0
  49. package/src/services/rithmic/orders.js +1 -251
  50. package/src/services/rithmic/proto-decoders.js +403 -0
  51. package/src/services/rithmic/protobuf.js +7 -443
  52. package/src/services/rithmic/specs.js +146 -0
  53. package/src/services/rithmic/trade-history.js +254 -0
  54. package/src/services/strategy/hft-signal-calc.js +147 -0
  55. package/src/services/strategy/hft-tick.js +33 -133
  56. package/src/services/tradovate/index.js +6 -119
  57. package/src/services/tradovate/orders.js +145 -0
@@ -0,0 +1,249 @@
1
+ /**
2
+ * @fileoverview CLIProxyAPI Installation
3
+ *
4
+ * Downloads, extracts, and configures CLIProxyAPI binary
5
+ */
6
+
7
+ const https = require('https');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+ const { exec } = require('child_process');
12
+
13
+ // Configuration
14
+ const PROXY_VERSION = 'v6.6.84';
15
+ const PROXY_PORT = 8317;
16
+ const PROXY_DIR = path.join(os.homedir(), '.hqx', 'proxy');
17
+ const PROXY_BIN = path.join(PROXY_DIR, process.platform === 'win32' ? 'cli-proxy-api.exe' : 'cli-proxy-api');
18
+ const PROXY_CONFIG = path.join(PROXY_DIR, 'config.yaml');
19
+ const PROXY_AUTH_DIR = path.join(PROXY_DIR, 'auths');
20
+ const API_KEY = 'hqx-local-key';
21
+ const MANAGEMENT_KEY = 'hqx-mgmt-key';
22
+
23
+ /**
24
+ * Get download URL for current platform
25
+ */
26
+ const getDownloadUrl = () => {
27
+ const platform = process.platform;
28
+ const arch = process.arch;
29
+
30
+ let osName, archName, ext;
31
+
32
+ if (platform === 'darwin') {
33
+ osName = 'darwin';
34
+ archName = arch === 'arm64' ? 'arm64' : 'amd64';
35
+ ext = 'tar.gz';
36
+ } else if (platform === 'win32') {
37
+ osName = 'windows';
38
+ archName = arch === 'arm64' ? 'arm64' : 'amd64';
39
+ ext = 'zip';
40
+ } else {
41
+ osName = 'linux';
42
+ archName = arch === 'arm64' ? 'arm64' : 'amd64';
43
+ ext = 'tar.gz';
44
+ }
45
+
46
+ const version = PROXY_VERSION.replace('v', '');
47
+ return `https://github.com/router-for-me/CLIProxyAPI/releases/download/${PROXY_VERSION}/CLIProxyAPI_${version}_${osName}_${archName}.${ext}`;
48
+ };
49
+
50
+ /**
51
+ * Check if CLIProxyAPI binary exists
52
+ */
53
+ const isInstalled = () => {
54
+ return fs.existsSync(PROXY_BIN);
55
+ };
56
+
57
+ /**
58
+ * Download file from URL
59
+ */
60
+ const downloadFile = (url, dest) => {
61
+ return new Promise((resolve, reject) => {
62
+ const file = fs.createWriteStream(dest);
63
+
64
+ const request = (url) => {
65
+ https.get(url, (res) => {
66
+ if (res.statusCode === 302 || res.statusCode === 301) {
67
+ request(res.headers.location);
68
+ return;
69
+ }
70
+
71
+ if (res.statusCode !== 200) {
72
+ reject(new Error(`HTTP ${res.statusCode}`));
73
+ return;
74
+ }
75
+
76
+ res.pipe(file);
77
+ file.on('finish', () => {
78
+ file.close();
79
+ resolve();
80
+ });
81
+ }).on('error', (err) => {
82
+ fs.unlink(dest, () => {});
83
+ reject(err);
84
+ });
85
+ };
86
+
87
+ request(url);
88
+ });
89
+ };
90
+
91
+ /**
92
+ * Extract tar.gz archive
93
+ */
94
+ const extractTarGz = (archive, dest) => {
95
+ return new Promise((resolve, reject) => {
96
+ exec(`tar -xzf "${archive}" -C "${dest}"`, (err) => {
97
+ if (err) reject(err);
98
+ else resolve();
99
+ });
100
+ });
101
+ };
102
+
103
+ /**
104
+ * Extract zip archive (Windows)
105
+ */
106
+ const extractZip = (archive, dest) => {
107
+ return new Promise((resolve, reject) => {
108
+ exec(`powershell -command "Expand-Archive -Path '${archive}' -DestinationPath '${dest}' -Force"`, (err) => {
109
+ if (err) reject(err);
110
+ else resolve();
111
+ });
112
+ });
113
+ };
114
+
115
+ /**
116
+ * Generate config file content
117
+ */
118
+ const getConfigContent = () => {
119
+ return `port: ${PROXY_PORT}
120
+ auth-dir: "${PROXY_AUTH_DIR}"
121
+ api-keys:
122
+ - "${API_KEY}"
123
+ remote-management:
124
+ secret-key: "${MANAGEMENT_KEY}"
125
+ allow-remote-management: false
126
+ request-retry: 3
127
+ quota-exceeded:
128
+ switch-project: true
129
+ switch-preview-model: true
130
+ `;
131
+ };
132
+
133
+ /**
134
+ * Download and install CLIProxyAPI
135
+ * @param {Function} onProgress - Progress callback (message)
136
+ */
137
+ const install = async (onProgress = () => {}) => {
138
+ // Create directories
139
+ if (!fs.existsSync(PROXY_DIR)) {
140
+ fs.mkdirSync(PROXY_DIR, { recursive: true });
141
+ }
142
+ if (!fs.existsSync(PROXY_AUTH_DIR)) {
143
+ fs.mkdirSync(PROXY_AUTH_DIR, { recursive: true });
144
+ }
145
+
146
+ onProgress('Downloading CLIProxyAPI...');
147
+
148
+ const downloadUrl = getDownloadUrl();
149
+ const ext = process.platform === 'win32' ? 'zip' : 'tar.gz';
150
+ const archivePath = path.join(PROXY_DIR, `cliproxyapi.${ext}`);
151
+
152
+ // Download
153
+ await downloadFile(downloadUrl, archivePath);
154
+
155
+ onProgress('Extracting...');
156
+
157
+ // Extract
158
+ if (ext === 'zip') {
159
+ await extractZip(archivePath, PROXY_DIR);
160
+ } else {
161
+ await extractTarGz(archivePath, PROXY_DIR);
162
+ }
163
+
164
+ // Find the binary (it might be in a subdirectory)
165
+ const possibleBins = [
166
+ path.join(PROXY_DIR, 'cli-proxy-api'),
167
+ path.join(PROXY_DIR, 'cli-proxy-api.exe'),
168
+ path.join(PROXY_DIR, 'CLIProxyAPI', 'cli-proxy-api'),
169
+ path.join(PROXY_DIR, 'CLIProxyAPI', 'cli-proxy-api.exe')
170
+ ];
171
+
172
+ for (const bin of possibleBins) {
173
+ if (fs.existsSync(bin) && bin !== PROXY_BIN) {
174
+ fs.renameSync(bin, PROXY_BIN);
175
+ break;
176
+ }
177
+ }
178
+
179
+ // Make executable (Unix)
180
+ if (process.platform !== 'win32') {
181
+ fs.chmodSync(PROXY_BIN, 0o755);
182
+ }
183
+
184
+ // Create config file
185
+ fs.writeFileSync(PROXY_CONFIG, getConfigContent());
186
+
187
+ // Cleanup archive
188
+ fs.unlinkSync(archivePath);
189
+
190
+ onProgress('Installation complete');
191
+
192
+ return true;
193
+ };
194
+
195
+ /**
196
+ * Check if config has correct management key (plain text, not hashed)
197
+ * @returns {boolean}
198
+ */
199
+ const isConfigValid = () => {
200
+ if (!fs.existsSync(PROXY_CONFIG)) return false;
201
+
202
+ try {
203
+ const config = fs.readFileSync(PROXY_CONFIG, 'utf8');
204
+
205
+ if (!config.includes('remote-management:') || !config.includes('secret-key:')) {
206
+ return false;
207
+ }
208
+
209
+ // Check if key is hashed (bcrypt hashes start with $2a$, $2b$, or $2y$)
210
+ if (config.includes('$2a$') || config.includes('$2b$') || config.includes('$2y$')) {
211
+ return false;
212
+ }
213
+
214
+ if (!config.includes(MANAGEMENT_KEY)) {
215
+ return false;
216
+ }
217
+
218
+ return true;
219
+ } catch (e) {
220
+ return false;
221
+ }
222
+ };
223
+
224
+ /**
225
+ * Rewrite config file with correct settings
226
+ */
227
+ const rewriteConfig = () => {
228
+ if (!fs.existsSync(PROXY_DIR)) {
229
+ fs.mkdirSync(PROXY_DIR, { recursive: true });
230
+ }
231
+
232
+ fs.writeFileSync(PROXY_CONFIG, getConfigContent());
233
+ };
234
+
235
+ module.exports = {
236
+ PROXY_VERSION,
237
+ PROXY_PORT,
238
+ PROXY_DIR,
239
+ PROXY_BIN,
240
+ PROXY_CONFIG,
241
+ PROXY_AUTH_DIR,
242
+ API_KEY,
243
+ MANAGEMENT_KEY,
244
+ getDownloadUrl,
245
+ isInstalled,
246
+ install,
247
+ isConfigValid,
248
+ rewriteConfig,
249
+ };