← すべてのサンプル
サンプル 31
Level alert
the script of a Price Trigger Line that raises an alert: a chime on this terminal and, if you give it an address, a
- カテゴリ
- Workspace:チャートやパネルを読む・変更する
- 権限
- workspace.writeexternal.access
- 実行する前に
- set as the script of a Price Trigger Line with workspace.write and external.access ticked on its Trigger page
- 何をするか
- sounds the alert chime; with a WEBHOOK, POSTS a message to that address (at most once a second, 20 a minute).
- 実行方法
- place a Price Trigger Line (left rail, Lines), Trigger page: Choose… this file. "Run now" tests it without waiting.
- 言語
>=0.1.1, <0.2.0- ホスト
>=0.1.6, <0.2.0- 必要なもの
- alert >=0.1.0, <0.2.0event >=0.1.0, <0.2.0
ソース
// Purpose: the script of a Price Trigger Line that raises an alert: a chime on this terminal and, if you give it an address, a // message to your Discord channel. The message says what crossed and where; the address is yours and never leaves this file. // Category: workspace // Permissions: workspace.write, external.access // Preconditions: set as the script of a Price Trigger Line with workspace.write and external.access ticked on its Trigger page // (a program asks for what it can ever use, and this one can post). To post to Discord, paste your channel's webhook address into // WEBHOOK below; left empty it only sounds the chime on this terminal. // Side effects: sounds the alert chime; with a WEBHOOK, POSTS a message to that address (at most once a second, 20 a minute). // Run: place a Price Trigger Line (left rail, Lines), Trigger page: Choose… this file. "Run now" tests it without waiting. lang ">=0.1.1, <0.2.0"; host "ttt" ">=0.1.6, <0.2.0"; requires "alert" ">=0.1.0, <0.2.0"; requires "event" ">=0.1.0, <0.2.0"; const WEBHOOK: String = ""; fn main() -> Result<Unit, Error> { let e = event.current(); let symbol = e.symbol.unwrap_or("the market"); let level = match e.price { Some(p) => to_string(p), None => "the line", }; let message = symbol + " crossed " + level; alert.notify("Level crossed", message)?; if WEBHOOK != "" { match alert.webhook("discord", WEBHOOK, message + " · sent from TTT") { Ok(_) => print("posted to Discord"), Err(err) => print("the webhook failed: " + err.code + ": " + err.message), } } print(message); return Ok(()); }