DXtrade: an entry never closes a hand trade, and a flatten never opens one

DXtrade dropped the intent the engine now passes, so on the live
Tradeify247 accounts an entry could still close a hand position as the
"entry" and the leg's flatten then OPEN a position with no exits. The
open/close decision moves out of vest-helpers into platform-client's
orderEffect, which both clients now follow to pick OPEN or CLOSE.

A flatten's flat read is "nothing to flatten" only when the client's own
record agrees. One empty read just after a fill the client saw may be the
gateway lagging, so it stays a plain refusal and keeps the FLATTEN FAILED
alarm. A check now fails if an engine order drops its intent or a client
stops going by orderEffect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-10-27 14:13:07 -05:00
co-authored by Claude Opus 5.5
parent e90f21ed91
commit 378530595e
7 changed files with 147 additions and 94 deletions
-28
View File
@@ -421,34 +421,6 @@ export function unrealizedPnl(p: Pick<VestPosition, 'side' | 'quantity' | 'openP
return (p.side === 'long' ? 1 : -1) * p.quantity * (mark - p.openPrice);
}
/**
* What an order on `side` does to the account's position in the symbol
* (`held`: its side, null when flat), or why nothing is sent. With no intent
* a flat account opens and the opposite side closes or reduces. An entry
* ('open') never closes: a hand trade the engine didn't know about would be
* closed in its place, and the leg's flatten would then open a position with
* no exits. A flatten ('close') never opens: nothingToClose says the account
* is flat in the symbol. Adding to a position is never supported.
*/
export function vestOrderEffect(o: {
symbol: string;
held: 'long' | 'short' | null;
side: 'long' | 'short';
intent?: 'open' | 'close';
}): { effect: 'open' | 'close' } | { refused: string; nothingToClose?: true } {
const { symbol, held, side, intent } = o;
if (held === side) {
return {
refused: intent === 'close'
? `the account holds a ${held} ${symbol} position, not one to close — nothing sent`
: `adding to an open ${symbol} position is not supported`,
};
}
if (held && intent === 'open') return { refused: `a ${held} ${symbol} position is already open — an entry never closes it, order not sent` };
if (!held && intent === 'close') return { refused: `no ${symbol} position to close — nothing sent`, nothingToClose: true };
return { effect: held ? 'close' : 'open' };
}
// ── transactions ────────────────────────────────────────────────────────────
/**