mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 17:28:08 +00:00
fix position
This commit is contained in:
@@ -623,9 +623,17 @@ export class LighterGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private applyAccountAssets(assets?: LighterAccountAsset[] | Record<string, LighterAccountAsset> | null): void {
|
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);
|
const normalized = this.normalizeAssets(assets);
|
||||||
if (!normalized.length) {
|
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) {
|
for (const asset of normalized) {
|
||||||
const key = this.normalizeAssetKey(asset);
|
const key = this.normalizeAssetKey(asset);
|
||||||
|
|||||||
@@ -301,11 +301,3 @@ function normalizeSymbolForms(value: string): string[] {
|
|||||||
if (base) forms.add(base);
|
if (base) forms.add(base);
|
||||||
return Array.from(forms);
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user