本文へ移動
← すべてのサンプル

サンプル 01

Exact fees

Exact money: what a fill costs, with no binary rounding anywhere.

カテゴリ
Pure:どこでも動く
権限
なし
言語
>=0.1.1, <0.2.0

ソース

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