mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
8 Commits
v0.0.49
...
233d1b689e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
233d1b689e | ||
|
|
2a27eea873 | ||
|
|
fcfb329712 | ||
|
|
ed2c814fab | ||
|
|
fc04b5042a | ||
|
|
b2a4c00253 | ||
|
|
c68c7582bc | ||
|
|
4e62ee1c5e |
@@ -1,9 +1,8 @@
|
||||
### 说明
|
||||
|
||||
* 参考golang库 [`https://github.com/bensema/gotdx`](https://github.com/bensema/gotdx)
|
||||
* 参考python库 [`https://github.com/mootdx/mootdx`](https://github.com/mootdx/mootdx)
|
||||
|
||||
* 数据入库示例(开发中) [`https://github.com/injoyai/stock`](https://github.com/injoyai/stock)
|
||||
* 参考 [`https://github.com/bensema/gotdx`](https://github.com/bensema/gotdx)
|
||||
* 参考 [`https://github.com/mootdx/mootdx`](https://github.com/mootdx/mootdx)
|
||||
* 参考 [`https://github.com/jing2uo/tdx2db`](https://github.com/jing2uo/tdx2db)
|
||||
|
||||
### 如何使用
|
||||
|
||||
|
||||
27
client.go
27
client.go
@@ -3,6 +3,10 @@ package tdx
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/injoyai/base/maps"
|
||||
"github.com/injoyai/base/maps/wait"
|
||||
"github.com/injoyai/conv"
|
||||
@@ -12,9 +16,6 @@ import (
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx/internal/bse"
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
"runtime/debug"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -560,6 +561,26 @@ func (this *Client) GetIndexAll(Type uint8, code string) (*protocol.KlineResp, e
|
||||
return this.GetIndexUntil(Type, code, func(k *protocol.Kline) bool { return false })
|
||||
}
|
||||
|
||||
func (this *Client) GetIndexMinute(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKlineMinute, code, start, count)
|
||||
}
|
||||
|
||||
func (this *Client) GetIndex5Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKline5Minute, code, start, count)
|
||||
}
|
||||
|
||||
func (this *Client) GetIndex15Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKline15Minute, code, start, count)
|
||||
}
|
||||
|
||||
func (this *Client) GetIndex30Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKline30Minute, code, start, count)
|
||||
}
|
||||
|
||||
func (this *Client) GetIndex60Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKline60Minute, code, start, count)
|
||||
}
|
||||
|
||||
func (this *Client) GetIndexDay(code string, start, count uint16) (*protocol.KlineResp, error) {
|
||||
return this.GetIndex(protocol.TypeKlineDay, code, start, count)
|
||||
}
|
||||
|
||||
86
codes.go
86
codes.go
@@ -2,24 +2,31 @@ package tdx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"iter"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
"time"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type ICodes interface {
|
||||
Iter() iter.Seq2[string, *CodeModel]
|
||||
Get(code string) *CodeModel
|
||||
GetName(code string) string
|
||||
GetStocks(limit ...int) []string
|
||||
GetETFs(limit ...int) []string
|
||||
GetStocks(limit ...int) CodeModels
|
||||
GetStockCodes(limit ...int) []string
|
||||
GetETFs(limit ...int) CodeModels
|
||||
GetETFCodes(limit ...int) []string
|
||||
GetIndexes(limits ...int) CodeModels
|
||||
GetIndexCodes(limits ...int) []string
|
||||
}
|
||||
|
||||
// DefaultCodes 增加单例,部分数据需要通过Codes里面的信息计算
|
||||
@@ -130,6 +137,8 @@ func NewCodes(c *Client, db *xorm.Engine) (*Codes, error) {
|
||||
return cc, cc.Update(true)
|
||||
}
|
||||
|
||||
var _ ICodes = &Codes{}
|
||||
|
||||
type Codes struct {
|
||||
*Client //客户端
|
||||
db *xorm.Engine //数据库实例
|
||||
@@ -138,6 +147,20 @@ type Codes struct {
|
||||
exchanges map[string][]string //交易所缓存
|
||||
}
|
||||
|
||||
func (this *Codes) Get(code string) *CodeModel {
|
||||
return this.Map[code]
|
||||
}
|
||||
|
||||
func (this *Codes) Iter() iter.Seq2[string, *CodeModel] {
|
||||
return func(yield func(string, *CodeModel) bool) {
|
||||
for _, code := range this.list {
|
||||
if !yield(code.FullCode(), code) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetName 获取股票名称
|
||||
func (this *Codes) GetName(code string) string {
|
||||
if v, ok := this.Map[code]; ok {
|
||||
@@ -147,13 +170,13 @@ func (this *Codes) GetName(code string) string {
|
||||
}
|
||||
|
||||
// GetStocks 获取股票代码,sh6xxx sz0xx sz30xx
|
||||
func (this *Codes) GetStocks(limits ...int) []string {
|
||||
func (this *Codes) GetStocks(limits ...int) CodeModels {
|
||||
limit := conv.Default(-1, limits...)
|
||||
ls := []string(nil)
|
||||
ls := []*CodeModel(nil)
|
||||
for _, m := range this.list {
|
||||
code := m.FullCode()
|
||||
if protocol.IsStock(code) {
|
||||
ls = append(ls, code)
|
||||
ls = append(ls, m)
|
||||
}
|
||||
if limit > 0 && len(ls) >= limit {
|
||||
break
|
||||
@@ -162,14 +185,18 @@ func (this *Codes) GetStocks(limits ...int) []string {
|
||||
return ls
|
||||
}
|
||||
|
||||
func (this *Codes) GetStockCodes(limits ...int) []string {
|
||||
return this.GetStocks(limits...).Codes()
|
||||
}
|
||||
|
||||
// GetETFs 获取基金代码,sz159xxx,sh510xxx,sh511xxx
|
||||
func (this *Codes) GetETFs(limits ...int) []string {
|
||||
func (this *Codes) GetETFs(limits ...int) CodeModels {
|
||||
limit := conv.Default(-1, limits...)
|
||||
ls := []string(nil)
|
||||
ls := []*CodeModel(nil)
|
||||
for _, m := range this.list {
|
||||
code := m.FullCode()
|
||||
if protocol.IsETF(code) {
|
||||
ls = append(ls, code)
|
||||
ls = append(ls, m)
|
||||
}
|
||||
if limit > 0 && len(ls) >= limit {
|
||||
break
|
||||
@@ -178,8 +205,29 @@ func (this *Codes) GetETFs(limits ...int) []string {
|
||||
return ls
|
||||
}
|
||||
|
||||
func (this *Codes) Get(code string) *CodeModel {
|
||||
return this.Map[code]
|
||||
// GetETFCodes 获取基金代码,sz159xxx,sh510xxx,sh511xxx
|
||||
func (this *Codes) GetETFCodes(limits ...int) []string {
|
||||
return this.GetETFs(limits...).Codes()
|
||||
}
|
||||
|
||||
// GetIndexes 获取基金代码,sz159xxx,sh510xxx,sh511xxx
|
||||
func (this *Codes) GetIndexes(limits ...int) CodeModels {
|
||||
limit := conv.Default(-1, limits...)
|
||||
ls := []*CodeModel(nil)
|
||||
for _, m := range this.list {
|
||||
code := m.FullCode()
|
||||
if protocol.IsIndex(code) {
|
||||
ls = append(ls, m)
|
||||
}
|
||||
if limit > 0 && len(ls) >= limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
return ls
|
||||
}
|
||||
|
||||
func (this *Codes) GetIndexCodes(limits ...int) []string {
|
||||
return this.GetIndexes(limits...).Codes()
|
||||
}
|
||||
|
||||
func (this *Codes) AddExchange(code string) string {
|
||||
@@ -367,3 +415,13 @@ func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CodeModels []*CodeModel
|
||||
|
||||
func (this CodeModels) Codes() []string {
|
||||
codes := make([]string, len(this))
|
||||
for i, v := range this {
|
||||
codes[i] = v.FullCode()
|
||||
}
|
||||
return codes
|
||||
}
|
||||
|
||||
68
codes_v2.go
68
codes_v2.go
@@ -2,6 +2,11 @@ package tdx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"iter"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/injoyai/base/maps"
|
||||
"github.com/injoyai/base/types"
|
||||
"github.com/injoyai/conv"
|
||||
@@ -12,9 +17,6 @@ import (
|
||||
"github.com/injoyai/tdx/internal/xorms"
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
"github.com/robfig/cron/v3"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@@ -148,11 +150,13 @@ type Codes2 struct {
|
||||
内部字段
|
||||
*/
|
||||
|
||||
c *Client //
|
||||
db *xorms.Engine //
|
||||
stocks types.List[string] //缓存
|
||||
etfs types.List[string] //缓存
|
||||
m *maps.Generic[string, *CodeModel] //缓存
|
||||
c *Client //
|
||||
db *xorms.Engine //
|
||||
stocks types.List[*CodeModel] //股票缓存
|
||||
etfs types.List[*CodeModel] //etf缓存
|
||||
indexes types.List[*CodeModel] //指数缓存
|
||||
all types.List[*CodeModel] //全部缓存
|
||||
m *maps.Generic[string, *CodeModel] //缓存
|
||||
}
|
||||
|
||||
func (this *Codes2) Get(code string) *CodeModel {
|
||||
@@ -160,6 +164,16 @@ func (this *Codes2) Get(code string) *CodeModel {
|
||||
return v
|
||||
}
|
||||
|
||||
func (this *Codes2) Iter() iter.Seq2[string, *CodeModel] {
|
||||
return func(yield func(string, *CodeModel) bool) {
|
||||
for _, code := range this.all {
|
||||
if !yield(code.FullCode(), code) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Codes2) GetName(code string) string {
|
||||
v, _ := this.m.Get(code)
|
||||
if v == nil {
|
||||
@@ -168,14 +182,31 @@ func (this *Codes2) GetName(code string) string {
|
||||
return v.Name
|
||||
}
|
||||
|
||||
func (this *Codes2) GetStocks(limit ...int) []string {
|
||||
func (this *Codes2) GetStocks(limit ...int) CodeModels {
|
||||
size := conv.Default(this.stocks.Len(), limit...)
|
||||
return this.stocks.Limit(size)
|
||||
return CodeModels(this.stocks.Limit(size))
|
||||
}
|
||||
|
||||
func (this *Codes2) GetETFs(limit ...int) []string {
|
||||
func (this *Codes2) GetStockCodes(limit ...int) []string {
|
||||
return this.GetStocks(limit...).Codes()
|
||||
}
|
||||
|
||||
func (this *Codes2) GetETFs(limit ...int) CodeModels {
|
||||
size := conv.Default(this.etfs.Len(), limit...)
|
||||
return this.etfs.Limit(size)
|
||||
return CodeModels(this.etfs.Limit(size))
|
||||
}
|
||||
|
||||
func (this *Codes2) GetETFCodes(limit ...int) []string {
|
||||
return this.GetETFs(limit...).Codes()
|
||||
}
|
||||
|
||||
func (this *Codes2) GetIndexes(limit ...int) CodeModels {
|
||||
size := conv.Default(this.etfs.Len(), limit...)
|
||||
return CodeModels(this.indexes.Limit(size))
|
||||
}
|
||||
|
||||
func (this *Codes2) GetIndexCodes(limit ...int) []string {
|
||||
return this.GetIndexes(limit...).Codes()
|
||||
}
|
||||
|
||||
func (this *Codes2) updated() (bool, error) {
|
||||
@@ -218,21 +249,26 @@ func (this *Codes2) Update() error {
|
||||
return err
|
||||
}
|
||||
|
||||
stocks := []string(nil)
|
||||
etfs := []string(nil)
|
||||
stocks := []*CodeModel(nil)
|
||||
etfs := []*CodeModel(nil)
|
||||
indexes := []*CodeModel(nil)
|
||||
for _, v := range codes {
|
||||
fullCode := v.FullCode()
|
||||
this.m.Set(fullCode, v)
|
||||
switch {
|
||||
case protocol.IsStock(fullCode):
|
||||
stocks = append(stocks, fullCode)
|
||||
stocks = append(stocks, v)
|
||||
case protocol.IsETF(fullCode):
|
||||
etfs = append(etfs, fullCode)
|
||||
etfs = append(etfs, v)
|
||||
case protocol.IsIndex(fullCode):
|
||||
indexes = append(indexes, v)
|
||||
}
|
||||
}
|
||||
|
||||
this.stocks = stocks
|
||||
this.etfs = etfs
|
||||
this.indexes = indexes
|
||||
this.all = codes
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ func main() {
|
||||
m, err := tdx.NewManage(nil)
|
||||
logs.PanicErr(err)
|
||||
|
||||
codes := m.Codes.GetStocks()
|
||||
codes := m.Codes.GetStocks().Codes()
|
||||
//codes = []string{
|
||||
// "sz000001",
|
||||
// "sz000002",
|
||||
|
||||
29
example/GetETFCodeNumber/main.go
Normal file
29
example/GetETFCodeNumber/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cs, err := tdx.NewCodes2()
|
||||
logs.PanicErr(err)
|
||||
|
||||
ls := cs.GetETFCodes()
|
||||
|
||||
shNumber := 0
|
||||
szNumber := 0
|
||||
for _, v := range ls {
|
||||
switch {
|
||||
case strings.HasPrefix(v, "sh"):
|
||||
shNumber++
|
||||
case strings.HasPrefix(v, "sz"):
|
||||
szNumber++
|
||||
}
|
||||
}
|
||||
|
||||
logs.Debug("sh:", shNumber)
|
||||
logs.Debug("sz:", szNumber)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (this *PullKlineMysql) Run(ctx context.Context, m *tdx.Manage) error {
|
||||
//1. 获取所有股票代码
|
||||
codes := this.Config.Codes
|
||||
if len(codes) == 0 {
|
||||
codes = m.Codes.GetStocks()
|
||||
codes = m.Codes.GetStockCodes()
|
||||
}
|
||||
|
||||
for _, v := range codes {
|
||||
|
||||
@@ -110,7 +110,7 @@ func (this *PullKline) Run(ctx context.Context, m *tdx.Manage) error {
|
||||
//1. 获取所有股票代码
|
||||
codes := this.Config.Codes
|
||||
if len(codes) == 0 {
|
||||
codes = m.Codes.GetStocks()
|
||||
codes = m.Codes.GetStockCodes()
|
||||
}
|
||||
|
||||
for _, v := range codes {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/injoyai/tdx
|
||||
|
||||
go 1.20
|
||||
go 1.23
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.22.0
|
||||
|
||||
16
go.sum
16
go.sum
@@ -22,12 +22,11 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
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/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||
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.2.15 h1:K/ysPqZl7vgNUAz/jpG1IdDpzdSMWvUfoJL+1gPdM9g=
|
||||
github.com/injoyai/base v1.2.15/go.mod h1:NfCQjml3z2pCvQ3J3YcOXtecqXD0xVPKjo4YTsMLhr8=
|
||||
github.com/injoyai/base v1.2.17 h1:+qYeCSeEMWgmTla+LBC0Ozan9ysS4mV0ne5nfMt9opU=
|
||||
github.com/injoyai/base v1.2.17/go.mod h1:NfCQjml3z2pCvQ3J3YcOXtecqXD0xVPKjo4YTsMLhr8=
|
||||
github.com/injoyai/conv v1.2.5 h1:G4OCyF0NTZul5W1u9IgXDOhW4/zmIigdPKXFHQGmv1M=
|
||||
@@ -39,6 +38,7 @@ github.com/injoyai/logs v1.0.12/go.mod h1:+dKEL6GvaFqqVRatqUBiCicJbZnAgtj7hVs824
|
||||
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/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
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=
|
||||
@@ -50,6 +50,7 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@@ -84,11 +85,14 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
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=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -98,9 +102,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
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.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
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=
|
||||
@@ -114,8 +120,11 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo=
|
||||
lukechampine.com/uint128 v1.3.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.41.0 h1:QoR1Sn3YWlmA1T4vLaKZfawdVtSiGx8H+cEojbC7v1Q=
|
||||
modernc.org/cc/v3 v3.41.0/go.mod h1:Ni4zjJYJ04CDOhG7dn640WGfwBzfE0ecX8TyMB0Fv0Y=
|
||||
modernc.org/ccgo/v3 v3.16.15 h1:KbDR3ZAVU+wiLyMESPtbtE/Add4elztFyfsWoNTgxS0=
|
||||
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
|
||||
modernc.org/libc v1.37.6 h1:orZH3c5wmhIQFTXF+Nt+eeauyd+ZIt2BX6ARe+kD+aw=
|
||||
modernc.org/libc v1.37.6/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
@@ -123,10 +132,13 @@ modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWP
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ=
|
||||
modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 h1:bvLlAPW1ZMTWA32LuZMBEGHAUOcATZjzHcotf3SWweM=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
xorm.io/core v0.7.3 h1:W8ws1PlrnkS1CZU1YWaYLMQcQilwAmQXU0BJDJon+H0=
|
||||
|
||||
@@ -175,14 +175,14 @@ type Manage struct {
|
||||
// RangeStocks 遍历所有股票
|
||||
func (this *Manage) RangeStocks(f func(code string)) {
|
||||
for _, v := range this.Codes.GetStocks() {
|
||||
f(v)
|
||||
f(v.FullCode())
|
||||
}
|
||||
}
|
||||
|
||||
// RangeETFs 遍历所有ETF
|
||||
func (this *Manage) RangeETFs(f func(code string)) {
|
||||
for _, v := range this.Codes.GetETFs() {
|
||||
f(v)
|
||||
f(v.FullCode())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ package protocol
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/injoyai/conv"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
"io"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/injoyai/conv"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
// String 字节先转小端,再转字符
|
||||
@@ -285,12 +286,27 @@ func IsETF(code string) bool {
|
||||
return true
|
||||
|
||||
case code[0:2] == ExchangeSZ.String() &&
|
||||
(code[2:4] == "15" || code[2:4] == "16"):
|
||||
(code[2:4] == "15"):
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsIndex 是否是指数,sh000001,sz399001,bj899100
|
||||
func IsIndex(code string) bool {
|
||||
if len(code) != 8 {
|
||||
return false
|
||||
}
|
||||
code = strings.ToLower(code)
|
||||
switch {
|
||||
case code[0:2] == ExchangeSH.String() && code[2:5] == "000":
|
||||
return true
|
||||
case code[0:2] == ExchangeSZ.String() && code[2:5] == "399":
|
||||
case code[0:2] == ExchangeBJ.String() && code[2:5] == "899":
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// AddPrefix 添加股票/基金代码前缀,针对股票/基金生效,例如000001,会增加前缀sz000001(平安银行),而不是sh000001(上证指数)
|
||||
func AddPrefix(code string) string {
|
||||
if len(code) == 6 {
|
||||
|
||||
Reference in New Issue
Block a user