mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
开发
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
package protocol
|
||||
|
||||
type Exchange uint8
|
||||
|
||||
func (this Exchange) Uint8() uint8 { return uint8(this) }
|
||||
|
||||
const (
|
||||
Connect = 0x000d //建立连接
|
||||
Handshake = 0xdb0f //握手
|
||||
ExchangeSH Exchange = iota //上海交易所
|
||||
ExchangeSZ //深圳交易所
|
||||
)
|
||||
|
||||
const (
|
||||
Control = 0x01
|
||||
)
|
||||
|
||||
const (
|
||||
Connect = 0x000d //建立连接
|
||||
Handshake = 0xdb0f //握手
|
||||
SecurityQuote = 0x053e // 行情信息
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -40,3 +40,31 @@ func DecodeSecurityList(bs []byte) (*SecurityListResp, error) {
|
||||
return nil, nil
|
||||
|
||||
}
|
||||
|
||||
func NewConnect() *Frame {
|
||||
return &Frame{
|
||||
Control: Control,
|
||||
Type: Connect,
|
||||
Data: []byte{0x01},
|
||||
}
|
||||
}
|
||||
|
||||
func NewSecurityQuotes(m map[Exchange]string) (*Frame, error) {
|
||||
f := &Frame{
|
||||
Control: Control,
|
||||
Type: SecurityQuote,
|
||||
Data: []byte{0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
}
|
||||
|
||||
payload := Bytes(uint16(len(m)))
|
||||
for k, v := range m {
|
||||
if len(v) != 6 {
|
||||
return nil, errors.New("股票代码长度错误")
|
||||
}
|
||||
payload = append(payload, k.Uint8())
|
||||
payload = append(payload, v...)
|
||||
}
|
||||
f.Data = append(f.Data, payload...)
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
21
protocol/model_test.go
Normal file
21
protocol/model_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
/*
|
||||
0c00000000011a001a003e05050000000000000002000030303030303101363030303038
|
||||
0c02000000011a001a003e05050000000000000002000030303030303101363030303038
|
||||
*/
|
||||
func TestNewSecurityQuotes(t *testing.T) {
|
||||
f, err := NewSecurityQuotes(map[Exchange]string{
|
||||
ExchangeSH: "000001",
|
||||
ExchangeSZ: "600008",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
t.Log(f.Bytes().HEX())
|
||||
}
|
||||
Reference in New Issue
Block a user