mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
feat: 更新 Lighter 适配器的账户快照逻辑,支持市场符号和市场 ID 过滤功能
This commit is contained in:
@@ -660,7 +660,13 @@ export class LighterGateway {
|
|||||||
|
|
||||||
private emitAccount(): void {
|
private emitAccount(): void {
|
||||||
if (!this.accountDetails) return;
|
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);
|
this.accountEvent.emit(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,9 +140,21 @@ export function toAccountSnapshot(
|
|||||||
symbol: string,
|
symbol: string,
|
||||||
details: LighterAccountDetails,
|
details: LighterAccountDetails,
|
||||||
positions: LighterPosition[] = [],
|
positions: LighterPosition[] = [],
|
||||||
assets: AsterAccountAsset[] = []
|
assets: AsterAccountAsset[] = [],
|
||||||
|
options?: { marketSymbol?: string | null; marketId?: number | null }
|
||||||
): AsterAccountSnapshot {
|
): 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 aggregateUnrealized = transformedPositions.reduce((acc, pos) => acc + Number(pos.unrealizedProfit ?? 0), 0);
|
||||||
const assetList = assets.length ? assets : defaultAsset(details);
|
const assetList = assets.length ? assets : defaultAsset(details);
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user