Compare commits

..

9 Commits

Author SHA1 Message Date
injoyai
1afa0c7c6d 升级引用库版本 2025-05-13 11:17:01 +08:00
injoyai
9bad0908b7 升级引用库版本 2025-05-13 11:16:21 +08:00
injoyai
360d0e861b 升级引用库版本 2025-05-13 11:16:04 +08:00
injoyai
b86e7dcacf 优化首次拉取会报错的问题(未创建目录) 2025-04-18 13:33:59 +08:00
injoyai
af505eb55e 优化首次拉取会报错的问题 2025-04-18 13:29:15 +08:00
钱纯净
630cbb8939 Merge remote-tracking branch 'origin/master' 2025-04-17 23:17:28 +08:00
钱纯净
0b89aadd7f 优化 2025-04-17 23:17:09 +08:00
injoyai
7c8b4989f6 增加pull-kline的mysql版本,待测试 2025-04-16 14:22:10 +08:00
injoyai
b00f1b65d5 默认按股票处理,不用配置DefaultCodes,基金才需要 2025-04-16 10:44:06 +08:00
11 changed files with 238 additions and 70 deletions

View File

@@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/injoyai/base/maps"
"github.com/injoyai/base/maps/wait/v2"
"github.com/injoyai/base/maps/wait"
"github.com/injoyai/conv"
"github.com/injoyai/ios"
"github.com/injoyai/ios/client"
@@ -235,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
@@ -256,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),
}
}
}
}

View File

@@ -28,7 +28,10 @@ func DialCodes(filename string, op ...client.Option) (*Codes, error) {
func NewCodes(c *Client, filenames ...string) (*Codes, error) {
filename := conv.DefaultString("./codes.db", filenames...)
//如果没有指定文件名,则使用默认
defaultFilename := filepath.Join(DefaultDatabaseDir, "codes.db")
filename := conv.Default[string](defaultFilename, filenames...)
filename = conv.Select[string](filename == "", defaultFilename, filename)
//如果文件夹不存在就创建
dir, _ := filepath.Split(filename)
@@ -118,7 +121,7 @@ func (this *Codes) GetName(code string) string {
// GetStocks 获取股票代码,sh6xxx sz0xx sz30xx
func (this *Codes) GetStocks(limits ...int) []string {
limit := conv.DefaultInt(-1, limits...)
limit := conv.Default[int](-1, limits...)
ls := []string(nil)
for _, m := range this.list {
code := m.FullCode()
@@ -314,7 +317,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 {

148
extend/pull-kline-mysql.go Normal file
View 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
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/injoyai/logs"
"github.com/injoyai/tdx"
"github.com/injoyai/tdx/protocol"
"os"
"path/filepath"
"sort"
"time"
@@ -41,6 +42,18 @@ var (
Quarter: NewKlineTable("QuarterKline", func(c *tdx.Client) KlineHandler { return c.GetKlineQuarterUntil }),
Year: NewKlineTable("YearKline", func(c *tdx.Client) KlineHandler { return c.GetKlineYearUntil }),
}
AllKlineTables = []string{
"MinuteKline",
"Minute5Kline",
"Minute15Kline",
"Minute30Kline",
"HourKline",
"DayKline",
"WeekKline",
"MonthKline",
"QuarterKline",
"YearKline",
}
)
type PullKlineConfig struct {
@@ -91,6 +104,8 @@ func (this *PullKline) Run(ctx context.Context, m *tdx.Manage) error {
go func(code string) {
defer limit.Done()
_ = os.MkdirAll(this.Config.Dir, 0777)
//连接数据库
db, err := xorm.NewEngine("sqlite", filepath.Join(this.Config.Dir, code+".db"))
if err != nil {
@@ -111,7 +126,7 @@ func (this *PullKline) Run(ctx context.Context, m *tdx.Manage) error {
default:
}
db.Sync2(table)
logs.PrintErr(db.Sync2(table))
//2. 获取最后一条数据
last := new(Kline)
@@ -186,7 +201,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"` //最高价

10
go.mod
View File

@@ -4,9 +4,10 @@ go 1.20
require (
github.com/glebarez/go-sqlite v1.22.0
github.com/injoyai/base v1.0.18
github.com/injoyai/conv v1.1.10
github.com/injoyai/ios v0.0.4
github.com/go-sql-driver/mysql v1.7.0
github.com/injoyai/base v1.2.7
github.com/injoyai/conv v1.2.2
github.com/injoyai/ios v0.0.7
github.com/injoyai/logs v1.0.9
github.com/robfig/cron/v3 v3.0.1
golang.org/x/text v0.16.0
@@ -21,14 +22,13 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
golang.org/x/sys v0.22.0 // indirect

34
go.sum
View File

@@ -14,36 +14,32 @@ github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec
github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.8.1 h1:4/Wjm0JIJaTDm8K1KcGrLHJoa8EsJ13YWeX+6Kfq6uI=
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/injoyai/base v1.0.18 h1:AMB1NhPe9acvMp04sThE8Ji/SRS1/MHsx19NmSoD8LA=
github.com/injoyai/base v1.0.18/go.mod h1:2JSv8ndJ/FmKyazfhDBewzylEbVfJV0EE/r6kOvnzwU=
github.com/injoyai/conv v1.1.5/go.mod h1:PYoJcbqaz4eyQUovzErRFCuDSPGB4L07AvdmFsTrTew=
github.com/injoyai/conv v1.1.10 h1:LefmOA4SKTEw6gGHXZ6UT8n2K+OzCttYSW8lVmvgQd8=
github.com/injoyai/conv v1.1.10/go.mod h1:PYoJcbqaz4eyQUovzErRFCuDSPGB4L07AvdmFsTrTew=
github.com/injoyai/ios v0.0.4 h1:yEZ6wN5uCSjAJB4qwpT6R77aMtjkblZo4giKwu9/s7Y=
github.com/injoyai/ios v0.0.4/go.mod h1:heABkaIUwoRRe424otl6mKgdU6LYt5gadav/V4gaojA=
github.com/injoyai/base v1.2.7 h1:uYZoUIPGidkTNMfQfObsyHulu5VvNCOzuCh1DGn+Hz0=
github.com/injoyai/base v1.2.7/go.mod h1:BsXiJ6/hXpswWxI4zLdKz+pW2Cwo+qhdfyaWDfR/vwg=
github.com/injoyai/conv v1.2.2 h1:nxFD3zCYq/ZvVE6xAExBR+agi6gB+vc9O0si67VAsPk=
github.com/injoyai/conv v1.2.2/go.mod h1:s05l3fQJQ4mT4VX+KIdbvCWQB0YzZHprmUfUu2uxd1k=
github.com/injoyai/ios v0.0.7 h1:7k/brTmpnoqE6ajodyilkr2EJmJmcvSkpUD+LptgUVU=
github.com/injoyai/ios v0.0.7/go.mod h1:9HemWSJTmhyJCnr+kH+lRfmvrEdABi1rkCBVsbqV5X8=
github.com/injoyai/logs v1.0.9 h1:Wq7rCVIQKcPx+z+lzKQb2qyDK4TML/cgmaSZN9tx33c=
github.com/injoyai/logs v1.0.9/go.mod h1:CLchJCGhb39Obyrci816R+KMtbxZhgPs0FuikhyixK4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -68,14 +64,15 @@ github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -88,7 +85,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -104,18 +100,12 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=

View File

@@ -1,11 +1,11 @@
package protocol
import (
"bytes"
"compress/zlib"
"errors"
"fmt"
"github.com/injoyai/base/bytes"
"github.com/injoyai/base/g"
"github.com/injoyai/base/types"
"github.com/injoyai/conv"
"io"
)
@@ -19,7 +19,7 @@ const (
)
type Message interface {
Bytes() g.Bytes
Bytes() types.Bytes
}
/*
@@ -39,7 +39,7 @@ type Frame struct {
Data []byte //数据
}
func (this *Frame) Bytes() g.Bytes {
func (this *Frame) Bytes() types.Bytes {
length := uint16(len(this.Data) + 2)
data := make([]byte, 12+len(this.Data))
data[0] = Prefix

View File

@@ -3,7 +3,7 @@ package protocol
import (
"errors"
"fmt"
"github.com/injoyai/base/g"
"github.com/injoyai/base/types"
"github.com/injoyai/conv"
"time"
)
@@ -15,7 +15,7 @@ type KlineReq struct {
Count uint16
}
func (this *KlineReq) Bytes(Type uint8) (g.Bytes, error) {
func (this *KlineReq) Bytes(Type uint8) (types.Bytes, error) {
if this.Count > 800 {
return nil, errors.New("单次数量不能超过800")
}

View File

@@ -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)

View File

@@ -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
}

View File

@@ -3,7 +3,6 @@ package protocol
import (
"bytes"
"fmt"
bytes2 "github.com/injoyai/base/bytes"
"github.com/injoyai/conv"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
@@ -15,12 +14,12 @@ import (
// String 字节先转小端,再转字符
func String(bs []byte) string {
return string(bytes2.Reverse(bs))
return string(Reverse(bs))
}
// Bytes 任意类型转小端字节
func Bytes(n any) []byte {
return bytes2.Reverse(conv.Bytes(n))
return Reverse(conv.Bytes(n))
}
// Reverse 字节倒序
@@ -34,12 +33,12 @@ func Reverse(bs []byte) []byte {
// Uint32 字节通过小端方式转为uint32
func Uint32(bs []byte) uint32 {
return conv.Uint32(bytes2.Reverse(bs))
return conv.Uint32(Reverse(bs))
}
// Uint16 字节通过小端方式转为uint16
func Uint16(bs []byte) uint16 {
return conv.Uint16(bytes2.Reverse(bs))
return conv.Uint16(Reverse(bs))
}
func UTF8ToGBK(text []byte) []byte {