mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
优化
This commit is contained in:
5
codes.go
5
codes.go
@@ -1,6 +1,7 @@
|
|||||||
package tdx
|
package tdx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"github.com/injoyai/conv"
|
"github.com/injoyai/conv"
|
||||||
"github.com/injoyai/logs"
|
"github.com/injoyai/logs"
|
||||||
"github.com/injoyai/tdx/protocol"
|
"github.com/injoyai/tdx/protocol"
|
||||||
@@ -195,6 +196,10 @@ func (this *Codes) Update(byDB ...bool) error {
|
|||||||
// GetCodes 更新股票并返回结果
|
// GetCodes 更新股票并返回结果
|
||||||
func (this *Codes) GetCodes(byDatabase bool) ([]*CodeModel, error) {
|
func (this *Codes) GetCodes(byDatabase bool) ([]*CodeModel, error) {
|
||||||
|
|
||||||
|
if this.Client == nil {
|
||||||
|
return nil, errors.New("client is nil")
|
||||||
|
}
|
||||||
|
|
||||||
//2. 查询数据库所有股票
|
//2. 查询数据库所有股票
|
||||||
list := []*CodeModel(nil)
|
list := []*CodeModel(nil)
|
||||||
if err := this.db.Find(&list); err != nil {
|
if err := this.db.Find(&list); err != nil {
|
||||||
|
|||||||
21
manage.go
21
manage.go
@@ -3,7 +3,6 @@ package tdx
|
|||||||
import (
|
import (
|
||||||
"github.com/injoyai/ios/client"
|
"github.com/injoyai/ios/client"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +15,11 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
|||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
cfg = &ManageConfig{}
|
cfg = &ManageConfig{}
|
||||||
}
|
}
|
||||||
if cfg.CodesDir == "" {
|
if cfg.CodesFilename == "" {
|
||||||
cfg.CodesDir = DefaultDatabaseDir
|
cfg.CodesFilename = DefaultDatabaseDir + "/codes.db"
|
||||||
}
|
}
|
||||||
if cfg.WorkdayDir == "" {
|
if cfg.WorkdayFileName == "" {
|
||||||
cfg.WorkdayDir = DefaultDatabaseDir
|
cfg.WorkdayFileName = DefaultDatabaseDir + "/workday.db"
|
||||||
}
|
}
|
||||||
if cfg.Dial == nil {
|
if cfg.Dial == nil {
|
||||||
cfg.Dial = DialDefault
|
cfg.Dial = DialDefault
|
||||||
@@ -32,7 +31,7 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
codesClient.Wait.SetTimeout(time.Second * 5)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -51,7 +50,7 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
workdayClient.Wait.SetTimeout(time.Second * 5)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -83,8 +82,8 @@ func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ManageConfig struct {
|
type ManageConfig struct {
|
||||||
Number int //客户端数量
|
Number int //客户端数量
|
||||||
CodesDir string //代码数据库位置
|
CodesFilename string //代码数据库位置
|
||||||
WorkdayDir string //工作日数据库位置
|
WorkdayFileName string //工作日数据库位置
|
||||||
Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式
|
Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package tdx
|
package tdx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
_ "github.com/glebarez/go-sqlite"
|
_ "github.com/glebarez/go-sqlite"
|
||||||
"github.com/injoyai/base/maps"
|
"github.com/injoyai/base/maps"
|
||||||
"github.com/injoyai/logs"
|
"github.com/injoyai/logs"
|
||||||
@@ -59,6 +60,11 @@ type Workday struct {
|
|||||||
|
|
||||||
// Update 更新
|
// Update 更新
|
||||||
func (this *Workday) Update() error {
|
func (this *Workday) Update() error {
|
||||||
|
|
||||||
|
if this.Client == nil {
|
||||||
|
return errors.New("client is nil")
|
||||||
|
}
|
||||||
|
|
||||||
//获取沪市指数的日K线,用作历史是否节假日的判断依据
|
//获取沪市指数的日K线,用作历史是否节假日的判断依据
|
||||||
//判断日K线是否拉取过
|
//判断日K线是否拉取过
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user