kestrel.markets
Version:
A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.
25 lines (21 loc) • 976 B
JavaScript
// Library quickstart — the text DSL and the typed object model are the SAME language.
// `parse` turns Kestrel text into typed objects; `print` turns them back into canonical
// text, and the round-trip is byte-stable (ADR-0004). Run it after `npm i kestrel.markets`:
//
// node examples/roundtrip.mjs
//
// From a fresh clone of this repo, build first so the import resolves:
//
// bun install && bun run build && node examples/roundtrip.mjs
//
import { parse, print } from "kestrel.markets/lang";
const source = `PLAN fade-flush budget 0.4R ttl 15:30 regime {intraday: range}
USING signal SPX exec SPY 0dte
WHEN spot crosses below 5150
DO buy 1 -1 P @ lean(bid, fair, 0.5)
TP 2x frac 0.5 @ fair
INVALIDATE spot > 5185 held 120s`;
const doc = parse(source); // text -> typed object model
const canonical = print(doc); // model -> canonical text
console.log(canonical);
console.log("\nround-trip byte-stable:", print(parse(canonical)) === canonical);