From 0d2aa84b8474ebc9b35b23792539bc216a64d606 Mon Sep 17 00:00:00 2001 From: discountry Date: Mon, 6 Oct 2025 19:17:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Lighter=20?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=99=A8=E7=9A=84=E8=B4=A6=E6=88=B7=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E7=AC=A6=E5=8F=B7=E5=92=8C=E5=B8=82=E5=9C=BA=20ID=20?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exchanges/lighter/gateway.ts | 8 +++++++- src/exchanges/lighter/mappers.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/exchanges/lighter/gateway.ts b/src/exchanges/lighter/gateway.ts index 98c327f..99a652c 100644 --- a/src/exchanges/lighter/gateway.ts +++ b/src/exchanges/lighter/gateway.ts @@ -660,7 +660,13 @@ export class LighterGateway { private emitAccount(): void { if (!this.accountDetails) return; - const snapshot = toAccountSnapshot(this.displaySymbol, this.accountDetails, this.positions); + const snapshot = toAccountSnapshot( + this.displaySymbol, + this.accountDetails, + this.positions, + [], + { marketSymbol: this.marketSymbol, marketId: this.marketId } + ); this.accountEvent.emit(snapshot); } diff --git a/src/exchanges/lighter/mappers.ts b/src/exchanges/lighter/mappers.ts index b9d46dc..663ff11 100644 --- a/src/exchanges/lighter/mappers.ts +++ b/src/exchanges/lighter/mappers.ts @@ -140,9 +140,21 @@ export function toAccountSnapshot( symbol: string, details: LighterAccountDetails, positions: LighterPosition[] = [], - assets: AsterAccountAsset[] = [] + assets: AsterAccountAsset[] = [], + options?: { marketSymbol?: string | null; marketId?: number | null } ): AsterAccountSnapshot { - const transformedPositions = positions.map((position) => lighterPositionToAster(symbol, position)); + const targetSymbol = options?.marketSymbol?.toUpperCase(); + const targetMarketId = options?.marketId; + const filteredPositions = positions.filter((position) => { + const marketMatches = + targetMarketId == null || + (Number.isFinite(Number(position.market_id)) && Number(position.market_id) === Number(targetMarketId)); + const symbolMatches = + !targetSymbol || + (typeof position.symbol === "string" && position.symbol.toUpperCase() === targetSymbol); + return marketMatches && symbolMatches; + }); + const transformedPositions = filteredPositions.map((position) => lighterPositionToAster(symbol, position)); const aggregateUnrealized = transformedPositions.reduce((acc, pos) => acc + Number(pos.unrealizedProfit ?? 0), 0); const assetList = assets.length ? assets : defaultAsset(details); return {