mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
修复盘内下午(13~15点)拉取K线数据的时候,11.30的时间会变成13.00
This commit is contained in:
@@ -177,7 +177,7 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) {
|
|||||||
|
|
||||||
resp.List = append(resp.List, k)
|
resp.List = append(resp.List, k)
|
||||||
}
|
}
|
||||||
|
resp.List = FixKlineTime(resp.List)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,3 +185,27 @@ type KlineCache struct {
|
|||||||
Type uint8 //1分钟,5分钟,日线等
|
Type uint8 //1分钟,5分钟,日线等
|
||||||
Kind string //指数,个股等
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user