mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
修改股票的英文Security为Stock
增加了分时数据,借鉴的第三方好像解析也不对,迟点再找个第三方包试下
This commit is contained in:
@@ -10,7 +10,7 @@ func main() {
|
||||
c, err := tdx.Dial("124.71.187.122:7709")
|
||||
logs.PanicErr(err)
|
||||
|
||||
resp, err := c.GetSecurityList(protocol.ExchangeSH)
|
||||
resp, err := c.GetStockList(protocol.ExchangeSH)
|
||||
logs.PrintErr(err)
|
||||
|
||||
for _, v := range resp.List {
|
||||
21
example/GetStockMinute/main.go
Normal file
21
example/GetStockMinute/main.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/injoyai/logs"
|
||||
"github.com/injoyai/tdx"
|
||||
"github.com/injoyai/tdx/protocol"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c, err := tdx.Dial("124.71.187.122:7709")
|
||||
logs.PanicErr(err)
|
||||
|
||||
resp, err := c.GetStockMinute(protocol.ExchangeSZ, "000001")
|
||||
logs.PrintErr(err)
|
||||
|
||||
for _, v := range resp.List {
|
||||
logs.Debug(v)
|
||||
}
|
||||
|
||||
<-c.Done()
|
||||
}
|
||||
@@ -21,7 +21,7 @@ func main() {
|
||||
b1cb74001c00000000000d005100bd00789c6378c1cecb252ace6066c5b4898987b9050ed1f90cc5b74c18a5bc18c1b43490fecff09c81819191f13fc3c9f3bb169f5e7dfefeb5ef57f7199a305009308208e5b32bb6bcbf70148712002d7f1e13
|
||||
b1cb74000c02000000003e05ac00ac000102020000303030303031601294121a1c2d4eadabcf0ed412aae5fc01afb0024561124fbcc08301afa47900b2e3174100bf68871a4201b741b6144302bb09af334403972e96354504ac09b619560e00000000f8ff601201363030303038b60fba04060607429788a70efa04ada37ab2531c12974d91e7449dbc354184b6010001844bad324102b5679ea1014203a65abd8d0143048a6ba4dd01440587e101b3d2029613000000000000b60f
|
||||
*/
|
||||
resp, err := c.GetSecurityQuotes(map[protocol.Exchange]string{
|
||||
resp, err := c.GetStockQuotes(map[protocol.Exchange]string{
|
||||
protocol.ExchangeSH: "000001",
|
||||
protocol.ExchangeSZ: "600008",
|
||||
})
|
||||
@@ -65,7 +65,8 @@ type Response struct {
|
||||
|
||||
/*
|
||||
Decode
|
||||
b1cb7400 1c 00000000 00 0d00 5100 bd00 789c6378c1cecb252ace6066c5b4898987b9050ed1f90cc5b74c18a5bc18c1b43490fecff09c81819191f13fc3c9f3bb169f5e7dfefeb5ef57f7199a305009308208e5b32bb6bcbf70148712002d7f1e13
|
||||
帧头 |未知 |消息ID |控制码 |数据类型 |未解压长度 |解压长度 |数据域
|
||||
b1cb7400 |1c |00000000 |00 |0d00 |5100 |bd00 |789c6378c1cecb252ace6066c5b4898987b9050ed1f90cc5b74c18a5bc18c1b43490fecff09c81819191f13fc3c9f3bb169f5e7dfefeb5ef57f7199a305009308208e5b32bb6bcbf70148712002d7f1e13
|
||||
*/
|
||||
func Decode(bs []byte) (*Response, error) {
|
||||
if len(bs) < 16 {
|
||||
|
||||
@@ -4,13 +4,16 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/injoyai/conv"
|
||||
"github.com/injoyai/logs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
MConnect = connect{}
|
||||
MHeart = heart{}
|
||||
MStockQuote = stockQuote{}
|
||||
MStockList = stockList{}
|
||||
MStockMinute = stockMinute{}
|
||||
)
|
||||
|
||||
type ConnectResp struct {
|
||||
@@ -39,6 +42,21 @@ func (connect) Decode(bs []byte) (*ConnectResp, error) {
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
type heart struct{}
|
||||
|
||||
func (this *heart) Frame() *Frame {
|
||||
return &Frame{
|
||||
Control: Control01,
|
||||
Type: TypeHeart,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
type StockListResp struct {
|
||||
@@ -64,7 +82,7 @@ func (stockList) Frame(exchange Exchange, starts ...uint16) *Frame {
|
||||
start := conv.DefaultUint16(0, starts...)
|
||||
return &Frame{
|
||||
Control: Control01,
|
||||
Type: TypeSecurityList,
|
||||
Type: TypeStockList,
|
||||
Data: []byte{exchange.Uint8(), 0x0, uint8(start), uint8(start >> 8)},
|
||||
}
|
||||
}
|
||||
@@ -159,7 +177,7 @@ type stockQuote struct{}
|
||||
func (this stockQuote) Frame(m map[Exchange]string) (*Frame, error) {
|
||||
f := &Frame{
|
||||
Control: Control01,
|
||||
Type: TypeSecurityQuote,
|
||||
Type: TypeStockQuote,
|
||||
Data: []byte{0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
}
|
||||
|
||||
@@ -265,3 +283,58 @@ func (this stockQuote) Decode(bs []byte) StockQuotesResp {
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
type StockMinuteResp struct {
|
||||
Count uint16
|
||||
List []PriceLevel
|
||||
}
|
||||
|
||||
type stockMinute struct{}
|
||||
|
||||
func (this *stockMinute) Frame(exchange Exchange, code string) (*Frame, error) {
|
||||
if len(code) != 6 {
|
||||
return nil, errors.New("股票代码长度错误")
|
||||
}
|
||||
codeBs := []byte(code)
|
||||
codeBs = append(codeBs, 0x0, 0x0, 0x0, 0x0)
|
||||
return &Frame{
|
||||
Control: Control01,
|
||||
Type: TypeStockMinute,
|
||||
Data: append([]byte{exchange.Uint8(), 0x0}, codeBs...),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (this *stockMinute) Decode(bs []byte) (*StockMinuteResp, error) {
|
||||
|
||||
if len(bs) < 6 {
|
||||
return nil, errors.New("数据长度不足")
|
||||
}
|
||||
|
||||
resp := &StockMinuteResp{
|
||||
Count: Uint16(bs[:2]),
|
||||
}
|
||||
//2-6字节是啥?
|
||||
bs = bs[6:]
|
||||
price := Price(0)
|
||||
|
||||
for i := uint16(0); i < resp.Count; i++ {
|
||||
bs, price = GetPrice(bs)
|
||||
var what Price
|
||||
bs, what = GetPrice(bs) //这个是什么
|
||||
logs.Debug(price, what)
|
||||
var number int
|
||||
bs, number = CutInt(bs)
|
||||
resp.List = append(resp.List, PriceLevel{
|
||||
Price: price,
|
||||
Number: number,
|
||||
})
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user