Documentación de T0 Lang
El lenguaje en el que se escriben los scripts de la terminal: su especificación, biblioteca estándar, API del host y herramientas, con programas de ejemplo desde cálculos puros hasta estrategias.
Estas páginas están en inglés. Una especificación en un solo idioma dice una sola cosa.
Un programa completo
Dinero exacto, sin redondeo binario en ningún sitio. Un programa así no necesita ningún permiso.
// Category: pure // Permissions: none // Exact money: what a fill costs, with no binary rounding anywhere. // Runs anywhere: `t0 run examples/01_exact_fees.tz`. lang ">=0.1.1, <0.2.0"; import std.decimal; fn main() { let fill = price(64000.50, USDT); let size = qty(0.25); let notional = fill * size; print("notional " + to_string(notional)); let taker = notional * bps(5); let maker = notional * bps(2); print("taker fee " + to_string(taker) + ", maker fee " + to_string(maker)); // 0.1 + 0.2 is 0.3 here: decimals are exact. print(0.1 + 0.2 == 0.3); // Rounding is always written down, and the mode is in the name. print(round(2.25, 1)); print(decimal.round_half_up(2.25, 1)); print(decimal.floor(taker.amount(), 2)); } // expect-output: notional 16000.1250 USDT // expect-output: taker fee 8.00006250 USDT, maker fee 3.20002500 USDT // expect-output: true // expect-output: 2.2 // expect-output: 2.3 // expect-output: 8.00
Lenguaje
- Language SpecificationThe language itself: its syntax, types and rules, version 0.2 included.
- Script kindsThe six kinds of T0 file, each with an extension of its own (.tzi, .tzc, .tzr, .tzp, .tzs, .tzm), and which can start which.
- Standard library (language 0.1)The pure standard library: text, list, decimal, time, fin and causal indicators, and what is deliberately left out.
- Diagnostic code registryEvery diagnostic has a stable code: what each one means and how it is shown.
API del host
Herramientas
- The `t0` command — machine-readable contract (`t0-cli/1`)The `t0` command's machine-readable contract: streams, JSON lines, exit codes and cancellation.
- Language services, formatter and editorsAnalysis, editor services, the formatter, highlighting, `t0 lsp` and TTT's own editor.
- Editor themesChoosing and loading a theme for T0 source, and the format of one.
- Script hooks and trigger linesRunning a script when something happens in the terminal, and trigger lines that run one when the market crosses them.
- PlaybooksA group of strategies, risk scripts and a portfolio controller, and the manager that says which are on, in a backtest and live.
- Writing a risk script and a portfolio scriptWriting a risk policy or a portfolio controller, what they are given and may answer, and how to try one before it trades.
Runtime y seguridad
Versiones
Cómo está construido
- Architecture overviewThe layers, who owns each, and the life of a `.tz` program inside TTT.
- Compiler pipeline and T0 IRThe compiler pipeline and the intermediate form it produces.
- ADR-0001: T0 Lang is its own Cargo workspace; TTT hosts it through a bridge crate
- ADR-0002: The reference runtime runs inside the TTT process, one worker thread per execution
- ADR-0003: Workspace/UI capabilities go through a request queue serviced by the frame loop
- ADR-0004: T0 strategies are lowered to a neutral signal graph and executed by the host's strategy engine
- ADR-0005: Exact decimals by default, floats on request, currency tags checked at runtime
- ADR-0006: Host capabilities are versioned contracts described as data, published in a manifest
- ADR-0007: The T0 IR is a typed, structured tree serialised as JSON
- ADR-0008: Programs declare what they need; sessions grant permissions; every host call is checked
- ADR-0009: A native backend, if built, runs in an isolated worker process
- ADR-0010: Resource governance, backtest capacity and cancellation semantics
- ADR-0011: T0 Lang 0.2 — strict mode, named books, market signals, and the handler model
- ADR-0012: Components: a program says what it is for the host (strategy, risk, portfolio)
- ADR-0013: Scripts start scripts: the `script.run` permission and the signal events
- ADR-0014: Managers and playbooks: one script decides which strategies and risk scripts are on
- ADR-0015: Decorators on strategy parameters: the source says which parameters a host's optimizer may move
- ADR-0016: `switch` and `off` on `@param`: a flag and a filter that can be seen to be on or off
Ejemplos
Programas que pasan por el compilador y el runtime reales. Cada uno dice qué permisos necesita y qué le hace a la terminal.