mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c8b4989f6 | ||
|
|
b00f1b65d5 | ||
|
|
78e2ead79c | ||
|
|
f69dd66ecb | ||
|
|
4ce4adbfea | ||
|
|
20de683bca | ||
|
|
49c6deb9c4 | ||
|
|
5c0bc2a772 | ||
|
|
0f75b402bc | ||
|
|
ce6718831c | ||
|
|
031d9f6509 | ||
|
|
5e4115d045 | ||
|
|
1cae60c65e |
61
client.go
61
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
|
||||
}
|
||||
|
||||
@@ -245,12 +235,18 @@ func (this *Client) GetCodeAll(exchange protocol.Exchange) (*protocol.CodeResp,
|
||||
|
||||
// GetQuote 获取盘口五档报价
|
||||
func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
||||
if DefaultCodes == nil {
|
||||
return nil, errors.New("DefaultCodes未初始化")
|
||||
}
|
||||
for i := range codes {
|
||||
codes[i] = DefaultCodes.AddExchange(codes[i])
|
||||
//如果是股票代码,则加上前缀
|
||||
codes[i] = protocol.AddPrefix(codes[i])
|
||||
if !protocol.IsStock(codes[i]) {
|
||||
if DefaultCodes == nil {
|
||||
return nil, errors.New("DefaultCodes未初始化")
|
||||
}
|
||||
//不是股票代码的话,根据codes的信息加上前缀
|
||||
codes[i] = DefaultCodes.AddExchange(codes[i])
|
||||
}
|
||||
}
|
||||
|
||||
f, err := protocol.MQuote.Frame(codes...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -266,26 +262,25 @@ func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
||||
if len(quotes) != len(codes) {
|
||||
return nil, fmt.Errorf("预期%d个,实际%d个", len(codes), len(quotes))
|
||||
}
|
||||
if DefaultCodes == nil {
|
||||
return nil, errors.New("DefaultCodes未初始化")
|
||||
}
|
||||
for i, code := range codes {
|
||||
m := DefaultCodes.Get(code)
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
|
||||
}
|
||||
for ii, v := range quotes[i].SellLevel {
|
||||
quotes[i].SellLevel[ii].Price = m.Price(v.Price)
|
||||
}
|
||||
for ii, v := range quotes[i].BuyLevel {
|
||||
quotes[i].BuyLevel[ii].Price = m.Price(v.Price)
|
||||
}
|
||||
quotes[i].K = protocol.K{
|
||||
Last: m.Price(quotes[i].K.Last),
|
||||
Open: m.Price(quotes[i].K.Open),
|
||||
High: m.Price(quotes[i].K.High),
|
||||
Low: m.Price(quotes[i].K.Low),
|
||||
Close: m.Price(quotes[i].K.Close),
|
||||
if !protocol.IsStock(code) {
|
||||
m := DefaultCodes.Get(code)
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
|
||||
}
|
||||
for ii, v := range quotes[i].SellLevel {
|
||||
quotes[i].SellLevel[ii].Price = m.Price(v.Price)
|
||||
}
|
||||
for ii, v := range quotes[i].BuyLevel {
|
||||
quotes[i].BuyLevel[ii].Price = m.Price(v.Price)
|
||||
}
|
||||
quotes[i].K = protocol.K{
|
||||
Last: m.Price(quotes[i].K.Last),
|
||||
Open: m.Price(quotes[i].K.Open),
|
||||
High: m.Price(quotes[i].K.High),
|
||||
Low: m.Price(quotes[i].K.Low),
|
||||
Close: m.Price(quotes[i].K.Close),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
codes.go
29
codes.go
@@ -1,26 +1,34 @@
|
||||
package tdx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/injoyai/conv"
|
||||
"github.com/injoyai/ios/client"
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
"github.com/robfig/cron/v3"
|
||||
"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) {
|
||||
func DialCodes(filename string, op ...client.Option) (*Codes, error) {
|
||||
c, err := DialDefault(op...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewCodes(c, filename)
|
||||
}
|
||||
|
||||
func NewCodes(c *Client, filenames ...string) (*Codes, error) {
|
||||
|
||||
filename := conv.DefaultString("./codes.db", filenames...)
|
||||
|
||||
//如果文件夹不存在就创建
|
||||
dir, _ := filepath.Split(filename)
|
||||
@@ -199,6 +207,10 @@ func (this *Codes) Update(byDB ...bool) error {
|
||||
// GetCodes 更新股票并返回结果
|
||||
func (this *Codes) GetCodes(byDatabase bool) ([]*CodeModel, error) {
|
||||
|
||||
if this.Client == nil {
|
||||
return nil, errors.New("client is nil")
|
||||
}
|
||||
|
||||
//2. 查询数据库所有股票
|
||||
list := []*CodeModel(nil)
|
||||
if err := this.db.Find(&list); err != nil {
|
||||
@@ -302,7 +314,8 @@ func (this *CodeModel) FullCode() string {
|
||||
}
|
||||
|
||||
func (this *CodeModel) Price(p protocol.Price) protocol.Price {
|
||||
return p * protocol.Price(math.Pow10(int(3-this.Decimal)))
|
||||
return protocol.Price(float64(p) * math.Pow10(int(2-this.Decimal)))
|
||||
return p * protocol.Price(math.Pow10(int(2-this.Decimal)))
|
||||
}
|
||||
|
||||
func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error {
|
||||
|
||||
4
dial.go
4
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
|
||||
|
||||
46
example/CheckGetHistoryErr/main.go
Normal file
46
example/CheckGetHistoryErr/main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m, err := tdx.NewManage(nil)
|
||||
logs.PanicErr(err)
|
||||
|
||||
codes := m.Codes.GetStocks()
|
||||
//codes = []string{
|
||||
// "sz000001",
|
||||
// "sz000002",
|
||||
//}
|
||||
|
||||
for _, code := range codes {
|
||||
m.Do(func(c *tdx.Client) error {
|
||||
resp, err := c.GetHistoryMinute(time.Now().Format("20060102"), code)
|
||||
logs.PanicErr(err)
|
||||
|
||||
resp2, err := c.GetKlineDay(code, 0, 1)
|
||||
logs.PanicErr(err)
|
||||
|
||||
if len(resp2.List) == 0 {
|
||||
logs.Debug(code)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(resp.List) == 0 {
|
||||
logs.Debug(code)
|
||||
return nil
|
||||
}
|
||||
|
||||
if resp2.List[0].Close != resp.List[len(resp.List)-1].Price {
|
||||
logs.Debug(code)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func main() {
|
||||
common.Test(func(c *tdx.Client) {
|
||||
resp, err := c.GetKlineDay("sh000001", 0, 10)
|
||||
resp, err := c.GetIndexDay("sh000001", 0, 10)
|
||||
logs.PanicErr(err)
|
||||
|
||||
for _, v := range resp.List {
|
||||
|
||||
@@ -10,6 +10,9 @@ func main() {
|
||||
c, err := tdx.Dial("124.71.187.122:7709", tdx.WithDebug())
|
||||
logs.PanicErr(err)
|
||||
|
||||
tdx.DefaultCodes, err = tdx.NewCodes(c, "./codes.db")
|
||||
logs.PanicErr(err)
|
||||
|
||||
_ = c
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/injoyai/tdx"
|
||||
"github.com/injoyai/tdx/extend"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -13,12 +14,13 @@ func main() {
|
||||
m, err := tdx.NewManage(nil)
|
||||
logs.PanicErr(err)
|
||||
|
||||
err = extend.NewPullKline(
|
||||
[]string{"sz000001"},
|
||||
[]string{extend.Year},
|
||||
filepath.Join(tdx.DefaultDatabaseDir, "kline"),
|
||||
1,
|
||||
).Run(context.Background(), m)
|
||||
err = extend.NewPullKline(extend.PullKlineConfig{
|
||||
Codes: []string{"sz000001"},
|
||||
Tables: []string{extend.Year},
|
||||
Dir: filepath.Join(tdx.DefaultDatabaseDir, "kline"),
|
||||
Limit: 1,
|
||||
StartAt: time.Time{},
|
||||
}).Run(context.Background(), m)
|
||||
logs.PanicErr(err)
|
||||
|
||||
}
|
||||
|
||||
148
extend/pull-kline-mysql.go
Normal file
148
extend/pull-kline-mysql.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package extend
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/injoyai/base/chans"
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx"
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func NewPullKlineMysql(cfg PullKlineConfig) (*PullKlineMysql, error) {
|
||||
db, err := xorm.NewEngine("mysql", cfg.Dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.SetMapper(core.SameMapper{})
|
||||
_tables := []*KlineTable(nil)
|
||||
for _, v := range cfg.Tables {
|
||||
table := KlineTableMap[v]
|
||||
if err = db.Sync2(table); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_tables = append(_tables, table)
|
||||
}
|
||||
return &PullKlineMysql{
|
||||
tables: _tables,
|
||||
Config: cfg,
|
||||
DB: db,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type PullKlineMysql struct {
|
||||
tables []*KlineTable
|
||||
Config PullKlineConfig
|
||||
DB *xorm.Engine
|
||||
}
|
||||
|
||||
func (this *PullKlineMysql) Name() string {
|
||||
return "拉取k线数据"
|
||||
}
|
||||
|
||||
func (this *PullKlineMysql) Run(ctx context.Context, m *tdx.Manage) error {
|
||||
limit := chans.NewWaitLimit(uint(this.Config.Limit))
|
||||
|
||||
//1. 获取所有股票代码
|
||||
codes := this.Config.Codes
|
||||
if len(codes) == 0 {
|
||||
codes = m.Codes.GetStocks()
|
||||
}
|
||||
|
||||
for _, v := range codes {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
limit.Add()
|
||||
go func(code string) {
|
||||
defer limit.Done()
|
||||
|
||||
for _, table := range this.tables {
|
||||
if table == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
//2. 获取最后一条数据
|
||||
last := new(Kline)
|
||||
if _, err = this.DB.Table(table).Where("Code=?", code).Desc("Date").Get(last); err != nil {
|
||||
logs.Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
//3. 从服务器获取数据
|
||||
insert := Klines{}
|
||||
err = m.Do(func(c *tdx.Client) error {
|
||||
insert, err = this.pull(code, last.Date, table.Handler(c))
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
logs.Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
//4. 插入数据库
|
||||
err = tdx.NewSessionFunc(this.DB, func(session *xorm.Session) error {
|
||||
for i, v := range insert {
|
||||
if i == 0 {
|
||||
if _, err := session.Table(table).Where("Code=? and Date >= ?", code, v.Date).Delete(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := session.Table(table).Insert(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
logs.PrintErr(err)
|
||||
|
||||
}
|
||||
|
||||
}(v)
|
||||
}
|
||||
limit.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *PullKlineMysql) pull(code string, lastDate int64, f func(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)) (Klines, error) {
|
||||
|
||||
if lastDate == 0 {
|
||||
lastDate = protocol.ExchangeEstablish.Unix()
|
||||
}
|
||||
|
||||
resp, err := f(code, func(k *protocol.Kline) bool {
|
||||
return k.Time.Unix() <= lastDate || k.Time.Unix() <= this.Config.StartAt.Unix()
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ks := Klines{}
|
||||
for _, v := range resp.List {
|
||||
ks = append(ks, &Kline{
|
||||
Code: code,
|
||||
Date: v.Time.Unix(),
|
||||
Open: v.Open,
|
||||
High: v.High,
|
||||
Low: v.Low,
|
||||
Close: v.Close,
|
||||
Volume: v.Volume,
|
||||
Amount: v.Amount,
|
||||
})
|
||||
}
|
||||
|
||||
return ks, nil
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@@ -42,24 +43,28 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func NewPullKline(codes, tables []string, dir string, limit int) *PullKline {
|
||||
type PullKlineConfig struct {
|
||||
Codes []string //操作代码
|
||||
Tables []string //数据类型
|
||||
Dir string //数据位置
|
||||
Limit int //协程数量
|
||||
StartAt time.Time //数据开始时间
|
||||
}
|
||||
|
||||
func NewPullKline(cfg PullKlineConfig) *PullKline {
|
||||
_tables := []*KlineTable(nil)
|
||||
for _, v := range tables {
|
||||
for _, v := range cfg.Tables {
|
||||
_tables = append(_tables, KlineTableMap[v])
|
||||
}
|
||||
return &PullKline{
|
||||
tables: _tables,
|
||||
dir: dir,
|
||||
Codes: codes,
|
||||
limit: limit,
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
type PullKline struct {
|
||||
tables []*KlineTable
|
||||
dir string //数据目录
|
||||
Codes []string //指定的代码
|
||||
limit int //并发数量
|
||||
Config PullKlineConfig
|
||||
}
|
||||
|
||||
func (this *PullKline) Name() string {
|
||||
@@ -67,10 +72,10 @@ func (this *PullKline) Name() string {
|
||||
}
|
||||
|
||||
func (this *PullKline) Run(ctx context.Context, m *tdx.Manage) error {
|
||||
limit := chans.NewWaitLimit(uint(this.limit))
|
||||
limit := chans.NewWaitLimit(uint(this.Config.Limit))
|
||||
|
||||
//1. 获取所有股票代码
|
||||
codes := this.Codes
|
||||
codes := this.Config.Codes
|
||||
if len(codes) == 0 {
|
||||
codes = m.Codes.GetStocks()
|
||||
}
|
||||
@@ -87,7 +92,7 @@ func (this *PullKline) Run(ctx context.Context, m *tdx.Manage) error {
|
||||
defer limit.Done()
|
||||
|
||||
//连接数据库
|
||||
db, err := xorm.NewEngine("sqlite", filepath.Join(this.dir, code+".db"))
|
||||
db, err := xorm.NewEngine("sqlite", filepath.Join(this.Config.Dir, code+".db"))
|
||||
if err != nil {
|
||||
logs.Err(err)
|
||||
return
|
||||
@@ -157,7 +162,7 @@ func (this *PullKline) pull(code string, lastDate int64, f func(code string, f f
|
||||
}
|
||||
|
||||
resp, err := f(code, func(k *protocol.Kline) bool {
|
||||
return k.Time.Unix() <= lastDate
|
||||
return k.Time.Unix() <= lastDate || k.Time.Unix() <= this.Config.StartAt.Unix()
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -181,7 +186,7 @@ func (this *PullKline) pull(code string, lastDate int64, f func(code string, f f
|
||||
}
|
||||
|
||||
type Kline struct {
|
||||
Code string `json:"code" xorm:"-"` //代码
|
||||
Code string `json:"code"` //代码
|
||||
Date int64 `json:"date"` //时间节点 2006-01-02 15:00
|
||||
Open protocol.Price `json:"open"` //开盘价
|
||||
High protocol.Price `json:"high"` //最高价
|
||||
|
||||
23
manage.go
23
manage.go
@@ -3,7 +3,6 @@ package tdx
|
||||
import (
|
||||
"github.com/injoyai/ios/client"
|
||||
"github.com/robfig/cron/v3"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -16,28 +15,26 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
||||
if cfg == nil {
|
||||
cfg = &ManageConfig{}
|
||||
}
|
||||
if cfg.CodesDir == "" {
|
||||
cfg.CodesDir = DefaultDatabaseDir
|
||||
if cfg.CodesFilename == "" {
|
||||
cfg.CodesFilename = DefaultDatabaseDir + "/codes.db"
|
||||
}
|
||||
if cfg.WorkdayDir == "" {
|
||||
cfg.WorkdayDir = DefaultDatabaseDir
|
||||
if cfg.WorkdayFileName == "" {
|
||||
cfg.WorkdayFileName = DefaultDatabaseDir + "/workday.db"
|
||||
}
|
||||
if cfg.Dial == nil {
|
||||
cfg.Dial = DialDefault
|
||||
}
|
||||
|
||||
//代码
|
||||
DefaultCodes = &Codes{}
|
||||
codesClient, err := cfg.Dial(op...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
DefaultCodes = codes
|
||||
|
||||
//连接池
|
||||
p, err := NewPool(func() (*Client, error) {
|
||||
@@ -53,7 +50,7 @@ func NewManage(cfg *ManageConfig, op ...client.Option) (*Manage, error) {
|
||||
return nil, err
|
||||
}
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
@@ -85,8 +82,8 @@ func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) {
|
||||
}
|
||||
|
||||
type ManageConfig struct {
|
||||
Number int //客户端数量
|
||||
CodesDir string //代码数据库位置
|
||||
WorkdayDir string //工作日数据库位置
|
||||
Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式
|
||||
Number int //客户端数量
|
||||
CodesFilename string //代码数据库位置
|
||||
WorkdayFileName string //工作日数据库位置
|
||||
Dial func(op ...client.Option) (cli *Client, err error) //默认连接方式
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ func (this historyMinute) Decode(bs []byte) (*MinuteResp, error) {
|
||||
Count: Uint16(bs[:2]),
|
||||
}
|
||||
|
||||
multiple := Price(1)
|
||||
if bs[5] > 0x40 {
|
||||
multiple = 10
|
||||
}
|
||||
multiple := Price(1) * 10
|
||||
//if bs[5] > 0x40 {
|
||||
//multiple = 10
|
||||
//}
|
||||
|
||||
//2-4字节是啥?
|
||||
bs = bs[6:]
|
||||
|
||||
@@ -47,7 +47,7 @@ type Quote struct {
|
||||
func (this *Quote) String() string {
|
||||
return fmt.Sprintf(`%s%s
|
||||
%s
|
||||
总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
|
||||
总手:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
|
||||
%s%s
|
||||
`,
|
||||
this.Exchange.String(), this.Code, this.K,
|
||||
@@ -142,9 +142,9 @@ func (this quote) Decode(bs []byte) QuotesResp {
|
||||
sellLevel := PriceLevel{}
|
||||
|
||||
bs, p = GetPrice(bs)
|
||||
buyLevel.Price = p + sec.K.Close
|
||||
buyLevel.Price = p*10 + sec.K.Close
|
||||
bs, p = GetPrice(bs)
|
||||
sellLevel.Price = p + sec.K.Close
|
||||
sellLevel.Price = p*10 + sec.K.Close
|
||||
|
||||
bs, buyLevel.Number = CutInt(bs)
|
||||
bs, sellLevel.Number = CutInt(bs)
|
||||
|
||||
@@ -78,6 +78,13 @@ func DecodeK(bs []byte) ([]byte, K) {
|
||||
bs, k.Low = GetPrice(bs)
|
||||
k.Low += k.Close
|
||||
|
||||
//默认按股票展示
|
||||
k.Last *= 10
|
||||
k.Open *= 10
|
||||
k.Close *= 10
|
||||
k.High *= 10
|
||||
k.Low *= 10
|
||||
|
||||
return bs, k
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tdx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "github.com/glebarez/go-sqlite"
|
||||
"github.com/injoyai/base/maps"
|
||||
"github.com/injoyai/logs"
|
||||
@@ -59,6 +60,11 @@ type Workday struct {
|
||||
|
||||
// Update 更新
|
||||
func (this *Workday) Update() error {
|
||||
|
||||
if this.Client == nil {
|
||||
return errors.New("client is nil")
|
||||
}
|
||||
|
||||
//获取沪市指数的日K线,用作历史是否节假日的判断依据
|
||||
//判断日K线是否拉取过
|
||||
|
||||
|
||||
Reference in New Issue
Block a user