mirror of
https://github.com/bensema/gotdx.git
synced 2025-11-21 02:45:33 +08:00
readme
This commit is contained in:
52
README.md
52
README.md
@@ -1 +1,53 @@
|
|||||||
# gotdx
|
# gotdx
|
||||||
|
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gotdx"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var opt = &gotdx.Opt{
|
||||||
|
Host: "119.147.212.81",
|
||||||
|
Port: 7709,
|
||||||
|
}
|
||||||
|
api := gotdx.NewClient(opt)
|
||||||
|
connectReply, err := api.Connect()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
log.Println(connectReply.Info)
|
||||||
|
|
||||||
|
reply, err := api.GetSecurityQuotes([]uint8{gotdx.MarketSh, gotdx.MarketSz}, []string{"000001", "600008"})
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, obj := range reply.List {
|
||||||
|
log.Println(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = api.Disconnect()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
- Connect 连接券商行情服务器
|
||||||
|
- Disconnect 断开服务器
|
||||||
|
- GetSecurityCount 获取指定市场内的证券数目
|
||||||
|
- GetSecurityQuotes 获取盘口五档报价
|
||||||
|
- GetSecurityList 获取市场内指定范围内的所有证券代码
|
||||||
|
- GetSecurityBars 获取股票K线
|
||||||
|
- GetIndexBars 获取指数K线
|
||||||
|
- GetMinuteTimeData 获取分时图数据
|
||||||
|
- GetHistoryMinuteTimeData 获取历史分时图数据
|
||||||
|
- GetTransactionData 获取分时成交
|
||||||
|
- GetHistoryTransactionData 获取历史分时成交
|
||||||
48
client.go
48
client.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"gotdx/proto"
|
"gotdx/proto"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -142,8 +143,18 @@ func (client *Client) GetSecurityCount(market uint16) (*proto.GetSecurityCountRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSecurityQuotes 获取盘口五档报价
|
// GetSecurityQuotes 获取盘口五档报价
|
||||||
func (client *Client) GetSecurityQuotes(params []proto.Stock) (*proto.GetSecurityQuotesReply, error) {
|
func (client *Client) GetSecurityQuotes(markets []uint8, codes []string) (*proto.GetSecurityQuotesReply, error) {
|
||||||
|
if len(markets) != len(codes) {
|
||||||
|
return nil, errors.New("market code count error")
|
||||||
|
}
|
||||||
obj := proto.NewGetSecurityQuotes()
|
obj := proto.NewGetSecurityQuotes()
|
||||||
|
var params []proto.Stock
|
||||||
|
for i, market := range markets {
|
||||||
|
params = append(params, proto.Stock{
|
||||||
|
Market: market,
|
||||||
|
Code: codes[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
obj.SetParams(&proto.GetSecurityQuotesRequest{StockList: params})
|
obj.SetParams(&proto.GetSecurityQuotesRequest{StockList: params})
|
||||||
err := client.do(obj)
|
err := client.do(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -153,9 +164,10 @@ func (client *Client) GetSecurityQuotes(params []proto.Stock) (*proto.GetSecurit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSecurityList 获取市场内指定范围内的所有证券代码
|
// GetSecurityList 获取市场内指定范围内的所有证券代码
|
||||||
func (client *Client) GetSecurityList(market uint16, start uint16) (*proto.GetSecurityListReply, error) {
|
func (client *Client) GetSecurityList(market uint8, start uint16) (*proto.GetSecurityListReply, error) {
|
||||||
obj := proto.NewGetSecurityList()
|
obj := proto.NewGetSecurityList()
|
||||||
obj.SetParams(&proto.GetSecurityListRequest{Market: market, Start: start})
|
_market := uint16(market)
|
||||||
|
obj.SetParams(&proto.GetSecurityListRequest{Market: _market, Start: start})
|
||||||
err := client.do(obj)
|
err := client.do(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -164,13 +176,13 @@ func (client *Client) GetSecurityList(market uint16, start uint16) (*proto.GetSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSecurityBars 获取股票K线
|
// GetSecurityBars 获取股票K线
|
||||||
// e Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo
|
func (client *Client) GetSecurityBars(category uint16, market uint8, code string, start uint16, count uint16) (*proto.GetSecurityBarsReply, error) {
|
||||||
func (client *Client) GetSecurityBars(category uint16, market uint16, code string, start uint16, count uint16) (*proto.GetSecurityBarsReply, error) {
|
|
||||||
obj := proto.NewGetSecurityBars()
|
obj := proto.NewGetSecurityBars()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
|
_market := uint16(market)
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetSecurityBarsRequest{
|
obj.SetParams(&proto.GetSecurityBarsRequest{
|
||||||
Market: market,
|
Market: _market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
Category: category,
|
Category: category,
|
||||||
Start: start,
|
Start: start,
|
||||||
@@ -184,12 +196,13 @@ func (client *Client) GetSecurityBars(category uint16, market uint16, code strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetIndexBars 获取指数K线
|
// GetIndexBars 获取指数K线
|
||||||
func (client *Client) GetIndexBars(category uint16, market uint16, code string, start uint16, count uint16) (*proto.GetIndexBarsReply, error) {
|
func (client *Client) GetIndexBars(category uint16, market uint8, code string, start uint16, count uint16) (*proto.GetIndexBarsReply, error) {
|
||||||
obj := proto.NewGetIndexBars()
|
obj := proto.NewGetIndexBars()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
|
_market := uint16(market)
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetIndexBarsRequest{
|
obj.SetParams(&proto.GetIndexBarsRequest{
|
||||||
Market: market,
|
Market: _market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
Category: category,
|
Category: category,
|
||||||
Start: start,
|
Start: start,
|
||||||
@@ -203,12 +216,13 @@ func (client *Client) GetIndexBars(category uint16, market uint16, code string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMinuteTimeData 获取分时图数据
|
// GetMinuteTimeData 获取分时图数据
|
||||||
func (client *Client) GetMinuteTimeData(market uint16, code string) (*proto.GetMinuteTimeDataReply, error) {
|
func (client *Client) GetMinuteTimeData(market uint8, code string) (*proto.GetMinuteTimeDataReply, error) {
|
||||||
obj := proto.NewGetMinuteTimeData()
|
obj := proto.NewGetMinuteTimeData()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
|
_market := uint16(market)
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetMinuteTimeDataRequest{
|
obj.SetParams(&proto.GetMinuteTimeDataRequest{
|
||||||
Market: market,
|
Market: _market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
})
|
})
|
||||||
err := client.do(obj)
|
err := client.do(obj)
|
||||||
@@ -219,13 +233,13 @@ func (client *Client) GetMinuteTimeData(market uint16, code string) (*proto.GetM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHistoryMinuteTimeData 获取历史分时图数据
|
// GetHistoryMinuteTimeData 获取历史分时图数据
|
||||||
func (client *Client) GetHistoryMinuteTimeData(date uint32, market uint16, code string) (*proto.GetHistoryMinuteTimeDataReply, error) {
|
func (client *Client) GetHistoryMinuteTimeData(date uint32, market uint8, code string) (*proto.GetHistoryMinuteTimeDataReply, error) {
|
||||||
obj := proto.NewGetHistoryMinuteTimeData()
|
obj := proto.NewGetHistoryMinuteTimeData()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetHistoryMinuteTimeDataRequest{
|
obj.SetParams(&proto.GetHistoryMinuteTimeDataRequest{
|
||||||
Date: date,
|
Date: date,
|
||||||
Market: uint8(market),
|
Market: market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
})
|
})
|
||||||
err := client.do(obj)
|
err := client.do(obj)
|
||||||
@@ -236,12 +250,13 @@ func (client *Client) GetHistoryMinuteTimeData(date uint32, market uint16, code
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactionData 获取分时成交
|
// GetTransactionData 获取分时成交
|
||||||
func (client *Client) GetTransactionData(market uint16, code string, start uint16, count uint16) (*proto.GetTransactionDataReply, error) {
|
func (client *Client) GetTransactionData(market uint8, code string, start uint16, count uint16) (*proto.GetTransactionDataReply, error) {
|
||||||
obj := proto.NewGetTransactionData()
|
obj := proto.NewGetTransactionData()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
|
_market := uint16(market)
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetTransactionDataRequest{
|
obj.SetParams(&proto.GetTransactionDataRequest{
|
||||||
Market: market,
|
Market: _market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
Start: start,
|
Start: start,
|
||||||
Count: count,
|
Count: count,
|
||||||
@@ -254,13 +269,14 @@ func (client *Client) GetTransactionData(market uint16, code string, start uint1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHistoryTransactionData 获取历史分时成交
|
// GetHistoryTransactionData 获取历史分时成交
|
||||||
func (client *Client) GetHistoryTransactionData(date uint32, market uint16, code string, start uint16, count uint16) (*proto.GetHistoryTransactionDataReply, error) {
|
func (client *Client) GetHistoryTransactionData(date uint32, market uint8, code string, start uint16, count uint16) (*proto.GetHistoryTransactionDataReply, error) {
|
||||||
obj := proto.NewGetHistoryTransactionData()
|
obj := proto.NewGetHistoryTransactionData()
|
||||||
_code := [6]byte{}
|
_code := [6]byte{}
|
||||||
|
_market := uint16(market)
|
||||||
copy(_code[:], code)
|
copy(_code[:], code)
|
||||||
obj.SetParams(&proto.GetHistoryTransactionDataRequest{
|
obj.SetParams(&proto.GetHistoryTransactionDataRequest{
|
||||||
Date: date,
|
Date: date,
|
||||||
Market: market,
|
Market: _market,
|
||||||
Code: _code,
|
Code: _code,
|
||||||
Start: start,
|
Start: start,
|
||||||
Count: count,
|
Count: count,
|
||||||
|
|||||||
@@ -8,19 +8,16 @@ import (
|
|||||||
|
|
||||||
var opt = &Opt{
|
var opt = &Opt{
|
||||||
Host: "119.147.212.81",
|
Host: "119.147.212.81",
|
||||||
//Host: "58.63.254.191",
|
|
||||||
//Host: "218.16.117.138",
|
|
||||||
//Host: "222.85.139.177",
|
|
||||||
Port: 7709,
|
Port: 7709,
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepare() *Client {
|
func prepare() *Client {
|
||||||
api := NewClient(opt)
|
api := NewClient(opt)
|
||||||
r, err := api.Connect()
|
reply, err := api.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
fmt.Println(r)
|
fmt.Println(reply.Info)
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +25,9 @@ func Test_tdx_Connect(t *testing.T) {
|
|||||||
api := NewClient(opt)
|
api := NewClient(opt)
|
||||||
reply, err := api.Connect()
|
reply, err := api.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
fmt.Println(reply)
|
fmt.Println(reply.Info)
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -40,24 +36,23 @@ func Test_tdx_GetSecurityCount(t *testing.T) {
|
|||||||
api := prepare()
|
api := prepare()
|
||||||
reply, err := api.GetSecurityCount(MarketSh)
|
reply, err := api.GetSecurityCount(MarketSh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
fmt.Println(reply)
|
fmt.Println(reply.Count)
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_tdx_GetSecurityQuotes(t *testing.T) {
|
func Test_tdx_GetSecurityQuotes(t *testing.T) {
|
||||||
api := prepare()
|
api := prepare()
|
||||||
params := []proto.Stock{}
|
reply, err := api.GetSecurityQuotes([]uint8{MarketSh}, []string{"002062"})
|
||||||
params = append(params, proto.Stock{Market: MarketSh, Code: "002062"})
|
|
||||||
params = append(params, proto.Stock{Market: MarketSh, Code: "000001"})
|
|
||||||
reply, err := api.GetSecurityQuotes(params)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
|
fmt.Println(obj)
|
||||||
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
|
|
||||||
@@ -67,10 +62,11 @@ func Test_tdx_GetSecurityList(t *testing.T) {
|
|||||||
api := prepare()
|
api := prepare()
|
||||||
reply, err := api.GetSecurityList(MarketSh, 0)
|
reply, err := api.GetSecurityList(MarketSh, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
|
}
|
||||||
|
for _, obj := range reply.List {
|
||||||
|
fmt.Println(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
|
|
||||||
@@ -81,12 +77,11 @@ func Test_tdx_GetSecurityBars(t *testing.T) {
|
|||||||
api := prepare()
|
api := prepare()
|
||||||
reply, err := api.GetSecurityBars(proto.KLINE_TYPE_RI_K, 0, "000001", 0, 10)
|
reply, err := api.GetSecurityBars(proto.KLINE_TYPE_RI_K, 0, "000001", 0, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
@@ -95,16 +90,14 @@ func Test_tdx_GetSecurityBars(t *testing.T) {
|
|||||||
|
|
||||||
func Test_tdx_GetIndexBars(t *testing.T) {
|
func Test_tdx_GetIndexBars(t *testing.T) {
|
||||||
// GetSecurityBars 与 GetIndexBars 使用同一个接口靠market区分
|
// GetSecurityBars 与 GetIndexBars 使用同一个接口靠market区分
|
||||||
|
|
||||||
api := prepare()
|
api := prepare()
|
||||||
reply, err := api.GetIndexBars(proto.KLINE_TYPE_RI_K, 1, "000001", 0, 10)
|
reply, err := api.GetIndexBars(proto.KLINE_TYPE_RI_K, 1, "000001", 0, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
@@ -115,12 +108,11 @@ func Test_tdx_GetMinuteTimeData(t *testing.T) {
|
|||||||
api := prepare()
|
api := prepare()
|
||||||
reply, err := api.GetMinuteTimeData(0, "159607")
|
reply, err := api.GetMinuteTimeData(0, "159607")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
@@ -132,12 +124,11 @@ func Test_tdx_GetHistoryMinuteTimeData(t *testing.T) {
|
|||||||
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
||||||
reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
@@ -149,12 +140,11 @@ func Test_tdx_GetTransactionData(t *testing.T) {
|
|||||||
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
||||||
reply, err := api.GetTransactionData(0, "159607", 0, 10)
|
reply, err := api.GetTransactionData(0, "159607", 0, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
@@ -166,12 +156,11 @@ func Test_tdx_GetHistoryTransactionData(t *testing.T) {
|
|||||||
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
//reply, err := api.GetHistoryMinuteTimeData(20220511, 0, "159607")
|
||||||
reply, err := api.GetHistoryTransactionData(20220511, 0, "159607", 0, 10)
|
reply, err := api.GetHistoryTransactionData(20220511, 0, "159607", 0, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Errorf("error:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(reply)
|
for _, obj := range reply.List {
|
||||||
for _, bar := range reply.List {
|
fmt.Println(obj)
|
||||||
fmt.Println(bar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = api.Disconnect()
|
_ = api.Disconnect()
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetHistoryMinuteTimeData struct {
|
type GetHistoryMinuteTimeData struct {
|
||||||
@@ -77,7 +76,6 @@ func (obj *GetHistoryMinuteTimeData) Serialize() ([]byte, error) {
|
|||||||
///20150520\t4.756000\t4.850000\t4.960000\t4.756000\t353161092\t1722953216.000000”
|
///20150520\t4.756000\t4.850000\t4.960000\t4.756000\t353161092\t1722953216.000000”
|
||||||
func (obj *GetHistoryMinuteTimeData) UnSerialize(header interface{}, data []byte) error {
|
func (obj *GetHistoryMinuteTimeData) UnSerialize(header interface{}, data []byte) error {
|
||||||
obj.respHeader = header.(*RespHeader)
|
obj.respHeader = header.(*RespHeader)
|
||||||
fmt.Println(hex.EncodeToString(data))
|
|
||||||
|
|
||||||
pos := 0
|
pos := 0
|
||||||
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
||||||
|
|||||||
@@ -89,8 +89,6 @@ func (obj *GetIndexBars) Serialize() ([]byte, error) {
|
|||||||
func (obj *GetIndexBars) UnSerialize(header interface{}, data []byte) error {
|
func (obj *GetIndexBars) UnSerialize(header interface{}, data []byte) error {
|
||||||
obj.respHeader = header.(*RespHeader)
|
obj.respHeader = header.(*RespHeader)
|
||||||
|
|
||||||
fmt.Println(hex.EncodeToString(data))
|
|
||||||
|
|
||||||
pos := 0
|
pos := 0
|
||||||
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
||||||
pos += 2
|
pos += 2
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMinuteTimeData struct {
|
type GetMinuteTimeData struct {
|
||||||
@@ -79,7 +78,7 @@ func (obj *GetMinuteTimeData) Serialize() ([]byte, error) {
|
|||||||
///20150520\t4.756000\t4.850000\t4.960000\t4.756000\t353161092\t1722953216.000000”
|
///20150520\t4.756000\t4.850000\t4.960000\t4.756000\t353161092\t1722953216.000000”
|
||||||
func (obj *GetMinuteTimeData) UnSerialize(header interface{}, data []byte) error {
|
func (obj *GetMinuteTimeData) UnSerialize(header interface{}, data []byte) error {
|
||||||
obj.respHeader = header.(*RespHeader)
|
obj.respHeader = header.(*RespHeader)
|
||||||
fmt.Println(hex.EncodeToString(data))
|
|
||||||
pos := 0
|
pos := 0
|
||||||
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
err := binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.reply.Count)
|
||||||
// 跳过4个字节
|
// 跳过4个字节
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ func (obj *GetSecurityCount) SetParams(req *GetSecurityCountRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (obj *GetSecurityCount) Serialize() ([]byte, error) {
|
func (obj *GetSecurityCount) Serialize() ([]byte, error) {
|
||||||
obj.reqHeader.PkgLen1 = 2 + uint16(len(obj.contentHex)) + 2
|
obj.reqHeader.PkgLen1 = 2 + 4 + 2
|
||||||
obj.reqHeader.PkgLen2 = 2 + uint16(len(obj.contentHex)) + 2
|
obj.reqHeader.PkgLen2 = 2 + 4 + 2
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := binary.Write(buf, binary.LittleEndian, obj.reqHeader)
|
err := binary.Write(buf, binary.LittleEndian, obj.reqHeader)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package proto
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"gotdx/utils"
|
"gotdx/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSecurityList struct {
|
type GetSecurityList struct {
|
||||||
@@ -88,7 +88,7 @@ func (obj *GetSecurityList) UnSerialize(header interface{}, data []byte) error {
|
|||||||
binary.Read(bytes.NewBuffer(data[pos:pos+8]), binary.LittleEndian, &name)
|
binary.Read(bytes.NewBuffer(data[pos:pos+8]), binary.LittleEndian, &name)
|
||||||
pos += 8
|
pos += 8
|
||||||
|
|
||||||
ele.Code = utils.Utf8ToGbk(name[:])
|
ele.Code = util.Utf8ToGbk(name[:])
|
||||||
|
|
||||||
pos += 4
|
pos += 4
|
||||||
binary.Read(bytes.NewBuffer(data[pos:pos+1]), binary.LittleEndian, &ele.DecimalPoint)
|
binary.Read(bytes.NewBuffer(data[pos:pos+1]), binary.LittleEndian, &ele.DecimalPoint)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gotdx/utils"
|
"gotdx/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSecurityQuotes struct {
|
type GetSecurityQuotes struct {
|
||||||
@@ -146,7 +146,7 @@ func (obj *GetSecurityQuotes) UnSerialize(header interface{}, data []byte) error
|
|||||||
binary.Read(bytes.NewBuffer(data[pos:pos+6]), binary.LittleEndian, &code)
|
binary.Read(bytes.NewBuffer(data[pos:pos+6]), binary.LittleEndian, &code)
|
||||||
//enc := mahonia.NewDecoder("gbk")
|
//enc := mahonia.NewDecoder("gbk")
|
||||||
//ele.Code = enc.ConvertString(string(code[:]))
|
//ele.Code = enc.ConvertString(string(code[:]))
|
||||||
ele.Code = utils.Utf8ToGbk(code[:])
|
ele.Code = util.Utf8ToGbk(code[:])
|
||||||
pos += 6
|
pos += 6
|
||||||
binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.Active1)
|
binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.Active1)
|
||||||
pos += 2
|
pos += 2
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"gotdx/utils"
|
"gotdx/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Hello1 struct {
|
type Hello1 struct {
|
||||||
@@ -59,7 +59,7 @@ func (obj *Hello1) Serialize() ([]byte, error) {
|
|||||||
func (obj *Hello1) UnSerialize(header interface{}, data []byte) error {
|
func (obj *Hello1) UnSerialize(header interface{}, data []byte) error {
|
||||||
obj.respHeader = header.(*RespHeader)
|
obj.respHeader = header.(*RespHeader)
|
||||||
|
|
||||||
serverInfo := utils.Utf8ToGbk(data[68:])
|
serverInfo := util.Utf8ToGbk(data[68:])
|
||||||
|
|
||||||
obj.reply.Info = serverInfo
|
obj.reply.Info = serverInfo
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"gotdx/utils"
|
"gotdx/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Hello2 struct {
|
type Hello2 struct {
|
||||||
@@ -57,7 +57,7 @@ func (obj *Hello2) Serialize() ([]byte, error) {
|
|||||||
func (obj *Hello2) UnSerialize(header interface{}, data []byte) error {
|
func (obj *Hello2) UnSerialize(header interface{}, data []byte) error {
|
||||||
obj.respHeader = header.(*RespHeader)
|
obj.respHeader = header.(*RespHeader)
|
||||||
|
|
||||||
serverInfo := utils.Utf8ToGbk(data[58:])
|
serverInfo := util.Utf8ToGbk(data[58:])
|
||||||
//fmt.Println(hex.EncodeToString(data))
|
//fmt.Println(hex.EncodeToString(data))
|
||||||
obj.reply.Info = serverInfo
|
obj.reply.Info = serverInfo
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
Reference in New Issue
Block a user