DXtrade: date transactions by the firm's day, not the CT trade date

The firm rolls its day at 22:00 UTC; our trade date at 5 PM CT. In summer
they coincide, in winter the firm's rolls an hour earlier. New entries are
already kept out of that hour, but a take-profit or stop that fills in it
was booked to the day before. firmDayOf labels the firm's day the way
currentTradeDateCT labels ours, and the sync's transfer window now starts
at the firm day behind today's trade date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-27 13:59:25 -05:00
co-authored by Claude Opus 5.5
parent 934620e8e9
commit 7f55e49755
3 changed files with 36 additions and 6 deletions
+12 -5
View File
@@ -25,7 +25,8 @@
* - Cash transactions (SETTLEMENT, COMMISSION, FINANCING, DEPOSIT,
* WITHDRAWAL…) are the books: daily P&L, fund transactions, today's
* realized P&L and the balance at the firm's 22:00 UTC reset all come from
* them.
* them. Each is dated by the firm's day (firmDayOf), which in winter rolls
* an hour before our 5 PM CT trade date.
* - No auto-liquidation profile: autoLiqThresholds stays 0; a breached
* account shows as accountStatus ≠ FULL_TRADING → active=false.
*/
@@ -44,7 +45,7 @@ import type { PlatformClient, PlatformAccount, PlatformContract, ClientHealth, P
import { OrderNotPlacedError, isOrderNotPlaced, errorMessage } from './platform-client';
import {
dxAccountId, accountDisplayName, accountCodeOf, encodeContractName, decodeContractName, roundToStep,
lastUtcReset, ctTradeDayStart, timeOf, parseDurationMs, ciNum, isFundType, signedFundValue, newOrderCode,
lastUtcReset, ctTradeDayStart, firmDayOf, timeOf, parseDurationMs, ciNum, isFundType, signedFundValue, newOrderCode,
inTradingHours, realizedVolPerHour, scoreCandidate, candidateRejection, parseTransfers, marginRateOf,
} from './dxtrade-helpers';
import type { DxTxn } from './dxtrade-helpers';
@@ -614,7 +615,13 @@ export class DXTradeClient implements PlatformClient {
const orders = new Map<string, DxOrder[]>();
let txns: DxTxn[] = [];
const now = new Date();
const windowStart = new Date(Math.min(ctTradeDayStart(now).getTime(), lastUtcReset(now, FIRM_RESET_UTC_HOUR).getTime()) - 5 * 60_000);
// From the firm's day that today's trade date names (in winter it
// began an hour before 5 PM CT) and the current reset, whichever
// is earlier.
const windowStart = new Date(Math.min(
lastUtcReset(ctTradeDayStart(now), FIRM_RESET_UTC_HOUR).getTime(),
lastUtcReset(now, FIRM_RESET_UTC_HOUR).getTime(),
) - 5 * 60_000);
if (codes.length > 0) {
try {
for (const m of await this.perAccounts<Record<string, unknown>>('/accounts/metrics', codes, (d) => (d as { metrics?: unknown[] })?.metrics ?? [])) {
@@ -659,7 +666,7 @@ export class DXTradeClient implements PlatformClient {
this.recentTxns.set(acc.id, map);
let realized = 0;
for (const t of map.values()) {
if (!isFundType(t.type) && currentTradeDateCT(new Date(t.time)) === today) realized += t.value;
if (!isFundType(t.type) && firmDayOf(new Date(t.time), FIRM_RESET_UTC_HOUR) === today) realized += t.value;
}
this.accountCashBalances[acc.id] = {
amount: balance, realizedPnL: round2(realized), equity: ciNum(m, 'equity'), availableFunds: ciNum(m, 'availableFunds'),
@@ -913,7 +920,7 @@ export class DXTradeClient implements PlatformClient {
const daily = new Map<string, { pnl: number; fees: number }>();
const funds = new Map<string, number>();
for (const t of mine) {
const date = currentTradeDateCT(new Date(t.time));
const date = firmDayOf(new Date(t.time), FIRM_RESET_UTC_HOUR);
if (isFundType(t.type)) {
funds.set(date, (funds.get(date) ?? 0) + signedFundValue(t.type, t.value));
continue;