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 {