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

サンプル 06

Workspace

The terminal's own charts: read them, then change the active one.

カテゴリ
Workspace:チャートやパネルを読む・変更する
権限
workspace.readworkspace.write
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.1, <0.2.0
必要なもの
workspace >=0.1.1, <0.2.0

ソース

// Category: workspace
// Permissions: workspace.read, workspace.write
// The terminal's own charts: read them, then change the active one.
// Every change goes through TTT's UI thread; a refusal (an unknown symbol
// or indicator) comes back as an error value to handle, never a crash.
//
// Grant in the T0 Lang window: workspace.read, workspace.write.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.1, <0.2.0";
requires "workspace" ">=0.1.1, <0.2.0";
import std.list;

fn main() -> Result<Unit, Error> {
    for chart in workspace.charts() {
        let marker = if chart.active { "*" } else { " " };
        print(marker + " " + chart.symbol + " " + chart.timeframe);
    }
    let offered = workspace.symbols();
    print(to_string(offered.len()) + " symbols offered; ETHUSDT among them: " + to_string(list.contains(offered, "ETHUSDT")));

    let chart = workspace.active_chart().expect("an open chart");
    workspace.set_timeframe(chart.chart, "15m")?;
    workspace.set_indicator(chart.chart, "EMA", true)?;
    print("drawn on the active chart: " + to_string(workspace.indicators(chart.chart)?));

    match workspace.set_indicator(chart.chart, "Astrology", true) {
        Ok(_) => print("accepted"),
        Err(e) => print("refused: " + e.code),
    }
    return Ok(());
}