mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
refactor: streamline order handling logic in LighterGateway by consolidating market ID checks and improving snapshot order clearing
This commit is contained in:
@@ -687,8 +687,6 @@ export class LighterGateway {
|
|||||||
const channelMarketId = this.extractMarketIdFromChannel(message.channel);
|
const channelMarketId = this.extractMarketIdFromChannel(message.channel);
|
||||||
if (position && Number.isFinite(Number(position.market_id))) {
|
if (position && Number.isFinite(Number(position.market_id))) {
|
||||||
this.mergePositions([position]);
|
this.mergePositions([position]);
|
||||||
} else if (type === "subscribed/account_market" && channelMarketId != null) {
|
|
||||||
this.removePositionsForMarkets([channelMarketId]);
|
|
||||||
}
|
}
|
||||||
if (Array.isArray(message.orders) && message.orders.length) {
|
if (Array.isArray(message.orders) && message.orders.length) {
|
||||||
const marketId = Number(position?.market_id ?? channelMarketId ?? this.marketId ?? NaN);
|
const marketId = Number(position?.market_id ?? channelMarketId ?? this.marketId ?? NaN);
|
||||||
@@ -823,11 +821,13 @@ export class LighterGateway {
|
|||||||
|
|
||||||
private applyOrderList(rawOrders: unknown, marketId: number | null, snapshot: boolean): void {
|
private applyOrderList(rawOrders: unknown, marketId: number | null, snapshot: boolean): void {
|
||||||
const orders = this.normalizeOrders(rawOrders);
|
const orders = this.normalizeOrders(rawOrders);
|
||||||
|
if (snapshot) {
|
||||||
if (marketId != null) {
|
if (marketId != null) {
|
||||||
this.clearOrdersForMarket(marketId);
|
this.clearOrdersForMarket(marketId);
|
||||||
} else if (snapshot) {
|
} else {
|
||||||
this.orderMap.clear();
|
this.orderMap.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (const order of orders) {
|
for (const order of orders) {
|
||||||
this.applyOrderUpdate(order);
|
this.applyOrderUpdate(order);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user