mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abe39fb2ae | ||
|
|
3ebd6e3fb6 |
20
example/GetKline30MinuteAll/main.go
Normal file
20
example/GetKline30MinuteAll/main.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/injoyai/logs"
|
||||||
|
"github.com/injoyai/tdx"
|
||||||
|
"github.com/injoyai/tdx/example/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.Test(func(c *tdx.Client) {
|
||||||
|
resp, err := c.GetKline30Minute("sz000001", 0, 20)
|
||||||
|
logs.PanicErr(err)
|
||||||
|
|
||||||
|
for _, v := range resp.List {
|
||||||
|
logs.Debug(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.Debug("总数:", resp.Count)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -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