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

サンプル 19

One chart per symbol

make sure there is a chart for each symbol of a watch list, at

カテゴリ
Workspace:チャートやパネルを読む・変更する
権限
workspace.readworkspace.write
実行する前に
a terminal window
何をするか
CHANGES YOUR WORKSPACE — opens one chart panel for each
実行方法
in TTT, open the T0 Editor, open this file, grant workspace.read
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.3, <0.2.0
必要なもの
workspace >=0.1.2, <0.2.0

ソース

// Purpose: make sure there is a chart for each symbol of a watch list, at
// one timeframe, opening only the ones that are missing. Running it twice
// changes nothing the second time.
// Category: workspace
// Permissions: workspace.read, workspace.write
// Preconditions: a terminal window
// Side effects: CHANGES YOUR WORKSPACE — opens one chart panel for each
// listed symbol that the terminal offers and that has no chart yet.
// Run: in TTT, open the T0 Editor, open this file, grant workspace.read
// and workspace.write, Run. Edit `watch` and `timeframe` to taste.

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

fn main() -> Result<Unit, Error> {
    let watch = ["BTCUSDT", "ETHUSDT", "SOLUSDT"];
    let timeframe = "1h";
    let offered = workspace.symbols();

    for symbol in watch {
        if !list.contains(offered, symbol) {
            print(symbol + ": not offered by this terminal, skipped");
        } else {
            let mut open = false;
            for c in workspace.charts() {
                if c.symbol == symbol {
                    open = true;
                }
            }
            if open {
                print(symbol + ": already has a chart");
            } else {
                let opened = workspace.open_chart(symbol, timeframe)?;
                print(symbol + ": opened " + opened.timeframe);
            }
        }
    }
    print(to_string(workspace.charts().len()) + " chart(s) open now");
    return Ok(());
}