mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50c997f26f | ||
|
|
0740ff7ca0 | ||
|
|
81f2ffcbea | ||
|
|
8a63c2ff2e | ||
|
|
71035fb210 | ||
|
|
f479d99c99 | ||
|
|
ddb36b5aa7 | ||
|
|
ddc4b801bf | ||
|
|
e22d2776e7 | ||
|
|
f46b97e1e1 |
@@ -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...)
|
||||
|
||||
25
manage.go
25
manage.go
@@ -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 //工作日数据库位置
|
||||
}
|
||||
|
||||
16
workday.go
16
workday.go
@@ -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"` //主键
|
||||
|
||||
Reference in New Issue
Block a user