feat: 更新 Lighter 适配器的账户快照逻辑,支持市场符号和市场 ID 过滤功能

This commit is contained in:
discountry
2025-10-06 19:17:24 +08:00
parent d2867ba98c
commit 0d2aa84b84
2 changed files with 21 additions and 3 deletions
+7 -1
View File
@@ -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);
}
+14 -2
View File
@@ -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 {