mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
feat: 更新网格引擎,优化订单填充检测逻辑,增强对历史键和元数据的比较处理
This commit is contained in:
@@ -454,7 +454,10 @@ export class GridEngine {
|
|||||||
private async syncGridSimple(price: number): Promise<void> {
|
private async syncGridSimple(price: number): Promise<void> {
|
||||||
const activeOrders = this.openOrders.filter((o) => o.symbol === this.config.symbol && o.type === "LIMIT");
|
const activeOrders = this.openOrders.filter((o) => o.symbol === this.config.symbol && o.type === "LIMIT");
|
||||||
|
|
||||||
// Detect fills by comparing last keys
|
// Detect fills by comparing previous keys vs current snapshot
|
||||||
|
const prevKeys = this.lastOpenOrderKeys;
|
||||||
|
const prevMeta = this.lastKeyMeta;
|
||||||
|
|
||||||
const currentKeys = new Set<string>();
|
const currentKeys = new Set<string>();
|
||||||
const keyToMeta = new Map<string, { side: "BUY" | "SELL"; level: number; reduceOnly: boolean }>();
|
const keyToMeta = new Map<string, { side: "BUY" | "SELL"; level: number; reduceOnly: boolean }>();
|
||||||
for (const o of activeOrders) {
|
for (const o of activeOrders) {
|
||||||
@@ -465,11 +468,10 @@ export class GridEngine {
|
|||||||
keyToMeta.set(key, { side: o.side, level, reduceOnly: o.reduceOnly === true });
|
keyToMeta.set(key, { side: o.side, level, reduceOnly: o.reduceOnly === true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// persist metadata for next tick to detect fills
|
|
||||||
this.lastKeyMeta = keyToMeta;
|
for (const prevKey of prevKeys) {
|
||||||
for (const prevKey of this.lastOpenOrderKeys) {
|
|
||||||
if (currentKeys.has(prevKey)) continue;
|
if (currentKeys.has(prevKey)) continue;
|
||||||
const meta = this.lastKeyMeta.get(prevKey) || keyToMeta.get(prevKey);
|
const meta = prevMeta.get(prevKey);
|
||||||
// If we can't resolve from current snapshot, try to decode by stored mapping
|
// If we can't resolve from current snapshot, try to decode by stored mapping
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
// For reduce-only disappearance, check mapping
|
// For reduce-only disappearance, check mapping
|
||||||
@@ -512,6 +514,8 @@ export class GridEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.lastOpenOrderKeys = currentKeys;
|
this.lastOpenOrderKeys = currentKeys;
|
||||||
|
// persist metadata for next tick to detect fills
|
||||||
|
this.lastKeyMeta = keyToMeta;
|
||||||
|
|
||||||
// Desired open orders according to locked sides
|
// Desired open orders according to locked sides
|
||||||
const desired: DesiredGridOrder[] = [];
|
const desired: DesiredGridOrder[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user