function main() {
while (!exchange.IO("status")) Sleep(1000)
exchange.SetContractType("rb888")
var r = exchange.GetRecords(PERIOD_H1)
if (!r || r.length < 48) return
r = r.slice(-48)
var top = r.reduce(function (a, b) { return b.Close > a.Close ? b : a })
LogStatus({
type: "chart", title: "最近48小时",
x: r.map(function (b) { return b.Time }),
series: [
{name: "收盘价", data: r.map(function (b) { return b.Close })},
{name: "成交量", kind: "bar", axis: "right", color: "muted",
data: r.map(function (b) { return b.Volume })}
],
marks: [{x: top.Time, text: "最高", color: "up"}]
})
}
python
def main():
while not exchange.IO("status"):
Sleep(1000)
exchange.SetContractType("rb888")
r = exchange.GetRecords(PERIOD_H1)
if not r or len(r) < 48:
return
r = r[-48:]
top = max(r, key=lambda b: b["Close"])
LogStatus({
"type": "chart", "title": "最近48小时",
"x": [b["Time"] for b in r],
"series": [
{"name": "收盘价", "data": [b["Close"] for b in r]},
{"name": "成交量", "kind": "bar", "axis": "right", "color": "muted",
"data": [b["Volume"] for b in r]}
],
"marks": [{"x": top["Time"], "text": "最高", "color": "up"}]
})
rust
fn join<T: ToString>(v: impl Iterator<Item = T>) -> String {
v.map(|x| x.to_string()).collect::<Vec<_>>().join(",")
}
fn main() {
while !exchange.IO("status").is_ok_and(|v| v.as_i64() == Some(1)) {
Sleep(1000);
}
if exchange.SetContractType("rb888").is_err() { return; }
let Ok(r) = exchange.GetRecords(None, PERIOD_H1, None) else { return };
if r.len() < 48 { return; }
let r = &r[r.len() - 48..];
let top = r.iter().fold(&r[0], |a, b| if b.Close > a.Close { b } else { a });
LogStatus!(format!(
r#"{{"type": "chart", "title": "最近48小时", "x": [{}], "series": [
{{"name": "收盘价", "data": [{}]}},
{{"name": "成交量", "kind": "bar", "axis": "right", "color": "muted", "data": [{}]}}],
"marks": [{{"x": {}, "text": "最高", "color": "up"}}]}}"#,
join(r.iter().map(|b| b.Time)),
join(r.iter().map(|b| b.Close)),
join(r.iter().map(|b| b.Volume)),
top.Time
));
}