T0 Lang 문서
터미널의 스크립트를 작성하는 언어. 사양, 표준 라이브러리, 호스트 API, 도구와 함께 순수 계산부터 전략까지의 예제 프로그램을 담았습니다.
이 페이지는 영어입니다. 하나의 언어로 유지된 사양은 하나의 내용만 말합니다.
완전한 프로그램
어디에도 이진 반올림이 없는 정확한 금액 계산. 이런 프로그램에는 권한이 전혀 필요하지 않습니다.
// 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
언어
- 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
도구
- 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.
런타임과 보안
버전 관리
구조
- 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
예제
실제 컴파일러와 런타임을 거치는 프로그램. 각각 필요한 권한과 터미널에 하는 일을 밝힙니다.