Ir al contenido
← Todos los ejemplos

Ejemplo 22

Focus or open

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

Categoría
Espacio de trabajo: lee o cambia gráficos y paneles
Permisos
workspace.readworkspace.write
Antes de ejecutarlo
a terminal window; the symbol offered by the terminal
Qué hace
CHANGES YOUR WORKSPACE — focuses a chart, or opens one (at
Cómo ejecutarlo
in TTT, open the T0 Editor, open this file, grant workspace.read
Lenguaje
>=0.1.1, <0.2.0
Host
>=0.1.3, <0.2.0
Necesita
workspace >=0.1.2, <0.2.0

Código

// 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(());
}