mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 00:38:07 +00:00
fix retry
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
export function isUnknownOrderError(error: unknown): boolean {
|
||||
const message = extractMessage(error);
|
||||
if (!message) return false;
|
||||
return message.includes("Unknown order") || message.includes("code\":-2011");
|
||||
}
|
||||
|
||||
export function extractMessage(error: unknown): string {
|
||||
if (typeof error === "string") return error;
|
||||
if (error instanceof Error) return error.message;
|
||||
try {
|
||||
return JSON.stringify(error);
|
||||
} catch {
|
||||
return String(error);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
const DATA_DIR = path.resolve(process.cwd(), "data");
|
||||
let dataDirReady = false;
|
||||
|
||||
async function ensureDataDir(): Promise<void> {
|
||||
if (dataDirReady) return;
|
||||
await fs.mkdir(DATA_DIR, { recursive: true }).catch(() => undefined);
|
||||
dataDirReady = true;
|
||||
}
|
||||
|
||||
export async function loadState<T>(fileName: string): Promise<T | null> {
|
||||
try {
|
||||
await ensureDataDir();
|
||||
const filePath = path.join(DATA_DIR, fileName);
|
||||
const data = await fs.readFile(filePath, "utf8");
|
||||
return JSON.parse(data) as T;
|
||||
} catch (error: any) {
|
||||
if (error?.code === "ENOENT") return null;
|
||||
console.error(`[state] load ${fileName} failed`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveState(fileName: string, state: unknown): Promise<void> {
|
||||
try {
|
||||
await ensureDataDir();
|
||||
const filePath = path.join(DATA_DIR, fileName);
|
||||
const tempPath = `${filePath}.tmp`;
|
||||
const payload = JSON.stringify(state, null, 2);
|
||||
await fs.writeFile(tempPath, payload, "utf8");
|
||||
await fs.rename(tempPath, filePath);
|
||||
} catch (error) {
|
||||
console.error(`[state] save ${fileName} failed`, error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user