1Branch0Tags
GL
glucryptoRefresh package-lock for opentool 0.19.5
a06de7114 hours ago10Commits
typescript
import type { ToolProfile } from "opentool"; import { backtestDecisionRequestSchema, buildBacktestDecisionSeriesInput, resolveBacktestMode, } from "opentool/backtest"; import { DIRECTIONAL_BOT_TEMPLATE_CONFIG, readConfig, resolveProfileAssets, resolveScheduleConfig, } from "../src/config"; import { buildBacktestDecisionSeries, runSignalBot } from "../src/directional-bot"; const config = readConfig(); export const schema = backtestDecisionRequestSchema.partial(); type BacktestAwareToolProfile = ToolProfile & { backtest?: { mode: "decisions"; }; }; export const profile: BacktestAwareToolProfile = { description: "Compact Hyperliquid directional strategy starter with optional live execution and decision backtests.", category: "strategy", backtest: { mode: "decisions", }, templatePreview: { subtitle: "Compact Hyperliquid execution starter with config-first setup and preview backtests.", description: `Uses a compact TWAP sell plan as the default strategy. Keeps the config contract, schedule metadata, and a hosted preview backtest path. Includes an optional real Hyperliquid order path for live execution. Designed as a low-token base for builder rewrites into custom Hyperliquid execution strategies.`, }, schedule: resolveScheduleConfig(config), assets: resolveProfileAssets(config), templateConfig: DIRECTIONAL_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") { const parsed = schema.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" }, } ); } try { const backtest = await buildBacktestDecisionSeries({ config: snapshot, ...buildBacktestDecisionSeriesInput(parsed.data), }); return Response.json({ ok: true, mode: normalizedMode, backtest, }); } 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 { return Response.json(await runSignalBot(snapshot)); } 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" }, }); } }