본문으로 건너뛰기
← 모든 예제

예제 22

Focus or open

bring a symbol's chart to the front, opening one if there is

분류
Workspace: 차트와 패널을 읽거나 변경
권한
workspace.readworkspace.write
실행하기 전에
a terminal window; the symbol offered by the terminal
하는 일
CHANGES YOUR WORKSPACE — focuses a chart, or opens one (at
실행 방법
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: bring a symbol's chart to the front, opening one if there is
// none — the "go to BTCUSDT" of a workspace.
// Category: workspace
// Permissions: workspace.read, workspace.write
// Preconditions: a terminal window; the symbol offered by the terminal
// Side effects: CHANGES YOUR WORKSPACE — focuses a chart, or opens one (at
// 15m) when there is none for the symbol.
// Run: in TTT, open the T0 Editor, open this file, grant workspace.read
// and workspace.write, Run. Change `symbol`.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.3, <0.2.0";
requires "workspace" ">=0.1.2, <0.2.0";

fn main() -> Result<Unit, Error> {
    let symbol = "ETHUSDT";
    for c in workspace.charts() {
        if c.symbol == symbol {
            workspace.focus_chart(c.chart)?;
            print("focused the " + symbol + " " + c.timeframe + " chart");
            return Ok(());
        }
    }
    let opened = workspace.open_chart(symbol, "15m")?;
    print("there was none: opened " + opened.symbol + " " + opened.timeframe);
    return Ok(());
}