max: reduce kline parsing cost

This commit is contained in:
c9s 2021-06-28 14:17:40 +08:00 committed by c9s
parent f64b0e7a9f
commit 75a2abeeab
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -192,17 +192,19 @@ func parseKLineEvent(val *fastjson.Value) (*KLineEvent, error) {
Timestamp: val.GetInt64("T"), Timestamp: val.GetInt64("T"),
} }
k := val.Get("k")
event.KLine = KLine{ event.KLine = KLine{
Symbol: string(val.GetStringBytes("k", "M")), Symbol: string(k.GetStringBytes("M")),
Interval: string(val.GetStringBytes("k", "R")), Interval: string(k.GetStringBytes("R")),
StartTime: time.Unix(0, val.GetInt64("k", "ST")*int64(time.Millisecond)), StartTime: time.Unix(0, k.GetInt64("ST")*int64(time.Millisecond)),
EndTime: time.Unix(0, val.GetInt64("k", "ET")*int64(time.Millisecond)), EndTime: time.Unix(0, k.GetInt64("ET")*int64(time.Millisecond)),
Open: fixedpoint.MustNewFromBytes(val.GetStringBytes("k", "O")), Open: fixedpoint.MustNewFromBytes(k.GetStringBytes("O")),
High: fixedpoint.MustNewFromBytes(val.GetStringBytes("k", "H")), High: fixedpoint.MustNewFromBytes(k.GetStringBytes("H")),
Low: fixedpoint.MustNewFromBytes(val.GetStringBytes("k", "L")), Low: fixedpoint.MustNewFromBytes(k.GetStringBytes("L")),
Close: fixedpoint.MustNewFromBytes(val.GetStringBytes("k", "C")), Close: fixedpoint.MustNewFromBytes(k.GetStringBytes("C")),
Volume: fixedpoint.MustNewFromBytes(val.GetStringBytes("k", "v")), Volume: fixedpoint.MustNewFromBytes(k.GetStringBytes("v")),
Closed: val.GetBool("k", "x"), Closed: k.GetBool("x"),
} }
return &event, nil return &event, nil