mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 01:08:07 +00:00
feat: 更新网格引擎,添加新逻辑以处理无持仓和无挂单状态,优化网格状态清理和初始侧分配功能
This commit is contained in:
@@ -56,3 +56,24 @@ export async function saveGridState(snapshot: StoredGridState): Promise<void> {
|
||||
map[snapshot.symbol] = snapshot;
|
||||
await fs.writeFile(GRID_FILE, JSON.stringify(map, null, 2), "utf8");
|
||||
}
|
||||
|
||||
export async function clearGridState(symbol: string): Promise<void> {
|
||||
const map = await readStateFile();
|
||||
if (!Object.prototype.hasOwnProperty.call(map, symbol)) {
|
||||
return;
|
||||
}
|
||||
delete map[symbol];
|
||||
const entries = Object.keys(map);
|
||||
if (!entries.length) {
|
||||
try {
|
||||
await fs.unlink(GRID_FILE);
|
||||
} catch (error: any) {
|
||||
if (!error || (error.code !== "ENOENT" && error.code !== "ENOTDIR")) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
await ensureDataDir();
|
||||
await fs.writeFile(GRID_FILE, JSON.stringify(map, null, 2), "utf8");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user