Compare commits

...

10 Commits

Author SHA1 Message Date
钱纯净
50c997f26f 细节优化 2025-03-03 19:35:56 +08:00
injoyai
0740ff7ca0 优化RangeDesc 2025-02-28 10:38:24 +08:00
injoyai
81f2ffcbea 优化RangeDesc 2025-02-28 10:36:13 +08:00
injoyai
8a63c2ff2e 增加RangeDesc,倒序遍历工作日,从今天-1990年12月19日(上海交易所成立时间) 2025-02-28 10:23:11 +08:00
injoyai
71035fb210 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	workday.go
2025-02-28 09:36:45 +08:00
injoyai
f479d99c99 修改沪市指数的数据时间作为是否开市的依据,替换掉平安银行(可能会出现停牌无数据的情况,历史出现过3次) 2025-02-28 09:35:58 +08:00
钱纯净
ddb36b5aa7 增加Workday的方法RangeDesc,用于遍历所有工作日,根据平安银行的日线数据,但是还有比平安银行更早上市的公司,会有些误差 2025-02-26 21:40:41 +08:00
injoyai
ddc4b801bf 增加默认连接 2025-02-26 13:26:10 +08:00
injoyai
e22d2776e7 细节优化 2025-02-24 17:00:02 +08:00
injoyai
f46b97e1e1 细节优化 2025-02-24 16:57:48 +08:00
3 changed files with 36 additions and 10 deletions

View File

@@ -38,6 +38,11 @@ func Dial(addr string, op ...client.Option) (cli *Client, err error) {
return DialWith(tcp.NewDial(addr), op...)
}
// DialDefault 默认连接方式
func DialDefault(op ...client.Option) (cli *Client, err error) {
return DialWith(NewHostDial(Hosts), op...)
}
// DialHosts 与服务器建立连接,多个服务器轮询,开启重试生效
func DialHosts(hosts []string, op ...client.Option) (cli *Client, err error) {
return DialWith(NewHostDial(hosts), op...)

View File

@@ -9,11 +9,17 @@ import (
func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
//初始化配置
if cfg == nil {
cfg = &ManageConfig{}
}
if len(cfg.Hosts) == 0 {
cfg.Hosts = Hosts
}
if cfg.Dir == "" {
cfg.Dir = "./data/"
if cfg.CodesDir == "" {
cfg.CodesDir = "./data/database"
}
if cfg.WorkdayDir == "" {
cfg.WorkdayDir = "./data/database"
}
//连接池
@@ -30,24 +36,25 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
return nil, err
}
codesClient.Wait.SetTimeout(time.Second * 5)
codes, err := NewCodes(codesClient, filepath.Join(cfg.Dir, "database/codes.db"))
codes, err := NewCodes(codesClient, filepath.Join(cfg.CodesDir, "codes.db"))
if err != nil {
return nil, err
}
///工作日
//工作日
workdayClient, err := DialHosts(cfg.Hosts, op...)
if err != nil {
return nil, err
}
workdayClient.Wait.SetTimeout(time.Second * 5)
workday, err := NewWorkday(workdayClient, filepath.Join(cfg.Dir, "database/codes.db"))
workday, err := NewWorkday(workdayClient, filepath.Join(cfg.WorkdayDir, "workday.db"))
if err != nil {
return nil, err
}
return &Manage{
Pool: p,
Config: cfg,
Codes: codes,
Workday: workday,
Cron: cron.New(cron.WithSeconds()),
@@ -56,6 +63,7 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
type Manage struct {
*Pool
Config *ManageConfig
Codes *Codes
Workday *Workday
Cron *cron.Cron
@@ -71,7 +79,8 @@ func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) {
}
type ManageConfig struct {
Hosts []string //服务端IP
Number int //客户端数量
Dir string //数据位置
Hosts []string //服务端IP
Number int //客户端数量
CodesDir string //代码数据位置
WorkdayDir string //工作日数据库位置
}

View File

@@ -59,7 +59,7 @@ type Workday struct {
// Update 更新
func (this *Workday) Update() error {
//获取平安银行的日K线,用作历史是否节假日的判断依据
//获取沪市指数的日K线,用作历史是否节假日的判断依据
//判断日K线是否拉取过
//获取全部工作日
@@ -77,7 +77,7 @@ func (this *Workday) Update() error {
now := time.Now()
if lastWorkday == nil || lastWorkday.Unix < IntegerDay(now).Unix() {
resp, err := this.Client.GetKlineDayAll("sz000001")
resp, err := this.Client.GetKlineDayAll("sh000001")
if err != nil {
logs.Err(err)
return err
@@ -110,6 +110,18 @@ func (this *Workday) TodayIs() bool {
return this.Is(time.Now())
}
// RangeDesc 倒序遍历工作日,从今天-1990年12月19日(上海交易所成立时间)
func (this *Workday) RangeDesc(f func(t time.Time) bool) {
t := IntegerDay(time.Now())
for ; t.After(time.Date(1990, 12, 18, 0, 0, 0, 0, time.Local)); t = t.Add(-time.Hour * 24) {
if this.Is(t) {
if !f(t) {
return
}
}
}
}
// WorkdayModel 工作日
type WorkdayModel struct {
ID int64 `json:"id"` //主键