From 5c0bc2a7729fe3294ef79005081da5e223198fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Tue, 1 Apr 2025 18:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes.go | 5 +++++ manage.go | 21 ++++++++++----------- workday.go | 6 ++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/codes.go b/codes.go index 10d08fd..03aa37f 100644 --- a/codes.go +++ b/codes.go @@ -1,6 +1,7 @@ package tdx import ( + "errors" "github.com/injoyai/conv" "github.com/injoyai/logs" "github.com/injoyai/tdx/protocol" @@ -195,6 +196,10 @@ func (this *Codes) Update(byDB ...bool) error { // GetCodes 更新股票并返回结果 func (this *Codes) GetCodes(byDatabase bool) ([]*CodeModel, error) { + if this.Client == nil { + return nil, errors.New("client is nil") + } + //2. 查询数据库所有股票 list := []*CodeModel(nil) if err := this.db.Find(&list); err != nil { diff --git a/manage.go b/manage.go index f716621..7798699 100644 --- a/manage.go +++ b/manage.go @@ -3,7 +3,6 @@ package tdx import ( "github.com/injoyai/ios/client" "github.com/robfig/cron/v3" - "path/filepath" "time" ) @@ -16,11 +15,11 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { if cfg == nil { cfg = &ManageConfig{} } - if cfg.CodesDir == "" { - cfg.CodesDir = DefaultDatabaseDir + if cfg.CodesFilename == "" { + cfg.CodesFilename = DefaultDatabaseDir + "/codes.db" } - if cfg.WorkdayDir == "" { - cfg.WorkdayDir = DefaultDatabaseDir + if cfg.WorkdayFileName == "" { + cfg.WorkdayFileName = DefaultDatabaseDir + "/workday.db" } if cfg.Dial == nil { cfg.Dial = DialDefault @@ -32,7 +31,7 @@ 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.CodesDir, "codes.db")) + codes, err := NewCodes(codesClient, cfg.CodesFilename) if err != nil { return nil, err } @@ -51,7 +50,7 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { return nil, err } workdayClient.Wait.SetTimeout(time.Second * 5) - workday, err := NewWorkday(workdayClient, filepath.Join(cfg.WorkdayDir, "workday.db")) + workday, err := NewWorkday(workdayClient, cfg.WorkdayFileName) if err != nil { return nil, err } @@ -83,8 +82,8 @@ func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) { } type ManageConfig struct { - Number int //客户端数量 - CodesDir string //代码数据库位置 - WorkdayDir string //工作日数据库位置 - Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式 + Number int //客户端数量 + CodesFilename string //代码数据库位置 + WorkdayFileName string //工作日数据库位置 + Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式 } diff --git a/workday.go b/workday.go index ee8a4b9..a06f867 100644 --- a/workday.go +++ b/workday.go @@ -1,6 +1,7 @@ package tdx import ( + "errors" _ "github.com/glebarez/go-sqlite" "github.com/injoyai/base/maps" "github.com/injoyai/logs" @@ -59,6 +60,11 @@ type Workday struct { // Update 更新 func (this *Workday) Update() error { + + if this.Client == nil { + return errors.New("client is nil") + } + //获取沪市指数的日K线,用作历史是否节假日的判断依据 //判断日K线是否拉取过