From 3ebd6e3fb6760fb8d0cf5327edf48cf3f602c66d Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Tue, 13 May 2025 14:17:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=98=E5=86=85=E4=B8=8B?= =?UTF-8?q?=E5=8D=88(13~15=E7=82=B9)=E6=8B=89=E5=8F=96K=E7=BA=BF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=97=B6=E5=80=99,11.30=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=BC=9A=E5=8F=98=E6=88=9013.00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/model_kline.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/protocol/model_kline.go b/protocol/model_kline.go index 1922dfa..7df5c1f 100644 --- a/protocol/model_kline.go +++ b/protocol/model_kline.go @@ -177,7 +177,7 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) { resp.List = append(resp.List, k) } - + resp.List = FixKlineTime(resp.List) return resp, nil } @@ -185,3 +185,27 @@ type KlineCache struct { Type uint8 //1分钟,5分钟,日线等 Kind string //指数,个股等 } + +// FixKlineTime 修复盘内下午(13~15点)拉取数据的时候,11.30的时间变成13.00 +func FixKlineTime(ks []*Kline) []*Kline { + if len(ks) == 0 { + return ks + } + now := time.Now() + //只有当天下午13~15点之间才会出现的时间问题 + node1 := time.Date(now.Year(), now.Month(), now.Day(), 13, 0, 0, 0, now.Location()) + node2 := time.Date(now.Year(), now.Month(), now.Day(), 15, 0, 0, 0, now.Location()) + if ks[len(ks)-1].Time.Unix() < node1.Unix() || ks[len(ks)-1].Time.Unix() > node2.Unix() { + return ks + } + ls := ks + if len(ls) >= 120 { + ls = ls[len(ls)-120:] + } + for i, v := range ls { + if v.Time.Unix() == node1.Unix() { + ls[i].Time = time.Date(now.Year(), now.Month(), now.Day(), 11, 30, 0, 0, now.Location()) + } + } + return ks +}