Manage简单兼容DefaultCodes

This commit is contained in:
injoyai
2025-03-18 14:48:02 +08:00
parent 51d8d06fbd
commit b221dbc3e2
2 changed files with 15 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package tdx
import (
"github.com/injoyai/conv"
"github.com/injoyai/logs"
"github.com/injoyai/tdx/protocol"
"github.com/robfig/cron/v3"
@@ -108,14 +109,15 @@ func (this *Codes) GetName(code string) string {
}
// GetStocks 获取股票代码,sh6xxx sz0xx sz30xx
func (this *Codes) GetStocks(limit ...int) []string {
func (this *Codes) GetStocks(limits ...int) []string {
limit := conv.DefaultInt(-1, limits...)
ls := []string(nil)
for _, m := range this.list {
code := m.FullCode()
if protocol.IsStock(code) {
ls = append(ls, code)
}
if len(limit) > 0 && len(ls) >= limit[0] {
if limit > 0 && len(ls) >= limit {
break
}
}

View File

@@ -22,16 +22,9 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
cfg.WorkdayDir = "./data/database"
}
//连接池
p, err := NewPool(func() (*Client, error) {
return DialHosts(cfg.Hosts, op...)
}, cfg.Number)
if err != nil {
return nil, err
}
//代码
codesClient, err := DialHosts(cfg.Hosts, op...)
DefaultCodes = &Codes{}
codesClient, err := DialHostsRandom(cfg.Hosts, op...)
if err != nil {
return nil, err
}
@@ -40,6 +33,15 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
if err != nil {
return nil, err
}
DefaultCodes = codes
//连接池
p, err := NewPool(func() (*Client, error) {
return DialHosts(cfg.Hosts, op...)
}, cfg.Number)
if err != nil {
return nil, err
}
//工作日
workdayClient, err := DialHosts(cfg.Hosts, op...)