Concept · Architecture · Why it matters

What is a deterministic computation layer?

A deterministic computation layer is a set of pure functions that maps inputs to outputs with zero variance. Same inputs today, tomorrow, and in six months always produce the same number — enforced by tests, not by convention.

In the context of crypto trading infrastructure, it means: liquidation prices, position sizes, funding costs, and breakeven prices that are exact, auditable, and callable by both humans and machines.

Four properties that define it

Idempotent

Call the same function with the same inputs 1,000 times — you get the same number back each time. No state, no side effects, no timestamp influence.

Traceable

Every output can be reconstructed by hand from the formula. If the math is wrong, it is wrong predictably — not randomly.

Verifiable

An independent party can run the same inputs against the same formula and confirm the result. No black box.

Composable

Deterministic functions can be chained: the output of liquidation_price becomes the input of margin_required, which feeds position_size. Each step is auditable.

How it compares to alternatives

LLM estimate
"Your liquidation is somewhere around $82,000"

Varies between calls. Cannot be audited. Not suitable for risk decisions.

Spreadsheet formula
=B2*(1-1/C2+D2)

Deterministic but not callable by machines. No schema, no versioning, no API.

Deterministic computation layer← this is TradingCalc
liquidation_price({ entry: 85000, leverage: 10, side: "long", mmr: 0.005 }) → 76,925.00

Why trading infrastructure specifically needs this

Trading decisions are binary: open or don't open, exit or hold. A number that is “approximately right” is not useful when the margin call threshold is exact. Determinism is not a preference in risk infrastructure — it is a requirement.

AI trading agents

An LLM calling a deterministic layer gets an exact number it can reason about — not a probabilistic guess. system.verify lets the agent confirm correctness before a trading session.

Risk monitors

Liquidation alerts and margin calls require exact thresholds. A ±0.5% error on liquidation price could mean the alert fires a candle too late.

Backtesting engines

Replaying historical trades requires the same formula every time, not one that changes with model versions or temperature settings.

On-chain oracles

Smart contracts cannot call an LLM. They can call a deterministic function whose output is signed and verifiable on-chain.

How TradingCalc implements it

Every calculator is a pure TypeScript function in src/lib/calculators/. No database reads, no network calls, no random seeds. Each function is covered by canonical test vectors with hand-verified arithmetic.

// Pure function — no side effects export function compute(input: LiquidationInput): LiquidationOutput { const { entry_price, leverage, side, mmr } = input; const liq = side === 'long' ? entry_price * (1 - 1 / leverage + mmr) : entry_price * (1 + 1 / leverage - mmr); return { liquidation_price: round(liq, 2) }; } // Same call, 1,000 times → same output compute({ entry_price: 85000, leverage: 10, side: 'long', mmr: 0.005 }) // → { liquidation_price: 76925.00 }

The same function runs in CI tests, in the REST API, in the MCP layer, and on the public verification page. Three independent surfaces — one formula.

Deterministic workflows: composition over configuration

A workflow is a deterministic pipeline: it chains several computation primitives, adds a decision layer on top, and returns a verdict. The “Should I open this trade?” workflow, for example, calls position sizing → liquidation price → funding cost, then classifies the result as CLEAR / WARN / HIGH RISK.

Use the computation layer directly

19 MCP tools. REST API. Free tier, no signup required. Every call returns an exact, auditable number — same formula as the live calculators.