2 Star 15 Fork 17

王布衣/engine

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
services_state.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-20 15:00 +08:00 . 增加系统服务子命令
package services
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/gotdx/trading"
"gitee.com/quant1x/gox/api"
"os"
"path/filepath"
"time"
)
func stateFilename(date, timestamp string) string {
date = trading.FixTradeDate(date)
t, _ := time.ParseInLocation(trading.CN_SERVERTIME_FORMAT, timestamp, time.Local)
//timestamp = t.Format(trading.CN_SERVERTIME_SHORT_FORMAT)
timestamp = t.Format("150405")
tm := date + "T" + timestamp
filename := fmt.Sprintf("%s/update.%s", cache.GetVariablePath(), tm)
return filename
}
// 状态文件不存在则可更新, 反之不可更新
func checkUpdateState(date, timestamp string) bool {
filename := stateFilename(date, timestamp)
return !api.FileExist(filename)
}
// 确定完成当期更新状态
func doneUpdate(date, timestamp string) {
filename := stateFilename(date, timestamp)
file, err := os.Create(filename)
if err != nil {
return
}
api.CloseQuietly(file)
}
// 清理过期的状态文件
func cleanExpiredStateFiles() error {
statePath := cache.GetVariablePath()
filePaths, err := filepath.Glob(statePath + "/update.*")
if err != nil {
return err
}
for _, filePath := range filePaths {
_ = os.Remove(filePath)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.7.3

搜索帮助