본문으로 건너뛰기

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

01_exact_fees.tz

언어

호스트 API

도구

런타임과 보안

버전 관리

구조

예제

실제 컴파일러와 런타임을 거치는 프로그램. 각각 필요한 권한과 터미널에 하는 일을 밝힙니다.

예제