hedgequantx 2.7.99 → 2.8.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.
- package/package.json +1 -1
- package/src/menus/dashboard.js +4 -12
- package/src/pages/ai-agents-ui.js +46 -1
- package/src/pages/ai-agents.js +84 -54
- package/src/pages/algo/algo-executor.js +61 -19
- package/src/pages/algo/copy-executor.js +331 -0
- package/src/pages/algo/copy-trading.js +44 -263
- package/src/pages/algo/custom-strategy.js +27 -2
- package/src/pages/algo/one-account.js +48 -1
- package/src/services/ai-supervision/consensus.js +284 -0
- package/src/services/ai-supervision/context.js +275 -0
- package/src/services/ai-supervision/directive.js +167 -0
- package/src/services/ai-supervision/health.js +288 -0
- package/src/services/ai-supervision/index.js +309 -0
- package/src/services/ai-supervision/parser.js +278 -0
- package/src/services/ai-supervision/symbols.js +259 -0
- package/src/services/cliproxy/index.js +32 -1
- package/src/services/index.js +5 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol Data for AI Supervision
|
|
3
|
+
*
|
|
4
|
+
* Contains detailed information about tradeable symbols
|
|
5
|
+
* including tick sizes, sessions, correlations, and characteristics.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const SYMBOLS = {
|
|
9
|
+
NQ: {
|
|
10
|
+
id: 'NQ',
|
|
11
|
+
name: 'E-mini Nasdaq 100',
|
|
12
|
+
exchange: 'CME',
|
|
13
|
+
tickSize: 0.25,
|
|
14
|
+
tickValue: 5.00,
|
|
15
|
+
pointValue: 20.00,
|
|
16
|
+
margin: 15000,
|
|
17
|
+
characteristics: {
|
|
18
|
+
volatility: 'high',
|
|
19
|
+
sector: 'technology',
|
|
20
|
+
behavior: 'momentum-driven, gap-prone',
|
|
21
|
+
avgRange: '150-300 points'
|
|
22
|
+
},
|
|
23
|
+
correlations: {
|
|
24
|
+
positive: ['ES', 'YM'],
|
|
25
|
+
negative: ['VIX'],
|
|
26
|
+
related: ['QQQ', 'AAPL', 'MSFT', 'NVDA']
|
|
27
|
+
},
|
|
28
|
+
sessions: {
|
|
29
|
+
most_active: ['us_open', 'us_close'],
|
|
30
|
+
avoid: ['asia_lunch', 'low_volume']
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
ES: {
|
|
35
|
+
id: 'ES',
|
|
36
|
+
name: 'E-mini S&P 500',
|
|
37
|
+
exchange: 'CME',
|
|
38
|
+
tickSize: 0.25,
|
|
39
|
+
tickValue: 12.50,
|
|
40
|
+
pointValue: 50.00,
|
|
41
|
+
margin: 12000,
|
|
42
|
+
characteristics: {
|
|
43
|
+
volatility: 'medium',
|
|
44
|
+
sector: 'broad_market',
|
|
45
|
+
behavior: 'reference index, institutional flow',
|
|
46
|
+
avgRange: '30-60 points'
|
|
47
|
+
},
|
|
48
|
+
correlations: {
|
|
49
|
+
positive: ['NQ', 'YM', 'RTY'],
|
|
50
|
+
negative: ['VIX', 'ZB'],
|
|
51
|
+
related: ['SPY', 'SPX']
|
|
52
|
+
},
|
|
53
|
+
sessions: {
|
|
54
|
+
most_active: ['us_open', 'us_close', 'london_us_overlap'],
|
|
55
|
+
avoid: ['asia_session']
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
YM: {
|
|
60
|
+
id: 'YM',
|
|
61
|
+
name: 'E-mini Dow',
|
|
62
|
+
exchange: 'CME',
|
|
63
|
+
tickSize: 1.00,
|
|
64
|
+
tickValue: 5.00,
|
|
65
|
+
pointValue: 5.00,
|
|
66
|
+
margin: 10000,
|
|
67
|
+
characteristics: {
|
|
68
|
+
volatility: 'medium-low',
|
|
69
|
+
sector: 'value_stocks',
|
|
70
|
+
behavior: 'slower than ES/NQ, less spiky',
|
|
71
|
+
avgRange: '200-400 points'
|
|
72
|
+
},
|
|
73
|
+
correlations: {
|
|
74
|
+
positive: ['ES', 'NQ'],
|
|
75
|
+
negative: ['VIX'],
|
|
76
|
+
related: ['DIA', 'DJIA']
|
|
77
|
+
},
|
|
78
|
+
sessions: {
|
|
79
|
+
most_active: ['us_open', 'us_close'],
|
|
80
|
+
avoid: ['overnight']
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
RTY: {
|
|
85
|
+
id: 'RTY',
|
|
86
|
+
name: 'E-mini Russell 2000',
|
|
87
|
+
exchange: 'CME',
|
|
88
|
+
tickSize: 0.10,
|
|
89
|
+
tickValue: 5.00,
|
|
90
|
+
pointValue: 50.00,
|
|
91
|
+
margin: 8000,
|
|
92
|
+
characteristics: {
|
|
93
|
+
volatility: 'high',
|
|
94
|
+
sector: 'small_caps',
|
|
95
|
+
behavior: 'more volatile than ES, liquidity gaps',
|
|
96
|
+
avgRange: '20-40 points'
|
|
97
|
+
},
|
|
98
|
+
correlations: {
|
|
99
|
+
positive: ['ES', 'NQ'],
|
|
100
|
+
negative: ['VIX'],
|
|
101
|
+
related: ['IWM', 'RUT']
|
|
102
|
+
},
|
|
103
|
+
sessions: {
|
|
104
|
+
most_active: ['us_open'],
|
|
105
|
+
avoid: ['overnight', 'low_volume']
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
GC: {
|
|
110
|
+
id: 'GC',
|
|
111
|
+
name: 'Gold Futures',
|
|
112
|
+
exchange: 'COMEX',
|
|
113
|
+
tickSize: 0.10,
|
|
114
|
+
tickValue: 10.00,
|
|
115
|
+
pointValue: 100.00,
|
|
116
|
+
margin: 11000,
|
|
117
|
+
characteristics: {
|
|
118
|
+
volatility: 'medium',
|
|
119
|
+
sector: 'precious_metals',
|
|
120
|
+
behavior: 'safe haven, inverse USD, central bank sensitive',
|
|
121
|
+
avgRange: '15-30 points'
|
|
122
|
+
},
|
|
123
|
+
correlations: {
|
|
124
|
+
positive: ['SI', 'EURUSD'],
|
|
125
|
+
negative: ['DXY', 'US10Y'],
|
|
126
|
+
related: ['GLD', 'XAUUSD']
|
|
127
|
+
},
|
|
128
|
+
sessions: {
|
|
129
|
+
most_active: ['london', 'us_open', 'asia_open'],
|
|
130
|
+
avoid: ['us_afternoon']
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
SI: {
|
|
135
|
+
id: 'SI',
|
|
136
|
+
name: 'Silver Futures',
|
|
137
|
+
exchange: 'COMEX',
|
|
138
|
+
tickSize: 0.005,
|
|
139
|
+
tickValue: 25.00,
|
|
140
|
+
pointValue: 5000.00,
|
|
141
|
+
margin: 9000,
|
|
142
|
+
characteristics: {
|
|
143
|
+
volatility: 'high',
|
|
144
|
+
sector: 'precious_metals',
|
|
145
|
+
behavior: 'follows gold with more volatility, industrial demand',
|
|
146
|
+
avgRange: '0.30-0.60 points'
|
|
147
|
+
},
|
|
148
|
+
correlations: {
|
|
149
|
+
positive: ['GC'],
|
|
150
|
+
negative: ['DXY'],
|
|
151
|
+
related: ['SLV', 'XAGUSD']
|
|
152
|
+
},
|
|
153
|
+
sessions: {
|
|
154
|
+
most_active: ['london', 'us_open'],
|
|
155
|
+
avoid: ['asia_lunch']
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
CL: {
|
|
160
|
+
id: 'CL',
|
|
161
|
+
name: 'Crude Oil Futures',
|
|
162
|
+
exchange: 'NYMEX',
|
|
163
|
+
tickSize: 0.01,
|
|
164
|
+
tickValue: 10.00,
|
|
165
|
+
pointValue: 1000.00,
|
|
166
|
+
margin: 7000,
|
|
167
|
+
characteristics: {
|
|
168
|
+
volatility: 'high',
|
|
169
|
+
sector: 'energy',
|
|
170
|
+
behavior: 'news-driven, inventories, geopolitical, OPEC',
|
|
171
|
+
avgRange: '1.50-3.00 points'
|
|
172
|
+
},
|
|
173
|
+
correlations: {
|
|
174
|
+
positive: ['BZ', 'XLE'],
|
|
175
|
+
negative: [],
|
|
176
|
+
related: ['USO', 'WTI']
|
|
177
|
+
},
|
|
178
|
+
sessions: {
|
|
179
|
+
most_active: ['us_open', 'inventory_report'],
|
|
180
|
+
avoid: ['overnight_thin']
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Trading sessions with times (Eastern Time)
|
|
187
|
+
*/
|
|
188
|
+
const SESSIONS = {
|
|
189
|
+
asia_open: { start: '18:00', end: '20:00', description: 'Asia market open' },
|
|
190
|
+
asia_session: { start: '20:00', end: '03:00', description: 'Asia main session' },
|
|
191
|
+
asia_lunch: { start: '00:00', end: '01:00', description: 'Asia lunch (low volume)' },
|
|
192
|
+
london: { start: '03:00', end: '08:00', description: 'London session' },
|
|
193
|
+
london_us_overlap: { start: '08:00', end: '11:30', description: 'London/US overlap' },
|
|
194
|
+
us_open: { start: '09:30', end: '11:30', description: 'US market open (high volume)' },
|
|
195
|
+
us_midday: { start: '11:30', end: '14:00', description: 'US midday (lower volume)' },
|
|
196
|
+
us_afternoon: { start: '14:00', end: '15:00', description: 'US afternoon' },
|
|
197
|
+
us_close: { start: '15:00', end: '16:00', description: 'US close (rebalancing)' },
|
|
198
|
+
overnight: { start: '16:00', end: '18:00', description: 'Overnight transition' }
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get symbol data by ID
|
|
203
|
+
*/
|
|
204
|
+
const getSymbol = (symbolId) => {
|
|
205
|
+
const key = symbolId?.toUpperCase?.()?.replace(/[0-9]/g, '') || '';
|
|
206
|
+
return SYMBOLS[key] || null;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get current session based on time
|
|
211
|
+
*/
|
|
212
|
+
const getCurrentSession = (date = new Date()) => {
|
|
213
|
+
const et = new Date(date.toLocaleString('en-US', { timeZone: 'America/New_York' }));
|
|
214
|
+
const hours = et.getHours();
|
|
215
|
+
const minutes = et.getMinutes();
|
|
216
|
+
const time = hours * 60 + minutes;
|
|
217
|
+
|
|
218
|
+
for (const [name, session] of Object.entries(SESSIONS)) {
|
|
219
|
+
const [startH, startM] = session.start.split(':').map(Number);
|
|
220
|
+
const [endH, endM] = session.end.split(':').map(Number);
|
|
221
|
+
const start = startH * 60 + startM;
|
|
222
|
+
const end = endH * 60 + endM;
|
|
223
|
+
|
|
224
|
+
if (start <= end) {
|
|
225
|
+
if (time >= start && time < end) return { name, ...session };
|
|
226
|
+
} else {
|
|
227
|
+
if (time >= start || time < end) return { name, ...session };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return { name: 'unknown', description: 'Unknown session' };
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Check if current time is good for trading a symbol
|
|
235
|
+
*/
|
|
236
|
+
const isGoodSessionForSymbol = (symbolId, date = new Date()) => {
|
|
237
|
+
const symbol = getSymbol(symbolId);
|
|
238
|
+
if (!symbol) return { good: true, reason: 'Unknown symbol' };
|
|
239
|
+
|
|
240
|
+
const session = getCurrentSession(date);
|
|
241
|
+
|
|
242
|
+
if (symbol.sessions.avoid?.includes(session.name)) {
|
|
243
|
+
return { good: false, reason: `${session.description} - typically low volume for ${symbolId}` };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (symbol.sessions.most_active?.includes(session.name)) {
|
|
247
|
+
return { good: true, reason: `${session.description} - optimal for ${symbolId}` };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return { good: true, reason: session.description };
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
module.exports = {
|
|
254
|
+
SYMBOLS,
|
|
255
|
+
SESSIONS,
|
|
256
|
+
getSymbol,
|
|
257
|
+
getCurrentSession,
|
|
258
|
+
isGoodSessionForSymbol
|
|
259
|
+
};
|
|
@@ -197,6 +197,36 @@ const chatCompletion = async (model, messages, options = {}) => {
|
|
|
197
197
|
return { success: true, response: result.data, error: null };
|
|
198
198
|
};
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Simple chat function for AI supervision
|
|
202
|
+
* @param {string} providerId - Provider ID (anthropic, openai, google, etc.)
|
|
203
|
+
* @param {string} modelId - Model ID
|
|
204
|
+
* @param {string} prompt - User prompt
|
|
205
|
+
* @param {number} timeout - Timeout in ms
|
|
206
|
+
* @returns {Promise<Object>} { success, content, error }
|
|
207
|
+
*/
|
|
208
|
+
const chat = async (providerId, modelId, prompt, timeout = 30000) => {
|
|
209
|
+
const messages = [{ role: 'user', content: prompt }];
|
|
210
|
+
|
|
211
|
+
const result = await fetchLocal('/v1/chat/completions', 'POST', {
|
|
212
|
+
model: modelId,
|
|
213
|
+
messages,
|
|
214
|
+
stream: false
|
|
215
|
+
}, timeout);
|
|
216
|
+
|
|
217
|
+
if (!result.success) {
|
|
218
|
+
return { success: false, content: null, error: result.error };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Extract content from response
|
|
222
|
+
const data = result.data;
|
|
223
|
+
if (data?.choices?.[0]?.message?.content) {
|
|
224
|
+
return { success: true, content: data.choices[0].message.content, error: null };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return { success: false, content: null, error: 'No content in response' };
|
|
228
|
+
};
|
|
229
|
+
|
|
200
230
|
module.exports = {
|
|
201
231
|
// Manager
|
|
202
232
|
CLIPROXY_VERSION,
|
|
@@ -221,5 +251,6 @@ module.exports = {
|
|
|
221
251
|
fetchModels,
|
|
222
252
|
fetchProviderModels,
|
|
223
253
|
getConnectedProviders,
|
|
224
|
-
chatCompletion
|
|
254
|
+
chatCompletion,
|
|
255
|
+
chat
|
|
225
256
|
};
|
package/src/services/index.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* @fileoverview Services module exports
|
|
3
3
|
* @module services
|
|
4
4
|
*
|
|
5
|
-
* Rithmic-only service hub
|
|
5
|
+
* Rithmic-only service hub + AI Supervision
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const { RithmicService } = require('./rithmic/index');
|
|
9
9
|
const { HQXServerService } = require('./hqx-server/index');
|
|
10
10
|
const { storage, connections } = require('./session');
|
|
11
|
+
const aiSupervision = require('./ai-supervision');
|
|
11
12
|
|
|
12
13
|
module.exports = {
|
|
13
14
|
// Platform Service (Rithmic only)
|
|
@@ -19,4 +20,7 @@ module.exports = {
|
|
|
19
20
|
// Session Management
|
|
20
21
|
storage,
|
|
21
22
|
connections,
|
|
23
|
+
|
|
24
|
+
// AI Supervision
|
|
25
|
+
aiSupervision,
|
|
22
26
|
};
|