1Branch0Tags
GL
glucryptoFix exact Hyperliquid symbols
7d8b23fa month ago76Commits
typescript
import { store } from "opentool/store"; import type { ToolProfile } from "opentool"; import { buildBacktestDecisionSeriesInput, backtestDecisionRequestSchema, resolveBacktestMode, } from "opentool/backtest"; import { readConfig, resolveProfileAssets, resolveScheduleConfig, SIGNAL_BOT_TEMPLATE_CONFIG, } from "../src/config"; import { buildBacktestDecisionSeries, runSignalBot, } from "../src/signal-bot"; const config = readConfig(); export const schema = backtestDecisionRequestSchema.partial(); type BacktestAwareToolProfile = ToolProfile & { backtest?: { mode: "decisions"; }; }; export const profile: BacktestAwareToolProfile = { description: "Hyperliquid price signal bot.", category: "strategy", backtest: { mode: "decisions", }, templatePreview: { subtitle: "Indicator-driven Hyperliquid signal strategy with fixed-amount sizing.", description: `Runs on a configured market schedule and evaluates one or more technical indicators. Maps the resulting signal into a standardized Hyperliquid trade decision. Uses fixed USD sizing as the primary launcher-facing budget model. Supports execution routing, leverage, and indicator-specific tuning after launch.`, }, schedule: resolveScheduleConfig(config), assets: resolveProfileAssets(config), templateConfig: SIGNAL_BOT_TEMPLATE_CONFIG, }; export async function POST(req: Request) { const snapshot = readConfig(); const payload = await req.json().catch(() => null); const mode = payload && typeof payload === "object" && !Array.isArray(payload) ? (payload as { mode?: unknown }).mode : null; const normalizedMode = resolveBacktestMode(mode); if (normalizedMode === "backtest_decisions") { try { const parsed = backtestDecisionRequestSchema.safeParse(payload); if (!parsed.success) { return new Response( JSON.stringify({ ok: false, error: parsed.error.issues[0]?.message ?? "invalid backtest request payload", }), { status: 400, headers: { "content-type": "application/json" }, } ); } const backtest = parsed.data; const decisionSeries = await buildBacktestDecisionSeries({ config: snapshot, ...buildBacktestDecisionSeriesInput(backtest), }); return Response.json({ ok: true, mode: normalizedMode, backtest: decisionSeries, }); } catch (error) { const message = error instanceof Error ? error.message : "unknown"; return new Response(JSON.stringify({ ok: false, error: message }), { status: 400, headers: { "content-type": "application/json" }, }); } } try { const result = await runSignalBot(snapshot); await store({ source: "signal-bot", ref: `signal-bot-${Date.now()}`, status: result.ok ? "info" : "failed", action: "signal", metadata: result, }); return Response.json(result); } catch (error) { const message = error instanceof Error ? error.message : "unknown"; await store({ source: "signal-bot", ref: `signal-bot-${Date.now()}`, status: "failed", action: "signal", metadata: { ok: false, error: message }, }); return new Response(JSON.stringify({ ok: false, error: message }), { status: 400, headers: { "content-type": "application/json" }, }); } }