From 974d3017e0351579988da057073adae2a09eda46 Mon Sep 17 00:00:00 2001 From: discountry Date: Mon, 8 Dec 2025 19:57:57 +0800 Subject: [PATCH] fix position --- src/exchanges/lighter/gateway.ts | 10 +++++++++- src/exchanges/lighter/mappers.ts | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/exchanges/lighter/gateway.ts b/src/exchanges/lighter/gateway.ts index 0700a6a..9ec937e 100644 --- a/src/exchanges/lighter/gateway.ts +++ b/src/exchanges/lighter/gateway.ts @@ -623,9 +623,17 @@ export class LighterGateway { } private applyAccountAssets(assets?: LighterAccountAsset[] | Record | null): void { + const payloadProvided = assets !== undefined && assets !== null; + const hasRawEntries = + Array.isArray(assets) ? assets.length > 0 : isPlainObject(assets) ? Object.keys(assets).length > 0 : false; const normalized = this.normalizeAssets(assets); if (!normalized.length) { - return; // ignore empty payloads to avoid wiping spot balances + // Explicitly clear cached balances when the venue returns an empty payload, + // so closed spot positions don't linger as phantom holdings. + if (payloadProvided && !hasRawEntries) { + this.assets.clear(); + } + return; } for (const asset of normalized) { const key = this.normalizeAssetKey(asset); diff --git a/src/exchanges/lighter/mappers.ts b/src/exchanges/lighter/mappers.ts index 73d0a26..1184cd5 100644 --- a/src/exchanges/lighter/mappers.ts +++ b/src/exchanges/lighter/mappers.ts @@ -301,11 +301,3 @@ function normalizeSymbolForms(value: string): string[] { if (base) forms.add(base); return Array.from(forms); } - -function normalizeMarketType(value: string | null | undefined): "perp" | "spot" | undefined { - if (!value) return undefined; - const normalized = value.toLowerCase(); - if (normalized === "spot") return "spot"; - if (normalized === "perp" || normalized === "perpetual" || normalized === "futures") return "perp"; - return undefined; -}