diff --git a/app/api/trades/route.ts b/app/api/trades/route.ts index c94d250..03ee9d4 100644 --- a/app/api/trades/route.ts +++ b/app/api/trades/route.ts @@ -29,7 +29,7 @@ export async function GET(req: Request) { const open = t.closedAt === null && t.closeReason === null && t.closedBy === null; const closedBy = open ? null : t.closedBy === 'bot' ? 'bot' - : t.closeReason === 'user_requested' ? (tracked(t.closedAt ?? t.openedAt) ? 'outside' : 'user_requested') + : t.closeReason === 'user_requested' ? (t.closedBy === 'outside' || tracked(t.closedAt ?? t.openedAt) ? 'outside' : 'user_requested') : t.closeReason ?? 'unknown'; const net = open || t.pnl === null ? null : Math.round((t.pnl - Math.abs(t.fee ?? 0) + (t.funding ?? 0)) * 100) / 100; @@ -48,7 +48,7 @@ export async function GET(req: Request) { net, openedAt: t.openedAt, closedAt: t.closedAt, - openedBy: t.openedBy === 'bot' ? 'bot' : tracked(t.openedAt) ? 'outside' : null, + openedBy: t.openedBy === 'bot' ? 'bot' : t.openedBy === 'outside' || tracked(t.openedAt) ? 'outside' : null, closedBy, }; }); diff --git a/lib/db.ts b/lib/db.ts index fd0edfb..63976f7 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -582,7 +582,9 @@ export function wipeAccountData(accountId: number): void { // Every position a platform's history shows — the bot's and anyone else's // (Vest: GET /v3/positions). The platform can't tell an API order from a // click, so opened_by / closed_by record what this instance did itself: -// 'bot' when its own order opened or closed the position, NULL otherwise. +// 'bot' when its own order opened or closed the position, NULL otherwise — +// or 'outside', set by hand for a trade from before marking began whose +// origin the bot's own log settles. // A wipe leaves these alone: they're refetched, but the marks aren't. db.exec(`