mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81c45e76d0 | ||
|
|
a8c248bf9d | ||
|
|
3e57f54978 | ||
|
|
50c997f26f | ||
|
|
0740ff7ca0 | ||
|
|
81f2ffcbea |
2
codes.go
2
codes.go
@@ -145,7 +145,7 @@ func (this *Codes) Code(byDatabase bool) ([]*CodeModel, error) {
|
||||
}
|
||||
}
|
||||
for _, v := range update {
|
||||
if _, err := session.Where("Code=?", v.Code).Cols("Name").Update(v); err != nil {
|
||||
if _, err := session.Where("Exchange=? and Code=? ", v.Exchange, v.Code).Cols("Name").Update(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
20
manage.go
20
manage.go
@@ -15,8 +15,11 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
||||
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"
|
||||
}
|
||||
|
||||
//连接池
|
||||
@@ -33,18 +36,18 @@ 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
|
||||
}
|
||||
@@ -76,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 //工作日数据库位置
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package protocol
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
TypeConnect = 0x000D //建立连接
|
||||
TypeHeart = 0x0004 //心跳
|
||||
@@ -12,6 +14,11 @@ const (
|
||||
TypeKline = 0x052D //K线图
|
||||
)
|
||||
|
||||
var (
|
||||
// ExchangeEstablish 交易所成立时间
|
||||
ExchangeEstablish = time.Date(1990, 12, 19, 0, 0, 0, 0, time.Local)
|
||||
)
|
||||
|
||||
/*
|
||||
从其他地方复制
|
||||
const (
|
||||
|
||||
@@ -113,10 +113,7 @@ func (this *Workday) TodayIs() bool {
|
||||
// RangeDesc 倒序遍历工作日,从今天-1990年12月19日(上海交易所成立时间)
|
||||
func (this *Workday) RangeDesc(f func(t time.Time) bool) {
|
||||
t := IntegerDay(time.Now())
|
||||
for ; t.Before(time.Date(1990, 12, 1, 0, 0, 0, 0, time.Local)); t = t.Add(-time.Hour * 24) {
|
||||
if t.Weekday() == time.Saturday || t.Weekday() == time.Sunday {
|
||||
continue
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user