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
@@ -7,6 +7,7 @@ const { getProviders, getProvider } = require('./providers');
7
7
  const { storage } = require('../session');
8
8
  const AISupervisor = require('./supervisor');
9
9
  const StrategySupervisor = require('./strategy-supervisor');
10
+ const { validateConnection } = require('./validation');
10
11
 
11
12
  // In-memory cache of connections
12
13
  let connectionsCache = null;
@@ -348,263 +349,7 @@ const getCredentials = () => {
348
349
  return agent?.credentials || null;
349
350
  };
350
351
 
351
- /**
352
- * Validate API key with provider
353
- */
354
- const validateConnection = async (providerId, optionId, credentials) => {
355
- const provider = getProvider(providerId);
356
- if (!provider) return { valid: false, error: 'Invalid provider' };
357
-
358
- try {
359
- switch (providerId) {
360
- case 'anthropic':
361
- return await validateAnthropic(credentials);
362
- case 'openai':
363
- return await validateOpenAI(credentials);
364
- case 'gemini':
365
- return await validateGemini(credentials);
366
- case 'deepseek':
367
- return await validateDeepSeek(credentials);
368
- case 'groq':
369
- return await validateGroq(credentials);
370
- case 'ollama':
371
- return await validateOllama(credentials);
372
- case 'lmstudio':
373
- return await validateLMStudio(credentials);
374
- case 'custom':
375
- return await validateCustom(credentials);
376
- // OpenAI-compatible providers (use same validation)
377
- case 'openrouter':
378
- return await validateOpenRouter(credentials);
379
- case 'xai':
380
- case 'mistral':
381
- case 'perplexity':
382
- case 'together':
383
- case 'qwen':
384
- case 'moonshot':
385
- case 'yi':
386
- case 'zhipu':
387
- case 'baichuan':
388
- return await validateOpenAICompatible(provider, credentials);
389
- default:
390
- return { valid: false, error: 'Unknown provider' };
391
- }
392
- } catch (error) {
393
- return { valid: false, error: error.message };
394
- }
395
- };
396
-
397
- // Validation functions for each provider
398
- const validateAnthropic = async (credentials) => {
399
- try {
400
- const token = credentials.apiKey || credentials.sessionKey || credentials.accessToken;
401
- if (!token) return { valid: false, error: 'No API key provided' };
402
-
403
- // Validate by fetching models from API - this proves the token works
404
- const response = await fetch('https://api.anthropic.com/v1/models', {
405
- method: 'GET',
406
- headers: {
407
- 'x-api-key': token,
408
- 'anthropic-version': '2023-06-01'
409
- }
410
- });
411
-
412
- if (response.ok) {
413
- const data = await response.json();
414
- if (data.data && Array.isArray(data.data) && data.data.length > 0) {
415
- return { valid: true, tokenType: 'api_key' };
416
- }
417
- return { valid: false, error: 'API returned no models' };
418
- }
419
-
420
- const error = await response.json();
421
- return { valid: false, error: error.error?.message || 'Invalid API key' };
422
- } catch (e) {
423
- return { valid: false, error: e.message };
424
- }
425
- };
426
-
427
- const validateOpenAI = async (credentials) => {
428
- try {
429
- const response = await fetch('https://api.openai.com/v1/models', {
430
- headers: {
431
- 'Authorization': `Bearer ${credentials.apiKey || credentials.accessToken}`
432
- }
433
- });
434
-
435
- if (response.ok) {
436
- return { valid: true };
437
- }
438
-
439
- return { valid: false, error: 'Invalid API key' };
440
- } catch (e) {
441
- return { valid: false, error: e.message };
442
- }
443
- };
444
-
445
- const validateGemini = async (credentials) => {
446
- try {
447
- const response = await fetch(
448
- `https://generativelanguage.googleapis.com/v1/models?key=${credentials.apiKey}`
449
- );
450
-
451
- if (response.ok) {
452
- return { valid: true };
453
- }
454
-
455
- return { valid: false, error: 'Invalid API key' };
456
- } catch (e) {
457
- return { valid: false, error: e.message };
458
- }
459
- };
460
-
461
- const validateDeepSeek = async (credentials) => {
462
- try {
463
- const response = await fetch('https://api.deepseek.com/v1/models', {
464
- headers: {
465
- 'Authorization': `Bearer ${credentials.apiKey}`
466
- }
467
- });
468
-
469
- if (response.ok) {
470
- return { valid: true };
471
- }
472
-
473
- return { valid: false, error: 'Invalid API key' };
474
- } catch (e) {
475
- return { valid: false, error: e.message };
476
- }
477
- };
478
-
479
- const validateGroq = async (credentials) => {
480
- try {
481
- const response = await fetch('https://api.groq.com/openai/v1/models', {
482
- headers: {
483
- 'Authorization': `Bearer ${credentials.apiKey}`
484
- }
485
- });
486
-
487
- if (response.ok) {
488
- return { valid: true };
489
- }
490
-
491
- return { valid: false, error: 'Invalid API key' };
492
- } catch (e) {
493
- return { valid: false, error: e.message };
494
- }
495
- };
496
-
497
- const validateOllama = async (credentials) => {
498
- try {
499
- const endpoint = credentials.endpoint || 'http://localhost:11434';
500
- const response = await fetch(`${endpoint}/api/tags`);
501
-
502
- if (response.ok) {
503
- const data = await response.json();
504
- return {
505
- valid: true,
506
- models: data.models?.map(m => m.name) || []
507
- };
508
- }
509
-
510
- return { valid: false, error: 'Cannot connect to Ollama' };
511
- } catch (e) {
512
- return { valid: false, error: 'Ollama not running. Start with: ollama serve' };
513
- }
514
- };
515
-
516
- const validateCustom = async (credentials) => {
517
- try {
518
- const response = await fetch(`${credentials.endpoint}/models`, {
519
- headers: credentials.apiKey ? {
520
- 'Authorization': `Bearer ${credentials.apiKey}`
521
- } : {}
522
- });
523
-
524
- if (response.ok) {
525
- return { valid: true };
526
- }
527
-
528
- return { valid: false, error: 'Cannot connect to endpoint' };
529
- } catch (e) {
530
- return { valid: false, error: e.message };
531
- }
532
- };
533
-
534
- const validateOpenRouter = async (credentials) => {
535
- try {
536
- const response = await fetch('https://openrouter.ai/api/v1/models', {
537
- headers: {
538
- 'Authorization': `Bearer ${credentials.apiKey}`
539
- }
540
- });
541
-
542
- if (response.ok) {
543
- return { valid: true };
544
- }
545
-
546
- return { valid: false, error: 'Invalid API key' };
547
- } catch (e) {
548
- return { valid: false, error: e.message };
549
- }
550
- };
551
-
552
- const validateLMStudio = async (credentials) => {
553
- try {
554
- const endpoint = credentials.endpoint || 'http://localhost:1234/v1';
555
- const response = await fetch(`${endpoint}/models`);
556
-
557
- if (response.ok) {
558
- const data = await response.json();
559
- return {
560
- valid: true,
561
- models: data.data?.map(m => m.id) || []
562
- };
563
- }
564
-
565
- return { valid: false, error: 'Cannot connect to LM Studio' };
566
- } catch (e) {
567
- return { valid: false, error: 'LM Studio not running. Start local server first.' };
568
- }
569
- };
570
-
571
- const validateOpenAICompatible = async (provider, credentials) => {
572
- try {
573
- const endpoint = provider.endpoint;
574
- const response = await fetch(`${endpoint}/models`, {
575
- headers: {
576
- 'Authorization': `Bearer ${credentials.apiKey}`,
577
- 'Content-Type': 'application/json'
578
- }
579
- });
580
-
581
- if (response.ok) {
582
- return { valid: true };
583
- }
584
-
585
- // Some providers don't have /models endpoint, try a simple chat
586
- const chatResponse = await fetch(`${endpoint}/chat/completions`, {
587
- method: 'POST',
588
- headers: {
589
- 'Authorization': `Bearer ${credentials.apiKey}`,
590
- 'Content-Type': 'application/json'
591
- },
592
- body: JSON.stringify({
593
- model: provider.defaultModel,
594
- messages: [{ role: 'user', content: 'hi' }],
595
- max_tokens: 5
596
- })
597
- });
598
-
599
- if (chatResponse.ok) {
600
- return { valid: true };
601
- }
602
-
603
- return { valid: false, error: 'Invalid API key or endpoint' };
604
- } catch (e) {
605
- return { valid: false, error: e.message };
606
- }
607
- };
352
+ // validateConnection imported from ./validation
608
353
 
609
354
  module.exports = {
610
355
  // Provider info
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Direct AI Providers Configuration
3
+ * @module services/ai/providers/direct-providers
4
+ *
5
+ * Provider configurations that connect directly to each provider's API
6
+ */
7
+
8
+ const DIRECT_PROVIDERS = {
9
+ anthropic: {
10
+ id: 'anthropic',
11
+ name: 'CLAUDE (ANTHROPIC)',
12
+ description: 'Pro/Max or API Key',
13
+ category: 'direct',
14
+ models: [],
15
+ defaultModel: null,
16
+ options: [
17
+ {
18
+ id: 'oauth_max',
19
+ label: 'CLAUDE PRO/MAX (OAUTH)',
20
+ description: ['Login with your Claude subscription', 'Unlimited usage with your plan'],
21
+ fields: ['oauth'],
22
+ authType: 'oauth'
23
+ },
24
+ {
25
+ id: 'api_key',
26
+ label: 'API KEY (PAY-PER-USE)',
27
+ description: ['Get key at console.anthropic.com', '~$0.10 per trading session'],
28
+ fields: ['apiKey'],
29
+ url: 'https://console.anthropic.com/settings/keys'
30
+ }
31
+ ],
32
+ endpoint: 'https://api.anthropic.com/v1'
33
+ },
34
+
35
+ openai: {
36
+ id: 'openai',
37
+ name: 'OPENAI (GPT-4/5)',
38
+ description: 'Plus/Pro or API Key',
39
+ category: 'direct',
40
+ models: [],
41
+ defaultModel: null,
42
+ options: [
43
+ {
44
+ id: 'oauth_plus',
45
+ label: 'PLUS/PRO SUBSCRIPTION (OAUTH)',
46
+ description: ['Login with your ChatGPT account', 'Unlimited with your plan'],
47
+ fields: ['oauth'],
48
+ authType: 'oauth'
49
+ },
50
+ {
51
+ id: 'api_key',
52
+ label: 'API KEY (PAY-PER-USE)',
53
+ description: ['Get key at platform.openai.com', '~$0.15 per trading session'],
54
+ fields: ['apiKey'],
55
+ url: 'https://platform.openai.com/api-keys'
56
+ }
57
+ ],
58
+ endpoint: 'https://api.openai.com/v1'
59
+ },
60
+
61
+ gemini: {
62
+ id: 'gemini',
63
+ name: 'GEMINI (GOOGLE)',
64
+ description: 'Advanced or API Key',
65
+ category: 'direct',
66
+ models: [],
67
+ defaultModel: null,
68
+ options: [
69
+ {
70
+ id: 'oauth_advanced',
71
+ label: 'ADVANCED SUBSCRIPTION (OAUTH)',
72
+ description: ['Login with your Google account', 'Unlimited with your plan'],
73
+ fields: ['oauth'],
74
+ authType: 'oauth'
75
+ },
76
+ {
77
+ id: 'api_key',
78
+ label: 'API KEY (FREE TIER)',
79
+ description: ['Get key at aistudio.google.com', 'Free tier: 60 requests/min'],
80
+ fields: ['apiKey'],
81
+ url: 'https://aistudio.google.com/apikey'
82
+ }
83
+ ],
84
+ endpoint: 'https://generativelanguage.googleapis.com/v1'
85
+ },
86
+
87
+ deepseek: {
88
+ id: 'deepseek',
89
+ name: 'DEEPSEEK',
90
+ description: 'Very cheap & capable',
91
+ category: 'direct',
92
+ models: [],
93
+ defaultModel: null,
94
+ options: [
95
+ {
96
+ id: 'api_key',
97
+ label: 'API KEY (VERY CHEAP)',
98
+ description: ['Get key at platform.deepseek.com', '~$0.02 per trading session'],
99
+ fields: ['apiKey'],
100
+ url: 'https://platform.deepseek.com'
101
+ }
102
+ ],
103
+ endpoint: 'https://api.deepseek.com/v1'
104
+ },
105
+
106
+ groq: {
107
+ id: 'groq',
108
+ name: 'GROQ',
109
+ description: 'Ultra fast inference',
110
+ category: 'direct',
111
+ models: [],
112
+ defaultModel: null,
113
+ options: [
114
+ {
115
+ id: 'api_key',
116
+ label: 'API KEY (FREE TIER)',
117
+ description: ['Get key at console.groq.com', 'Generous free tier', 'Ultra low latency'],
118
+ fields: ['apiKey'],
119
+ url: 'https://console.groq.com/keys'
120
+ }
121
+ ],
122
+ endpoint: 'https://api.groq.com/openai/v1'
123
+ },
124
+
125
+ xai: {
126
+ id: 'xai',
127
+ name: 'GROK (XAI)',
128
+ description: 'Elon Musk\'s Grok AI',
129
+ category: 'direct',
130
+ models: [],
131
+ defaultModel: null,
132
+ options: [
133
+ {
134
+ id: 'api_key',
135
+ label: 'API KEY',
136
+ description: ['Get key at console.x.ai', 'Grok models from xAI'],
137
+ fields: ['apiKey'],
138
+ url: 'https://console.x.ai'
139
+ }
140
+ ],
141
+ endpoint: 'https://api.x.ai/v1'
142
+ },
143
+
144
+ mistral: {
145
+ id: 'mistral',
146
+ name: 'MISTRAL',
147
+ description: 'European AI leader',
148
+ category: 'direct',
149
+ models: [],
150
+ defaultModel: null,
151
+ options: [
152
+ {
153
+ id: 'api_key',
154
+ label: 'API KEY',
155
+ description: ['Get key at console.mistral.ai', 'Fast European models'],
156
+ fields: ['apiKey'],
157
+ url: 'https://console.mistral.ai'
158
+ }
159
+ ],
160
+ endpoint: 'https://api.mistral.ai/v1'
161
+ },
162
+
163
+ perplexity: {
164
+ id: 'perplexity',
165
+ name: 'PERPLEXITY',
166
+ description: 'Real-time web search AI',
167
+ category: 'direct',
168
+ models: [],
169
+ defaultModel: null,
170
+ options: [
171
+ {
172
+ id: 'api_key',
173
+ label: 'API KEY',
174
+ description: ['Get key at perplexity.ai/settings/api', 'Real-time market news & data', 'Web search integrated'],
175
+ fields: ['apiKey'],
176
+ url: 'https://www.perplexity.ai/settings/api'
177
+ }
178
+ ],
179
+ endpoint: 'https://api.perplexity.ai'
180
+ },
181
+
182
+ together: {
183
+ id: 'together',
184
+ name: 'TOGETHER AI',
185
+ description: 'Open source models, fast & cheap',
186
+ category: 'direct',
187
+ models: [],
188
+ defaultModel: null,
189
+ options: [
190
+ {
191
+ id: 'api_key',
192
+ label: 'API KEY',
193
+ description: ['Get key at api.together.xyz', '100+ open source models', 'Fast inference, good pricing'],
194
+ fields: ['apiKey'],
195
+ url: 'https://api.together.xyz/settings/api-keys'
196
+ }
197
+ ],
198
+ endpoint: 'https://api.together.xyz/v1'
199
+ },
200
+
201
+ iflow: {
202
+ id: 'iflow',
203
+ name: 'IFLOW',
204
+ description: 'Subscription (OAuth)',
205
+ category: 'direct',
206
+ models: [],
207
+ defaultModel: null,
208
+ options: [
209
+ {
210
+ id: 'oauth_sub',
211
+ label: 'SUBSCRIPTION (OAUTH)',
212
+ description: ['Login with your iFlow account', 'Access to DeepSeek, Kimi, GLM & more'],
213
+ fields: ['oauth'],
214
+ authType: 'oauth'
215
+ }
216
+ ],
217
+ endpoint: 'https://api.iflow.com/v1'
218
+ },
219
+
220
+ qwen: {
221
+ id: 'qwen',
222
+ name: 'QWEN (ALIBABA)',
223
+ description: 'Chat subscription or API Key',
224
+ category: 'direct',
225
+ models: [],
226
+ defaultModel: null,
227
+ options: [
228
+ {
229
+ id: 'oauth_chat',
230
+ label: 'CHAT SUBSCRIPTION (OAUTH)',
231
+ description: ['Login with your Qwen account', 'Unlimited with your plan'],
232
+ fields: ['oauth'],
233
+ authType: 'oauth'
234
+ },
235
+ {
236
+ id: 'api_key',
237
+ label: 'API KEY (DASHSCOPE)',
238
+ description: ['Get key at dashscope.aliyun.com', 'Qwen2.5 models', 'Very competitive pricing'],
239
+ fields: ['apiKey'],
240
+ url: 'https://dashscope.console.aliyun.com/apiKey'
241
+ }
242
+ ],
243
+ endpoint: 'https://dashscope.aliyuncs.com/compatible-mode/v1'
244
+ },
245
+
246
+ moonshot: {
247
+ id: 'moonshot',
248
+ name: 'MOONSHOT (KIMI)',
249
+ description: '200K context window',
250
+ category: 'direct',
251
+ models: [],
252
+ defaultModel: null,
253
+ options: [
254
+ {
255
+ id: 'api_key',
256
+ label: 'API KEY',
257
+ description: ['Get key at platform.moonshot.cn', 'Up to 200K context', 'Good for long documents'],
258
+ fields: ['apiKey'],
259
+ url: 'https://platform.moonshot.cn/console/api-keys'
260
+ }
261
+ ],
262
+ endpoint: 'https://api.moonshot.cn/v1'
263
+ },
264
+
265
+ yi: {
266
+ id: 'yi',
267
+ name: '01.AI (YI)',
268
+ description: 'Yi models by Kai-Fu Lee',
269
+ category: 'direct',
270
+ models: [],
271
+ defaultModel: null,
272
+ options: [
273
+ {
274
+ id: 'api_key',
275
+ label: 'API KEY',
276
+ description: ['Get key at platform.01.ai', 'Yi-Large: GPT-4 level', 'Affordable pricing'],
277
+ fields: ['apiKey'],
278
+ url: 'https://platform.01.ai'
279
+ }
280
+ ],
281
+ endpoint: 'https://api.01.ai/v1'
282
+ },
283
+
284
+ zhipu: {
285
+ id: 'zhipu',
286
+ name: 'ZHIPU AI (GLM)',
287
+ description: 'ChatGLM models',
288
+ category: 'direct',
289
+ models: [],
290
+ defaultModel: null,
291
+ options: [
292
+ {
293
+ id: 'api_key',
294
+ label: 'API KEY',
295
+ description: ['Get key at open.bigmodel.cn', 'ChatGLM-4 models', 'Strong multilingual'],
296
+ fields: ['apiKey'],
297
+ url: 'https://open.bigmodel.cn/usercenter/apikeys'
298
+ }
299
+ ],
300
+ endpoint: 'https://open.bigmodel.cn/api/paas/v4'
301
+ },
302
+
303
+ baichuan: {
304
+ id: 'baichuan',
305
+ name: 'BAICHUAN',
306
+ description: 'Multilingual AI model',
307
+ category: 'direct',
308
+ models: [],
309
+ defaultModel: null,
310
+ options: [
311
+ {
312
+ id: 'api_key',
313
+ label: 'API KEY',
314
+ description: ['Get key at platform.baichuan-ai.com', 'Strong multilingual support', 'Competitive pricing'],
315
+ fields: ['apiKey'],
316
+ url: 'https://platform.baichuan-ai.com/console/apikey'
317
+ }
318
+ ],
319
+ endpoint: 'https://api.baichuan-ai.com/v1'
320
+ },
321
+ };
322
+
323
+ module.exports = { DIRECT_PROVIDERS };