Vest: no leg opens past 8 PM ET until a sync has read the new day

The engine's Vest day now turns with the client's numbers, at the first
sync after the reset. A leg opened between 8 PM ET and that sync would be
planned and counted on the day that ended, so both the pick and the open
wait for it. The claim log's "stage N next" counts payouts the way the
engine picks its stage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-10-27 16:10:16 -05:00
co-authored by Claude Opus 5.5
parent e02838409b
commit dc210ffcb7
3 changed files with 23 additions and 3 deletions
+4 -2
View File
@@ -18,7 +18,7 @@ import {
BIG_DAY_THRESHOLD, LEG_COMPLETION_EPSILON, MAX_LEGS_PER_DAY, BIG_DAY_THRESHOLD, LEG_COMPLETION_EPSILON, MAX_LEGS_PER_DAY,
FALLBACK_COMMISSION_PER_CONTRACT, MAX_COMMISSION_PER_CONTRACT, DLL_MIN_STOP, FALLBACK_COMMISSION_PER_CONTRACT, MAX_COMMISSION_PER_CONTRACT, DLL_MIN_STOP,
CME_EVENING_OPEN_MIN, foldReason, withinFirmCaps, CME_EVENING_OPEN_MIN, foldReason, withinFirmCaps,
fundRowsKey, markFinishedCycle, unbookedPayoutDrop, machineSide, stageInputsFor, floorRoom, shortestNextLeg, fundRowsKey, markFinishedCycle, unbookedPayoutDrop, machineSide, stageInputsFor, stagePayouts, floorRoom, shortestNextLeg,
claimedCycle, withinEndedCycleWindow, claimedCycle, withinEndedCycleWindow,
type DayPlan, type FinishedCycleMark, type ClaimedCycle, type DayPlan, type FinishedCycleMark, type ClaimedCycle,
} from './trading-logic'; } from './trading-logic';
@@ -2099,7 +2099,9 @@ function afterClaim(
console.error(`${tag} ${firm.name} ${acc.name}: the completed cycle the claim ended wasn't saved — ${errorMessage(err)}`); console.error(`${tag} ${firm.name} ${acc.name}: the completed cycle the claim ended wasn't saved — ${errorMessage(err)}`);
} }
} }
const stage = 1 + (client.sameDayClaims?.(acc.id) ?? 0); // The stage the engine trades next, counted as it counts it (stagePayouts).
const cfg = getAccountConfig(acc.id).accountType;
const stage = 1 + stagePayouts(client.fundTransactions?.[acc.id] ?? [], cfg ? stageInputsFor(client, acc.id, cfg) : {});
console.log(`${tag} ${firm.name} ${acc.name}: claimed $${claimed}${received !== null ? ` (you get $${received})` : ''}` console.log(`${tag} ${firm.name} ${acc.name}: claimed $${claimed}${received !== null ? ` (you get $${received})` : ''}`
+ ` — trading stage ${stage} next (${tradeDate})`); + ` — trading stage ${stage} next (${tradeDate})`);
return stage; return stage;
+14
View File
@@ -777,6 +777,13 @@ export class VestClient implements PlatformClient {
return vestDayOf(this.numbersAt > 0 ? Math.min(now, this.numbersAt) : now); return vestDayOf(this.numbersAt > 0 ? Math.min(now, this.numbersAt) : now);
} }
/** Past 8 PM ET with the numbers still the ended day's: a leg opened now
* would be planned and counted on that day, so none opens until a sync
* has read the new one. */
private newDayUnread(now: number): boolean {
return this.tradeDate(now) !== vestDayOf(now);
}
/** /**
* See PlatformClient: the gain since the day's base that is still in the * See PlatformClient: the gain since the day's base that is still in the
* account — since this client's own claim today, else since the reset, * account — since this client's own claim today, else since the reset,
@@ -1766,6 +1773,10 @@ export class VestClient implements PlatformClient {
console.log(`${this.tag} ${root} → nothing tradable — Vest's 8 PM ET reset in ${Math.ceil(toReset / 60_000)} min`); console.log(`${this.tag} ${root} → nothing tradable — Vest's 8 PM ET reset in ${Math.ceil(toReset / 60_000)} min`);
return null; return null;
} }
if (root !== 'survey' && this.newDayUnread(now)) {
console.log(`${this.tag} ${root} → nothing tradable — Vest's day has turned and no sync has read it yet`);
return null;
}
for (const symbol of symbols) { for (const symbol of symbols) {
const spec = specs.get(symbol); const spec = specs.get(symbol);
if (!spec) { board.push({ symbol, score: null, note: 'unknown symbol' }); continue; } if (!spec) { board.push({ symbol, score: null, note: 'unknown symbol' }); continue; }
@@ -1963,6 +1974,9 @@ export class VestClient implements PlatformClient {
if (toReset <= RESET_ENTRY_BLOCK_MS) { if (toReset <= RESET_ENTRY_BLOCK_MS) {
throw new OrderNotPlacedError(`Vest's 8 PM ET reset is ${Math.ceil(toReset / 60_000)} min away — no new position until it passes`); throw new OrderNotPlacedError(`Vest's 8 PM ET reset is ${Math.ceil(toReset / 60_000)} min away — no new position until it passes`);
} }
if (this.newDayUnread(Date.now())) {
throw new OrderNotPlacedError(`Vest's day has turned and no sync has read it yet — no new position until one has`);
}
const opposite = side === 'long' ? 'short' : 'long'; const opposite = side === 'long' ? 'short' : 'long';
const hedged = [...this.positionsDetail.values()].flat().some((p) => p.symbol === symbol && p.side === opposite) const hedged = [...this.positionsDetail.values()].flat().some((p) => p.symbol === symbol && p.side === opposite)
|| this.openingSides.get(symbol)?.side === opposite; || this.openingSides.get(symbol)?.side === opposite;
+5 -1
View File
@@ -58,7 +58,7 @@ const {
const { vestDayOf, vestAccountId, VestApiError, VEST_STATUS_ACTIVE } = await import('../lib/vest-helpers.ts'); const { vestDayOf, vestAccountId, VestApiError, VEST_STATUS_ACTIVE } = await import('../lib/vest-helpers.ts');
const { encodeContractName } = await import('../lib/dxtrade-helpers.ts'); const { encodeContractName } = await import('../lib/dxtrade-helpers.ts');
const { tradeDateFor, stageInputsFor, resolveEffectiveConfig, claimedCycle, endedCycleCompletion } = await import('../lib/trading-logic.ts'); const { tradeDateFor, stageInputsFor, resolveEffectiveConfig, claimedCycle, endedCycleCompletion } = await import('../lib/trading-logic.ts');
const { isClientReady } = await import('../lib/platform-client.ts'); const { isClientReady, isOrderNotPlaced } = await import('../lib/platform-client.ts');
const iso = (s) => Date.parse(s); const iso = (s) => Date.parse(s);
const WALLET = '0x7ce10771819f80130e204ddb5ca1522e48a9b451'; const WALLET = '0x7ce10771819f80130e204ddb5ca1522e48a9b451';
@@ -383,6 +383,10 @@ test("the client's Vest day turns with its numbers, and a sync that stalls stops
assert.equal(vestDayOf(Date.now()), '2026-10-28'); assert.equal(vestDayOf(Date.now()), '2026-10-28');
assert.equal(engineDay(), '2026-10-27'); assert.equal(engineDay(), '2026-10-27');
assert.equal(isClientReady(client), true); assert.equal(isClientReady(client), true);
// Nothing opens on the ended day's numbers.
const opening = await client.sendOrder(A, encodeContractName('NDX-USD', 0.001), 500, 'Buy', 'Market', undefined, 'open').catch((err) => err);
assert.equal(isOrderNotPlaced(opening), true);
assert.match(opening.message, /no sync has read it yet/);
await client.requestSync(); await client.requestSync();
assert.equal(engineDay(), '2026-10-28'); assert.equal(engineDay(), '2026-10-28');
// No sync after the next reset: the day holds back only while the // No sync after the next reset: the day holds back only while the