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.
- package/package.json +1 -1
- package/src/menus/ai-agent-connect.js +181 -0
- package/src/menus/ai-agent-models.js +219 -0
- package/src/menus/ai-agent-oauth.js +292 -0
- package/src/menus/ai-agent-ui.js +141 -0
- package/src/menus/ai-agent.js +88 -1489
- package/src/pages/algo/copy-engine.js +449 -0
- package/src/pages/algo/copy-trading.js +11 -543
- package/src/pages/algo/smart-logs-data.js +218 -0
- package/src/pages/algo/smart-logs.js +9 -214
- package/src/pages/algo/ui-constants.js +144 -0
- package/src/pages/algo/ui-summary.js +184 -0
- package/src/pages/algo/ui.js +42 -526
- package/src/pages/stats-calculations.js +191 -0
- package/src/pages/stats-ui.js +381 -0
- package/src/pages/stats.js +14 -507
- package/src/services/ai/client-analysis.js +194 -0
- package/src/services/ai/client-models.js +333 -0
- package/src/services/ai/client.js +6 -489
- package/src/services/ai/index.js +2 -257
- package/src/services/ai/proxy-install.js +249 -0
- package/src/services/ai/proxy-manager.js +29 -411
- package/src/services/ai/proxy-remote.js +161 -0
- package/src/services/ai/strategy-supervisor.js +10 -765
- package/src/services/ai/supervisor-data.js +195 -0
- package/src/services/ai/supervisor-optimize.js +215 -0
- package/src/services/ai/supervisor-sync.js +178 -0
- package/src/services/ai/supervisor-utils.js +158 -0
- package/src/services/ai/supervisor.js +50 -515
- package/src/services/ai/validation.js +250 -0
- package/src/services/hqx-server-events.js +110 -0
- package/src/services/hqx-server-handlers.js +217 -0
- package/src/services/hqx-server-latency.js +136 -0
- package/src/services/hqx-server.js +51 -403
- package/src/services/position-constants.js +28 -0
- package/src/services/position-manager.js +105 -554
- package/src/services/position-momentum.js +206 -0
- package/src/services/projectx/accounts.js +142 -0
- package/src/services/projectx/index.js +40 -289
- package/src/services/projectx/trading.js +180 -0
- package/src/services/rithmic/handlers.js +2 -208
- package/src/services/rithmic/index.js +32 -542
- package/src/services/rithmic/latency-tracker.js +182 -0
- package/src/services/rithmic/specs.js +146 -0
- package/src/services/rithmic/trade-history.js +254 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor Utility Functions
|
|
3
|
+
* Pure functions for market analysis - no state dependencies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const calculateTrendStrength = (ticks) => {
|
|
9
|
+
if (!ticks || ticks.length < 20) return { strength: 0, direction: 'unknown' };
|
|
10
|
+
const prices = ticks.map(t => t.price).filter(Boolean);
|
|
11
|
+
if (prices.length < 20) return { strength: 0, direction: 'unknown' };
|
|
12
|
+
const shortTerm = prices.slice(-20);
|
|
13
|
+
const shortChange = shortTerm[shortTerm.length - 1] - shortTerm[0];
|
|
14
|
+
const mediumTerm = prices.slice(-50);
|
|
15
|
+
const mediumChange = mediumTerm[mediumTerm.length - 1] - mediumTerm[0];
|
|
16
|
+
const aligned = (shortChange > 0 && mediumChange > 0) || (shortChange < 0 && mediumChange < 0);
|
|
17
|
+
const avgRange = Math.abs(Math.max(...prices) - Math.min(...prices)) || 1;
|
|
18
|
+
return {
|
|
19
|
+
strength: aligned ? Math.min(1, (Math.abs(shortChange) + Math.abs(mediumChange)) / avgRange) : 0,
|
|
20
|
+
direction: mediumChange > 0 ? 'bullish' : mediumChange < 0 ? 'bearish' : 'neutral',
|
|
21
|
+
shortTermDirection: shortChange > 0 ? 'up' : shortChange < 0 ? 'down' : 'flat',
|
|
22
|
+
aligned
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const calculateRecentRange = (ticks, count) => {
|
|
27
|
+
if (!ticks || ticks.length === 0) return { high: 0, low: 0, range: 0 };
|
|
28
|
+
const prices = ticks.slice(-count).map(t => t.price).filter(Boolean);
|
|
29
|
+
if (prices.length === 0) return { high: 0, low: 0, range: 0 };
|
|
30
|
+
const high = Math.max(...prices);
|
|
31
|
+
const low = Math.min(...prices);
|
|
32
|
+
return { high, low, range: high - low };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const calculatePriceVelocity = (ticks, count) => {
|
|
36
|
+
if (!ticks || ticks.length < 2) return { velocity: 0, acceleration: 0 };
|
|
37
|
+
const recentTicks = ticks.slice(-count);
|
|
38
|
+
if (recentTicks.length < 2) return { velocity: 0, acceleration: 0 };
|
|
39
|
+
const prices = recentTicks.map(t => t.price).filter(Boolean);
|
|
40
|
+
if (prices.length < 2) return { velocity: 0, acceleration: 0 };
|
|
41
|
+
const totalChange = prices[prices.length - 1] - prices[0];
|
|
42
|
+
const velocity = totalChange / prices.length;
|
|
43
|
+
const midPoint = Math.floor(prices.length / 2);
|
|
44
|
+
const firstHalfVelocity = (prices[midPoint] - prices[0]) / midPoint;
|
|
45
|
+
const secondHalfVelocity = (prices[prices.length - 1] - prices[midPoint]) / (prices.length - midPoint);
|
|
46
|
+
const acceleration = secondHalfVelocity - firstHalfVelocity;
|
|
47
|
+
return { velocity, acceleration };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getMarketSession = (hour) => {
|
|
51
|
+
if (hour >= 9 && hour < 12) return 'morning';
|
|
52
|
+
if (hour >= 12 && hour < 14) return 'midday';
|
|
53
|
+
if (hour >= 14 && hour < 16) return 'afternoon';
|
|
54
|
+
if (hour >= 16 && hour < 18) return 'close';
|
|
55
|
+
if (hour >= 18 || hour < 9) return 'overnight';
|
|
56
|
+
return 'unknown';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getMinutesSinceOpen = (hour) => {
|
|
60
|
+
const now = new Date();
|
|
61
|
+
const currentMinutes = hour * 60 + now.getMinutes();
|
|
62
|
+
const openMinutes = 9 * 60 + 30;
|
|
63
|
+
return Math.max(0, currentMinutes - openMinutes);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const analyzePriceLevelInteraction = (entryPrice, ticks) => {
|
|
67
|
+
if (!ticks || ticks.length < 20) return null;
|
|
68
|
+
const prices = ticks.map(t => t.price).filter(Boolean);
|
|
69
|
+
if (prices.length < 20) return null;
|
|
70
|
+
const high = Math.max(...prices);
|
|
71
|
+
const low = Math.min(...prices);
|
|
72
|
+
const range = high - low || 1;
|
|
73
|
+
const positionInRange = (entryPrice - low) / range;
|
|
74
|
+
let levelType = 'middle';
|
|
75
|
+
if (positionInRange > 0.8) levelType = 'near_high';
|
|
76
|
+
else if (positionInRange < 0.2) levelType = 'near_low';
|
|
77
|
+
else if (positionInRange > 0.6) levelType = 'upper_middle';
|
|
78
|
+
else if (positionInRange < 0.4) levelType = 'lower_middle';
|
|
79
|
+
return {
|
|
80
|
+
positionInRange: Math.round(positionInRange * 100) / 100,
|
|
81
|
+
distanceToHigh: high - entryPrice,
|
|
82
|
+
distanceToLow: entryPrice - low,
|
|
83
|
+
recentHigh: high,
|
|
84
|
+
recentLow: low,
|
|
85
|
+
levelType
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const determineLevelType = (price, ticks) => {
|
|
90
|
+
if (!ticks || ticks.length < 10) return 'unknown';
|
|
91
|
+
const prices = ticks.map(t => t.price).filter(Boolean);
|
|
92
|
+
if (prices.length < 10) return 'unknown';
|
|
93
|
+
const high = Math.max(...prices);
|
|
94
|
+
const low = Math.min(...prices);
|
|
95
|
+
const tickSize = 0.25;
|
|
96
|
+
if (Math.abs(price - high) <= tickSize * 4) return 'resistance';
|
|
97
|
+
if (Math.abs(price - low) <= tickSize * 4) return 'support';
|
|
98
|
+
if (price > high) return 'breakout_high';
|
|
99
|
+
if (price < low) return 'breakout_low';
|
|
100
|
+
return 'middle';
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const analyzePriceAction = (ticks) => {
|
|
104
|
+
if (!ticks || ticks.length < 2) return { trend: 'unknown', strength: 0 };
|
|
105
|
+
const prices = ticks.map(t => t.price).filter(Boolean);
|
|
106
|
+
if (prices.length < 2) return { trend: 'unknown', strength: 0 };
|
|
107
|
+
const first = prices[0];
|
|
108
|
+
const last = prices[prices.length - 1];
|
|
109
|
+
const change = last - first;
|
|
110
|
+
const range = Math.max(...prices) - Math.min(...prices);
|
|
111
|
+
return {
|
|
112
|
+
trend: change > 0 ? 'up' : change < 0 ? 'down' : 'flat',
|
|
113
|
+
strength: range > 0 ? Math.abs(change) / range : 0,
|
|
114
|
+
range,
|
|
115
|
+
change
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const analyzeVolume = (ticks) => {
|
|
120
|
+
if (!ticks || ticks.length === 0) return { total: 0, avg: 0, trend: 'unknown' };
|
|
121
|
+
const volumes = ticks.map(t => t.volume || 0);
|
|
122
|
+
const total = volumes.reduce((a, b) => a + b, 0);
|
|
123
|
+
const avg = total / volumes.length;
|
|
124
|
+
const mid = Math.floor(volumes.length / 2);
|
|
125
|
+
const firstHalf = volumes.slice(0, mid).reduce((a, b) => a + b, 0);
|
|
126
|
+
const secondHalf = volumes.slice(mid).reduce((a, b) => a + b, 0);
|
|
127
|
+
return {
|
|
128
|
+
total,
|
|
129
|
+
avg,
|
|
130
|
+
trend: secondHalf > firstHalf * 1.2 ? 'increasing' : secondHalf < firstHalf * 0.8 ? 'decreasing' : 'stable'
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const calculateVolatility = (ticks) => {
|
|
135
|
+
if (!ticks || ticks.length < 2) return 0;
|
|
136
|
+
const prices = ticks.map(t => t.price).filter(Boolean);
|
|
137
|
+
if (prices.length < 2) return 0;
|
|
138
|
+
const returns = [];
|
|
139
|
+
for (let i = 1; i < prices.length; i++) {
|
|
140
|
+
returns.push((prices[i] - prices[i-1]) / prices[i-1]);
|
|
141
|
+
}
|
|
142
|
+
const mean = returns.reduce((a, b) => a + b, 0) / returns.length;
|
|
143
|
+
const variance = returns.reduce((sum, r) => sum + Math.pow(r - mean, 2), 0) / returns.length;
|
|
144
|
+
return Math.sqrt(variance);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
module.exports = {
|
|
148
|
+
calculateTrendStrength,
|
|
149
|
+
calculateRecentRange,
|
|
150
|
+
calculatePriceVelocity,
|
|
151
|
+
getMarketSession,
|
|
152
|
+
getMinutesSinceOpen,
|
|
153
|
+
analyzePriceLevelInteraction,
|
|
154
|
+
determineLevelType,
|
|
155
|
+
analyzePriceAction,
|
|
156
|
+
analyzeVolume,
|
|
157
|
+
calculateVolatility
|
|
158
|
+
};
|