import { parseArgs } from "node:util"; import { Bot } from "./src/bot.js"; import { initDB } from "./src/db.js"; const options = { pairs: { type: "string", short: "p", default: "BTC-USD", }, interval: { type: "string", short: "i", default: "5000", }, threshold: { type: "string", short: "t", default: "0.01", }, }; const { values } = parseArgs({ options, strict: true, allowPositionals: true, args: process.argv.slice(2), }); const pairs = values.pairs.split(",").map((p) => p.trim()); const interval = parseInt(values.interval, 10); const threshold = parseFloat(values.threshold); // Basic validation if (isNaN(interval) || interval < 1000) { console.error("Error: Interval must be a number >= 1000ms"); process.exit(1); } async function run() { console.log("Starting Uphold interview bot..."); console.log( `Configuration: Pairs=[${pairs.join(", ")}] Interval=${interval}ms Threshold=${threshold}%`, ); if (process.env.DATABASE_URL) { await initDB(); } else { console.warn("[Warning] No DATABASE_URL found. Alerts will NOT be saved."); } const bots = pairs.map((pair) => new Bot(pair, interval, threshold)); bots.forEach((b) => b.start()); process.on("SIGINT", () => { console.log("\nShutting down..."); bots.forEach((bot) => bot.stop()); process.exit(0); }); } run().catch((err) => { console.error("Fatal Error:", err); process.exit(1); });