hedgequantx 1.3.9 → 1.3.10
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
CHANGED
|
@@ -211,7 +211,10 @@ class ProjectXService {
|
|
|
211
211
|
|
|
212
212
|
// Get P&L for active accounts only
|
|
213
213
|
if (account.status === 0) {
|
|
214
|
-
|
|
214
|
+
let openPnL = 0;
|
|
215
|
+
let todayPnL = 0;
|
|
216
|
+
|
|
217
|
+
// 1. Get unrealized P&L from open positions
|
|
215
218
|
try {
|
|
216
219
|
const posRes = await this._request(
|
|
217
220
|
this.propfirm.userApi,
|
|
@@ -221,18 +224,49 @@ class ProjectXService {
|
|
|
221
224
|
debug(`Positions for ${account.accountId}:`, JSON.stringify(posRes.data, null, 2));
|
|
222
225
|
|
|
223
226
|
if (posRes.statusCode === 200 && Array.isArray(posRes.data)) {
|
|
224
|
-
let openPnL = 0;
|
|
225
227
|
for (const pos of posRes.data) {
|
|
226
228
|
if (pos.profitAndLoss !== undefined && pos.profitAndLoss !== null) {
|
|
227
229
|
openPnL += pos.profitAndLoss;
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
|
-
enriched.openPnL = openPnL;
|
|
231
|
-
enriched.profitAndLoss = openPnL; // Open P&L from positions
|
|
232
232
|
}
|
|
233
233
|
} catch (e) {
|
|
234
234
|
debug('Failed to get positions:', e.message);
|
|
235
235
|
}
|
|
236
|
+
|
|
237
|
+
// 2. Get realized P&L from today's closed trades
|
|
238
|
+
try {
|
|
239
|
+
const today = new Date();
|
|
240
|
+
today.setHours(0, 0, 0, 0);
|
|
241
|
+
const now = new Date();
|
|
242
|
+
|
|
243
|
+
const tradesRes = await this._request(
|
|
244
|
+
this.propfirm.gatewayApi,
|
|
245
|
+
'/api/Trade/search',
|
|
246
|
+
'POST',
|
|
247
|
+
{
|
|
248
|
+
accountId: account.accountId,
|
|
249
|
+
startTimestamp: today.toISOString(),
|
|
250
|
+
endTimestamp: now.toISOString()
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
debug(`Today trades for ${account.accountId}:`, JSON.stringify(tradesRes.data, null, 2));
|
|
254
|
+
|
|
255
|
+
if (tradesRes.statusCode === 200) {
|
|
256
|
+
const trades = Array.isArray(tradesRes.data) ? tradesRes.data : (tradesRes.data.trades || []);
|
|
257
|
+
for (const trade of trades) {
|
|
258
|
+
if (trade.profitAndLoss !== undefined && trade.profitAndLoss !== null) {
|
|
259
|
+
todayPnL += trade.profitAndLoss;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} catch (e) {
|
|
264
|
+
debug('Failed to get today trades:', e.message);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
enriched.openPnL = openPnL;
|
|
268
|
+
enriched.todayPnL = todayPnL;
|
|
269
|
+
enriched.profitAndLoss = openPnL + todayPnL; // Total day P&L = unrealized + realized
|
|
236
270
|
}
|
|
237
271
|
|
|
238
272
|
debug(`Account ${account.accountId}:`, {
|