From 7a9d59f8f115cb4197895392ceaa1a0692142539 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Thu, 20 Mar 2025 13:18:49 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 17 +++++++++++++++++ protocol/model_kline.go | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9f45605..8962883 100644 --- a/client.go +++ b/client.go @@ -15,6 +15,16 @@ import ( "time" ) +const ( + LevelNone = 0 + LevelDebug = 2 + LevelWrite = 3 + LevelRead = 4 + LevelInfo = 5 + LevelError = 7 + LevelAll = 999 +) + // WithDebug 是否打印通讯数据 func WithDebug(b ...bool) client.Option { return func(c *client.Client) { @@ -22,6 +32,12 @@ func WithDebug(b ...bool) client.Option { } } +func WithLevel(level int) client.Option { + return func(c *client.Client) { + c.Logger.SetLevel(level) + } +} + // WithRedial 断线重连 func WithRedial(b ...bool) client.Option { return func(c *client.Client) { @@ -31,6 +47,7 @@ func WithRedial(b ...bool) client.Option { // DialDefault 默认连接方式 func DialDefault(op ...client.Option) (cli *Client, err error) { + op = append([]client.Option{WithRedial()}, op...) return DialHostsRange(Hosts, op...) } diff --git a/protocol/model_kline.go b/protocol/model_kline.go index 258b71e..d133d3a 100644 --- a/protocol/model_kline.go +++ b/protocol/model_kline.go @@ -77,7 +77,10 @@ func (this *Kline) RisePrice() Price { // RiseRate 涨跌比例/涨跌幅,第一个数据不准,仅做参考 func (this *Kline) RiseRate() float64 { - return float64(this.RisePrice()) / float64(this.Open) * 100 + if this.Last == 0 { + return float64(this.Close-this.Open) / float64(this.Open) * 100 + } + return float64(this.Close-this.Last) / float64(this.Last) * 100 } type kline struct{} From 80d6d6dfc5a33234a04a0b31f3d3d227114c2b34 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Thu, 20 Mar 2025 13:37:34 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workday.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workday.go b/workday.go index d90f90b..ee8a4b9 100644 --- a/workday.go +++ b/workday.go @@ -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("sh000001") + resp, err := this.Client.GetIndexDayAll("sh000001") if err != nil { logs.Err(err) return err From 0c27cc42767de2f775f0f259ced55b1710c90819 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Mon, 24 Mar 2025 16:28:30 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97,=E6=97=A5=E5=BF=97=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E4=B8=BAInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index c4fdc74..352749d 100644 --- a/client.go +++ b/client.go @@ -8,6 +8,7 @@ import ( "github.com/injoyai/conv" "github.com/injoyai/ios" "github.com/injoyai/ios/client" + "github.com/injoyai/ios/module/common" "github.com/injoyai/logs" "github.com/injoyai/tdx/protocol" "runtime/debug" @@ -16,13 +17,13 @@ import ( ) const ( - LevelNone = 0 - LevelDebug = 2 - LevelWrite = 3 - LevelRead = 4 - LevelInfo = 5 - LevelError = 7 - LevelAll = 999 + LevelNone = common.LevelNone + LevelDebug = common.LevelDebug + LevelWrite = common.LevelWrite + LevelRead = common.LevelRead + LevelInfo = common.LevelInfo + LevelError = common.LevelError + LevelAll = common.LevelAll ) // WithDebug 是否打印通讯数据 @@ -80,7 +81,8 @@ func DialWith(dial ios.DialFunc, op ...client.Option) (cli *Client, err error) { } cli.Client, err = client.Dial(dial, func(c *client.Client) { - c.Logger.Debug(false) //关闭日志打印 + c.Logger.Debug(true) //关闭日志打印 + c.Logger.SetLevel(LevelInfo) //设置日志级别 c.Logger.WithHEX() //以HEX显示 c.SetOption(op...) //自定义选项 c.Event.OnReadFrom = protocol.ReadFrom //分包 From ff7fc6aba01b2ad00ef099ec9ad95eb1377ad876 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Mon, 24 Mar 2025 16:29:03 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0RangDial=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dial.go | 1 + 1 file changed, 1 insertion(+) diff --git a/dial.go b/dial.go index 02ec6b3..d5414de 100644 --- a/dial.go +++ b/dial.go @@ -74,6 +74,7 @@ func NewRangeDial(hosts []string) ios.DialFunc { if i < len(hosts)-1 { //最后一个错误返回出去 logs.Err(err) + <-time.After(time.Second * 3) } } return From e76043dc29bf585e77ecbfcb27db2489a4b5daed Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Mon, 24 Mar 2025 16:33:52 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=BF=9E=E6=8E=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manage.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/manage.go b/manage.go index e78148b..d863bf9 100644 --- a/manage.go +++ b/manage.go @@ -16,19 +16,19 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { if cfg == nil { cfg = &ManageConfig{} } - if len(cfg.Hosts) == 0 { - cfg.Hosts = Hosts - } if cfg.CodesDir == "" { cfg.CodesDir = DefaultDatabaseDir } if cfg.WorkdayDir == "" { cfg.WorkdayDir = DefaultDatabaseDir } + if cfg.Dial == nil { + cfg.Dial = DialDefault + } //代码 DefaultCodes = &Codes{} - codesClient, err := DialHostsRange(cfg.Hosts, op...) + codesClient, err := cfg.Dial(op...) if err != nil { return nil, err } @@ -41,14 +41,14 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { //连接池 p, err := NewPool(func() (*Client, error) { - return DialHostsRange(cfg.Hosts, op...) + return cfg.Dial(op...) }, cfg.Number) if err != nil { return nil, err } //工作日 - workdayClient, err := DialHostsRange(cfg.Hosts, op...) + workdayClient, err := cfg.Dial(op...) if err != nil { return nil, err } @@ -85,8 +85,8 @@ func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) { } type ManageConfig struct { - Hosts []string //服务端IP - Number int //客户端数量 - CodesDir string //代码数据库位置 - WorkdayDir string //工作日数据库位置 + Number int //客户端数量 + CodesDir string //代码数据库位置 + WorkdayDir string //工作日数据库位置 + Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式 } From 1cae60c65e2b104d5fd6db55ffdb966a0d7df52a Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Mon, 24 Mar 2025 16:40:37 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9NewRangeDial=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E9=97=B4=E9=9A=94=E4=B8=BA2=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dial.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dial.go b/dial.go index d5414de..fbff896 100644 --- a/dial.go +++ b/dial.go @@ -73,8 +73,8 @@ func NewRangeDial(hosts []string) ios.DialFunc { } if i < len(hosts)-1 { //最后一个错误返回出去 - logs.Err(err) - <-time.After(time.Second * 3) + logs.Err(err, "等待2秒后尝试下一个服务地址...") + <-time.After(time.Second * 2) } } return From 5e4115d045c88b12e293580d03b922277487c0b5 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Mon, 24 Mar 2025 17:01:24 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9DefaultCodes,=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 10 ---------- codes.go | 8 ++------ manage.go | 2 -- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/client.go b/client.go index 352749d..50a2d72 100644 --- a/client.go +++ b/client.go @@ -105,16 +105,6 @@ func DialWith(dial ios.DialFunc, op ...client.Option) (cli *Client, err error) { go cli.Client.Run() - /* - 部分接口需要通过代码信息计算得出 - */ - codesOnce.Do(func() { - //初始化代码管理 - if DefaultCodes == nil { - DefaultCodes, err = NewCodes(cli, "./codes.db") - } - }) - return cli, err } diff --git a/codes.go b/codes.go index 929d8cd..10d08fd 100644 --- a/codes.go +++ b/codes.go @@ -8,17 +8,13 @@ import ( "math" "os" "path/filepath" - "sync" "time" "xorm.io/core" "xorm.io/xorm" ) -// 增加单例,部分数据需要通过Codes里面的信息计算 -var ( - DefaultCodes *Codes - codesOnce sync.Once -) +// DefaultCodes 增加单例,部分数据需要通过Codes里面的信息计算 +var DefaultCodes *Codes func NewCodes(c *Client, filename string) (*Codes, error) { diff --git a/manage.go b/manage.go index d863bf9..f716621 100644 --- a/manage.go +++ b/manage.go @@ -27,7 +27,6 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { } //代码 - DefaultCodes = &Codes{} codesClient, err := cfg.Dial(op...) if err != nil { return nil, err @@ -37,7 +36,6 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) { if err != nil { return nil, err } - DefaultCodes = codes //连接池 p, err := NewPool(func() (*Client, error) {