UNPKG

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.

47 lines (45 loc) 1.45 kB
// src/blotter/protocol-view.ts function settledAtOf(b) { const asOf = b.totals.settle_mark?.as_of_ts; if (typeof asOf === "number") return new Date(asOf).toISOString(); let maxTs = 0; for (const p of b.plans) for (const s of p.lifecycle) if (s.ts > maxTs) maxTs = s.ts; return new Date(maxTs).toISOString(); } function toProtocolTotals(b) { const t = b.totals; const sm = t.settle_mark; const settle_mark = sm === undefined ? undefined : { stale: sm.stale, source: sm.source, mark_uncertain: sm.mark_uncertain, note: sm.note }; return { floor: t.floor, expected: t.expected, ...t.sampled !== undefined ? { sampled: t.sampled } : {}, headline: { channel: t.headline.channel, usd: t.headline.usd, gate: { qualified: t.headline.gate.qualified, reasons: t.headline.gate.reasons }, tainted: t.headline.tainted, reasons: t.headline.reasons }, ...settle_mark !== undefined ? { settle_mark } : {} }; } function toProtocolFillClaim(b) { return b.fill_claim.map((c) => ({ support: c.support, expected: c.expected, gain: c.gain, loss: c.loss })); } function toProtocolBlotter(sessionId, b) { return { sessionId, orders: [], fills: [], positions: [], settlement: { realized: b.totals.floor, asset: "usd", settledAt: settledAtOf(b) }, totals: toProtocolTotals(b), fill_claim: toProtocolFillClaim(b) }; } export { toProtocolBlotter };