临时解决盘口价格不对的问题,感觉不是很合理

This commit is contained in:
钱纯净
2025-03-17 21:51:53 +08:00
parent cd5cf290f1
commit 4114bc72dd
2 changed files with 79 additions and 38 deletions

View File

@@ -40,7 +40,7 @@ func NewCodes(c *Client, filename string) (*Codes, error) {
}
update := new(UpdateModel)
{ //插入一条数据
{ //查询或者插入一条数据
has, err := db.Get(update)
if err != nil {
return nil, err
@@ -57,22 +57,38 @@ func NewCodes(c *Client, filename string) (*Codes, error) {
Codes: nil,
}
//设置定时器,每天早上9点更新数据
task := cron.New(cron.WithSeconds())
task.AddFunc("0 0 9 * * *", func() {
for i := 0; i < 3; i++ {
if err := cc.Update(); err == nil {
return
{ //设置定时器,每天早上9点更新数据
task := cron.New(cron.WithSeconds())
task.AddFunc("0 0 9 * * *", func() {
for i := 0; i < 3; i++ {
if err := cc.Update(); err == nil {
return
}
logs.Err(err)
<-time.After(time.Minute * 5)
}
})
task.Start()
}
{ //判断是否更新过,更新过则不更新
now := time.Now()
node := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.Local)
updateTime := time.Unix(update.Time, 0)
if now.Sub(node) > 0 {
//当前时间在9点之后,且更新时间在9点之前,需要更新
if updateTime.Sub(node) < 0 {
return cc, cc.Update()
}
} else {
//当前时间在9点之前,且更新时间在上个节点之前
if updateTime.Sub(node.Add(time.Hour*24)) < 0 {
return cc, cc.Update()
}
logs.Err(err)
<-time.After(time.Minute * 5)
}
})
task.Start()
//判断是否更新过,更新过则不更新
//time.Unix(update.Time,0).A
}
//从缓存中加载
return cc, cc.Update(true)
}
@@ -118,7 +134,9 @@ func (this *Codes) Update(byCache ...bool) error {
codeMap[code.Exchange+code.Code] = code
}
this.Codes = codeMap
return nil
//更新时间
_, err = this.db.Update(&UpdateModel{Time: time.Now().Unix()})
return err
}
// Code 更新股票并返回结果