fix position

This commit is contained in:
discountry
2025-12-08 19:57:57 +08:00
parent 668c3a57d3
commit 974d3017e0
2 changed files with 9 additions and 9 deletions
+9 -1
View File
@@ -623,9 +623,17 @@ export class LighterGateway {
}
private applyAccountAssets(assets?: LighterAccountAsset[] | Record<string, LighterAccountAsset> | 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);