hedgequantx 2.3.16 → 2.3.18
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/dist/lib/api.jsc +0 -0
- package/dist/lib/api2.jsc +0 -0
- package/dist/lib/core.jsc +0 -0
- package/dist/lib/core2.jsc +0 -0
- package/dist/lib/data.jsc +0 -0
- package/dist/lib/data2.jsc +0 -0
- package/dist/lib/decoder.jsc +0 -0
- package/dist/lib/m/mod1.jsc +0 -0
- package/dist/lib/m/mod2.jsc +0 -0
- package/dist/lib/n/r1.jsc +0 -0
- package/dist/lib/n/r2.jsc +0 -0
- package/dist/lib/n/r3.jsc +0 -0
- package/dist/lib/n/r4.jsc +0 -0
- package/dist/lib/n/r5.jsc +0 -0
- package/dist/lib/n/r6.jsc +0 -0
- package/dist/lib/n/r7.jsc +0 -0
- package/dist/lib/o/util1.jsc +0 -0
- package/dist/lib/o/util2.jsc +0 -0
- package/package.json +1 -1
- package/src/pages/algo/one-account.js +94 -44
package/dist/lib/api.jsc
CHANGED
|
Binary file
|
package/dist/lib/api2.jsc
CHANGED
|
Binary file
|
package/dist/lib/core.jsc
CHANGED
|
Binary file
|
package/dist/lib/core2.jsc
CHANGED
|
Binary file
|
package/dist/lib/data.jsc
CHANGED
|
Binary file
|
package/dist/lib/data2.jsc
CHANGED
|
Binary file
|
package/dist/lib/decoder.jsc
CHANGED
|
Binary file
|
package/dist/lib/m/mod1.jsc
CHANGED
|
Binary file
|
package/dist/lib/m/mod2.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r1.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r2.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r3.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r4.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r5.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r6.jsc
CHANGED
|
Binary file
|
package/dist/lib/n/r7.jsc
CHANGED
|
Binary file
|
package/dist/lib/o/util1.jsc
CHANGED
|
Binary file
|
package/dist/lib/o/util2.jsc
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -11,6 +11,8 @@ const { AlgoUI, renderSessionSummary } = require('./ui');
|
|
|
11
11
|
const { prompts } = require('../../utils');
|
|
12
12
|
const { checkMarketHours } = require('../../services/projectx/market');
|
|
13
13
|
|
|
14
|
+
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* One Account Menu
|
|
16
18
|
*/
|
|
@@ -154,28 +156,50 @@ const configureAlgo = async (account, contract) => {
|
|
|
154
156
|
|
|
155
157
|
/**
|
|
156
158
|
* Launch algo trading
|
|
159
|
+
* 100% API data - no simulation, no mock data, no local calculations
|
|
157
160
|
*/
|
|
158
161
|
const launchAlgo = async (service, account, contract, config) => {
|
|
159
162
|
const { contracts, dailyTarget, maxRisk, showName } = config;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const accountName = showName
|
|
163
|
-
|
|
163
|
+
|
|
164
|
+
// Use RAW API fields
|
|
165
|
+
const accountName = showName
|
|
166
|
+
? (account.accountName || account.rithmicAccountId || account.accountId)
|
|
167
|
+
: 'HQX *****';
|
|
164
168
|
const symbolName = contract.name;
|
|
169
|
+
const connectionType = account.platform || 'ProjectX';
|
|
165
170
|
|
|
166
171
|
const ui = new AlgoUI({ subtitle: 'HQX Algo Trading', mode: 'one-account' });
|
|
167
172
|
|
|
168
173
|
const stats = {
|
|
169
|
-
accountName,
|
|
170
|
-
|
|
174
|
+
accountName,
|
|
175
|
+
symbol: symbolName,
|
|
176
|
+
qty: contracts,
|
|
177
|
+
target: dailyTarget,
|
|
178
|
+
risk: maxRisk,
|
|
171
179
|
propfirm: account.propfirm || 'Unknown',
|
|
172
|
-
platform:
|
|
173
|
-
pnl: 0,
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
platform: connectionType,
|
|
181
|
+
pnl: 0,
|
|
182
|
+
trades: 0,
|
|
183
|
+
wins: 0,
|
|
184
|
+
losses: 0,
|
|
185
|
+
latency: 0,
|
|
186
|
+
connected: true,
|
|
187
|
+
startTime: Date.now()
|
|
176
188
|
};
|
|
177
189
|
|
|
178
|
-
|
|
190
|
+
let running = true;
|
|
191
|
+
let stopReason = null;
|
|
192
|
+
let startingPnL = null; // P&L at algo start (from API)
|
|
193
|
+
let lastPositionPnL = 0;
|
|
194
|
+
|
|
195
|
+
// Log startup info from API
|
|
196
|
+
ui.addLog('info', `Connection: ${connectionType}`);
|
|
197
|
+
ui.addLog('info', `Account: ${accountName}`);
|
|
198
|
+
ui.addLog('info', `Symbol: ${symbolName} | Qty: ${contracts}`);
|
|
199
|
+
ui.addLog('info', `Target: $${dailyTarget} | Max Risk: $${maxRisk}`);
|
|
200
|
+
ui.addLog('info', 'Monitoring positions from API...');
|
|
201
|
+
|
|
202
|
+
// Measure API latency (real network round-trip)
|
|
179
203
|
const measureLatency = async () => {
|
|
180
204
|
try {
|
|
181
205
|
const start = Date.now();
|
|
@@ -186,56 +210,82 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
186
210
|
}
|
|
187
211
|
};
|
|
188
212
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// Local algo - no external server needed
|
|
193
|
-
ui.addLog('info', `Starting algo on ${stats.platform}...`);
|
|
194
|
-
ui.addLog('info', `Symbol: ${symbolName} | Qty: ${contracts}`);
|
|
195
|
-
ui.addLog('info', `Target: $${dailyTarget} | Risk: $${maxRisk}`);
|
|
196
|
-
stats.connected = true;
|
|
197
|
-
|
|
198
|
-
// Poll P&L from API every 2 seconds
|
|
199
|
-
const pollPnL = async () => {
|
|
213
|
+
// Poll data from API - 100% real data
|
|
214
|
+
const pollAPI = async () => {
|
|
200
215
|
try {
|
|
201
|
-
// Get
|
|
216
|
+
// Get account P&L from API
|
|
217
|
+
const accountResult = await service.getTradingAccounts();
|
|
218
|
+
if (accountResult.success && accountResult.accounts) {
|
|
219
|
+
const acc = accountResult.accounts.find(a => a.accountId === account.accountId);
|
|
220
|
+
if (acc && acc.profitAndLoss !== undefined) {
|
|
221
|
+
const accountPnL = acc.profitAndLoss;
|
|
222
|
+
|
|
223
|
+
// Set starting P&L on first poll
|
|
224
|
+
if (startingPnL === null) {
|
|
225
|
+
startingPnL = accountPnL;
|
|
226
|
+
ui.addLog('info', `Starting P&L: $${startingPnL.toFixed(2)}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Session P&L = current - starting (both from API)
|
|
230
|
+
const sessionPnL = accountPnL - startingPnL;
|
|
231
|
+
stats.pnl = sessionPnL;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Get positions from API
|
|
202
236
|
const posResult = await service.getPositions(account.accountId);
|
|
237
|
+
|
|
203
238
|
if (posResult.success && posResult.positions) {
|
|
204
|
-
// Find position for
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
239
|
+
// Find position for selected contract
|
|
240
|
+
const position = posResult.positions.find(p => {
|
|
241
|
+
const posSymbol = p.contractId || p.symbol || '';
|
|
242
|
+
return posSymbol.includes(contract.name) || posSymbol.includes(contract.id);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (position) {
|
|
246
|
+
const positionPnL = position.profitAndLoss || 0;
|
|
211
247
|
|
|
212
|
-
// Detect trade completion
|
|
213
|
-
if (Math.abs(
|
|
214
|
-
const tradePnL =
|
|
248
|
+
// Detect trade completion (position P&L changed significantly)
|
|
249
|
+
if (lastPositionPnL !== 0 && Math.abs(positionPnL - lastPositionPnL) > 0.01) {
|
|
250
|
+
const tradePnL = positionPnL - lastPositionPnL;
|
|
215
251
|
stats.trades++;
|
|
216
|
-
|
|
252
|
+
|
|
253
|
+
if (tradePnL > 0) {
|
|
217
254
|
stats.wins++;
|
|
218
|
-
ui.addLog('trade',
|
|
255
|
+
ui.addLog('trade', `+$${tradePnL.toFixed(2)}`);
|
|
219
256
|
} else {
|
|
220
257
|
stats.losses++;
|
|
221
|
-
ui.addLog('loss',
|
|
258
|
+
ui.addLog('loss', `-$${Math.abs(tradePnL).toFixed(2)}`);
|
|
222
259
|
}
|
|
223
260
|
}
|
|
261
|
+
|
|
262
|
+
lastPositionPnL = positionPnL;
|
|
263
|
+
|
|
264
|
+
// Log position info from API
|
|
265
|
+
if (position.quantity && position.quantity !== 0) {
|
|
266
|
+
const side = position.quantity > 0 ? 'LONG' : 'SHORT';
|
|
267
|
+
const qty = Math.abs(position.quantity);
|
|
268
|
+
ui.addLog('info', `${side} ${qty}x @ P&L: $${positionPnL.toFixed(2)}`);
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
// No position for this symbol
|
|
272
|
+
lastPositionPnL = 0;
|
|
224
273
|
}
|
|
225
274
|
}
|
|
226
275
|
|
|
227
|
-
// Check target/risk limits
|
|
276
|
+
// Check target/risk limits (using SESSION P&L, not account total)
|
|
228
277
|
if (stats.pnl >= dailyTarget) {
|
|
229
278
|
stopReason = 'target';
|
|
230
279
|
running = false;
|
|
231
|
-
ui.addLog('success', `TARGET
|
|
280
|
+
ui.addLog('success', `SESSION TARGET! +$${stats.pnl.toFixed(2)}`);
|
|
232
281
|
} else if (stats.pnl <= -maxRisk) {
|
|
233
282
|
stopReason = 'risk';
|
|
234
283
|
running = false;
|
|
235
|
-
ui.addLog('error', `MAX RISK
|
|
284
|
+
ui.addLog('error', `SESSION MAX RISK! -$${Math.abs(stats.pnl).toFixed(2)}`);
|
|
236
285
|
}
|
|
286
|
+
|
|
237
287
|
} catch (e) {
|
|
238
|
-
|
|
288
|
+
ui.addLog('error', `API: ${e.message}`);
|
|
239
289
|
}
|
|
240
290
|
};
|
|
241
291
|
|
|
@@ -245,9 +295,9 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
245
295
|
measureLatency(); // Initial measurement
|
|
246
296
|
const latencyInterval = setInterval(() => { if (running) measureLatency(); }, 5000);
|
|
247
297
|
|
|
248
|
-
// Poll
|
|
249
|
-
|
|
250
|
-
const
|
|
298
|
+
// Poll data from API every 2 seconds
|
|
299
|
+
pollAPI(); // Initial poll
|
|
300
|
+
const apiInterval = setInterval(() => { if (running) pollAPI(); }, 2000);
|
|
251
301
|
|
|
252
302
|
// Keyboard
|
|
253
303
|
const setupKeyHandler = () => {
|
|
@@ -276,7 +326,7 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
276
326
|
|
|
277
327
|
clearInterval(refreshInterval);
|
|
278
328
|
clearInterval(latencyInterval);
|
|
279
|
-
clearInterval(
|
|
329
|
+
clearInterval(apiInterval);
|
|
280
330
|
if (cleanupKeys) cleanupKeys();
|
|
281
331
|
ui.cleanup();
|
|
282
332
|
|