hedgequantx 2.3.17 → 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 +35 -28
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
|
@@ -189,7 +189,8 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
189
189
|
|
|
190
190
|
let running = true;
|
|
191
191
|
let stopReason = null;
|
|
192
|
-
let
|
|
192
|
+
let startingPnL = null; // P&L at algo start (from API)
|
|
193
|
+
let lastPositionPnL = 0;
|
|
193
194
|
|
|
194
195
|
// Log startup info from API
|
|
195
196
|
ui.addLog('info', `Connection: ${connectionType}`);
|
|
@@ -212,6 +213,25 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
212
213
|
// Poll data from API - 100% real data
|
|
213
214
|
const pollAPI = async () => {
|
|
214
215
|
try {
|
|
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
|
+
|
|
215
235
|
// Get positions from API
|
|
216
236
|
const posResult = await service.getPositions(account.accountId);
|
|
217
237
|
|
|
@@ -223,62 +243,49 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
223
243
|
});
|
|
224
244
|
|
|
225
245
|
if (position) {
|
|
226
|
-
|
|
227
|
-
const apiPnL = position.profitAndLoss || 0;
|
|
246
|
+
const positionPnL = position.profitAndLoss || 0;
|
|
228
247
|
|
|
229
|
-
// Detect trade completion (P&L changed)
|
|
230
|
-
if (
|
|
231
|
-
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;
|
|
232
251
|
stats.trades++;
|
|
233
252
|
|
|
234
253
|
if (tradePnL > 0) {
|
|
235
254
|
stats.wins++;
|
|
236
|
-
ui.addLog('trade', `+$${tradePnL.toFixed(2)}
|
|
255
|
+
ui.addLog('trade', `+$${tradePnL.toFixed(2)}`);
|
|
237
256
|
} else {
|
|
238
257
|
stats.losses++;
|
|
239
|
-
ui.addLog('loss', `-$${Math.abs(tradePnL).toFixed(2)}
|
|
258
|
+
ui.addLog('loss', `-$${Math.abs(tradePnL).toFixed(2)}`);
|
|
240
259
|
}
|
|
241
260
|
}
|
|
242
261
|
|
|
243
|
-
|
|
244
|
-
stats.pnl = apiPnL;
|
|
262
|
+
lastPositionPnL = positionPnL;
|
|
245
263
|
|
|
246
264
|
// Log position info from API
|
|
247
265
|
if (position.quantity && position.quantity !== 0) {
|
|
248
266
|
const side = position.quantity > 0 ? 'LONG' : 'SHORT';
|
|
249
267
|
const qty = Math.abs(position.quantity);
|
|
250
|
-
ui.addLog('info',
|
|
268
|
+
ui.addLog('info', `${side} ${qty}x @ P&L: $${positionPnL.toFixed(2)}`);
|
|
251
269
|
}
|
|
252
270
|
} else {
|
|
253
|
-
// No position
|
|
254
|
-
|
|
255
|
-
ui.addLog('info', 'Position closed - Flat');
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Get account balance from API
|
|
261
|
-
const accountResult = await service.getTradingAccounts();
|
|
262
|
-
if (accountResult.success && accountResult.accounts) {
|
|
263
|
-
const acc = accountResult.accounts.find(a => a.accountId === account.accountId);
|
|
264
|
-
if (acc && acc.profitAndLoss !== undefined) {
|
|
265
|
-
stats.pnl = acc.profitAndLoss;
|
|
271
|
+
// No position for this symbol
|
|
272
|
+
lastPositionPnL = 0;
|
|
266
273
|
}
|
|
267
274
|
}
|
|
268
275
|
|
|
269
|
-
// Check target/risk limits (using
|
|
276
|
+
// Check target/risk limits (using SESSION P&L, not account total)
|
|
270
277
|
if (stats.pnl >= dailyTarget) {
|
|
271
278
|
stopReason = 'target';
|
|
272
279
|
running = false;
|
|
273
|
-
ui.addLog('success', `TARGET
|
|
280
|
+
ui.addLog('success', `SESSION TARGET! +$${stats.pnl.toFixed(2)}`);
|
|
274
281
|
} else if (stats.pnl <= -maxRisk) {
|
|
275
282
|
stopReason = 'risk';
|
|
276
283
|
running = false;
|
|
277
|
-
ui.addLog('error', `MAX RISK! -$${Math.abs(stats.pnl).toFixed(2)}`);
|
|
284
|
+
ui.addLog('error', `SESSION MAX RISK! -$${Math.abs(stats.pnl).toFixed(2)}`);
|
|
278
285
|
}
|
|
279
286
|
|
|
280
287
|
} catch (e) {
|
|
281
|
-
ui.addLog('error', `API
|
|
288
|
+
ui.addLog('error', `API: ${e.message}`);
|
|
282
289
|
}
|
|
283
290
|
};
|
|
284
291
|
|