← Todos los ejemplos
Ejemplo 13
Open chart
open a new chart in the terminal, at a chosen timeframe, and
- Categoría
- Espacio de trabajo: lee o cambia gráficos y paneles
- Permisos
- workspace.readworkspace.write
- Antes de ejecutarlo
- a terminal window; at least one symbol on offer
- Qué hace
- CHANGES YOUR WORKSPACE — opens one chart panel (of the
- Cómo ejecutarlo
- in TTT, open "T0 Lang", open this file, grant workspace.read and
- 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: open a new chart in the terminal, at a chosen timeframe, and // check it is really there; show that refused requests open nothing. // Category: workspace // Permissions: workspace.read, workspace.write // Preconditions: a terminal window; at least one symbol on offer // Side effects: CHANGES YOUR WORKSPACE — opens one chart panel (of the // first symbol the terminal offers, at 15m) and puts it in focus. // Run: in TTT, open "T0 Lang", open this file, grant workspace.read and // workspace.write, Run. 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> { // The rule: the first symbol the terminal offers. No symbol is assumed // to exist in every installation. let symbol = workspace.symbols().first().expect("the terminal offers no symbol to chart"); let before = workspace.charts().len(); match workspace.open_chart("NOT-A-SYMBOL", "15m") { Ok(_) => print("unexpected: an unknown symbol was charted"), Err(e) => print("refused as it should be: " + e.code), } match workspace.open_chart(symbol, "fortnight") { Ok(_) => print("unexpected: an unknown timeframe was accepted"), Err(e) => print("refused as it should be: " + e.code), } print("charts after the refusals: " + to_string(workspace.charts().len() - before) + " new"); let opened = workspace.open_chart(symbol, "15m")?; // Not trusted from the answer alone: read back from the terminal. let now = workspace.chart(opened.chart)?; print("opened " + now.symbol + " " + now.timeframe + (if now.active { ", in focus" } else { ", NOT in focus" })); print("charts now: " + to_string(workspace.charts().len() - before) + " new"); let mut shown = false; for p in workspace.panels() { match p.chart { Some(c) => { if c == opened.chart { shown = true; } } None => {} } } print(if shown { "it has a panel of its own" } else { "it has NO panel" }); return Ok(()); }