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);
-8
View File
@@ -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;
}