本文へ移動

T0 Lang ドキュメント

ターミナルのスクリプトを書く言語。仕様、標準ライブラリ、ホストAPI、ツール類と、純粋な計算から戦略までのサンプルプログラム。

これらのページは英語です。仕様は一つの言語で保つことで、一つのことだけを語ります。

完全なプログラム

どこにも2進の丸めがない、正確なお金の計算。このようなプログラムに権限は一切必要ありません。

// 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

ツール

ランタイムとセキュリティ

バージョン管理

仕組み

サンプル

実際のコンパイラとランタイムを通るプログラム。それぞれ、必要な権限とターミナルへの作用を記しています。

サンプル