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,10 @@
|
|||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/injoyai/logs"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ func (this SecurityQuotesResp) String() string {
|
|||||||
|
|
||||||
type SecurityQuote struct {
|
type SecurityQuote struct {
|
||||||
Exchange Exchange // 市场
|
Exchange Exchange // 市场
|
||||||
Code string // 代码
|
Code string // 股票代码 6个ascii字符串
|
||||||
Active1 uint16 // 活跃度
|
Active1 uint16 // 活跃度
|
||||||
K K //k线
|
K K //k线
|
||||||
ServerTime string // 时间
|
ServerTime string // 时间
|
||||||
@@ -107,37 +109,18 @@ type SecurityQuote struct {
|
|||||||
InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上)
|
InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上)
|
||||||
OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上)
|
OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上)
|
||||||
|
|
||||||
ReversedBytes2 int // 保留
|
ReversedBytes2 int // 保留,未知
|
||||||
ReversedBytes3 int // 保留
|
ReversedBytes3 int // 保留,未知
|
||||||
BidLevels [5]PriceLevel
|
BuyLevel [5]PriceLevel // 5档买盘(买1-5)
|
||||||
AskLevels [5]PriceLevel
|
SellLevel [5]PriceLevel // 5档卖盘(卖1-5)
|
||||||
Bid1 float64
|
|
||||||
Ask1 float64
|
ReversedBytes4 uint16 // 保留,未知
|
||||||
BidVol1 int
|
ReversedBytes5 int // 保留,未知
|
||||||
AskVol1 int
|
ReversedBytes6 int // 保留,未知
|
||||||
Bid2 float64
|
ReversedBytes7 int // 保留,未知
|
||||||
Ask2 float64
|
ReversedBytes8 int // 保留,未知
|
||||||
BidVol2 int
|
ReversedBytes9 uint16 // 保留,未知
|
||||||
AskVol2 int
|
Rate float64 // 涨速,好像都是0
|
||||||
Bid3 float64
|
|
||||||
Ask3 float64
|
|
||||||
BidVol3 int
|
|
||||||
AskVol3 int
|
|
||||||
Bid4 float64
|
|
||||||
Ask4 float64
|
|
||||||
BidVol4 int
|
|
||||||
AskVol4 int
|
|
||||||
Bid5 float64
|
|
||||||
Ask5 float64
|
|
||||||
BidVol5 int
|
|
||||||
AskVol5 int
|
|
||||||
ReversedBytes4 uint16 // 保留
|
|
||||||
ReversedBytes5 int // 保留
|
|
||||||
ReversedBytes6 int // 保留
|
|
||||||
ReversedBytes7 int // 保留
|
|
||||||
ReversedBytes8 int // 保留
|
|
||||||
ReversedBytes9 uint16 // 保留
|
|
||||||
Rate float64 // 涨速
|
|
||||||
Active2 uint16 // 活跃度
|
Active2 uint16 // 活跃度
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,10 +155,33 @@ func (this securityQuote) Frame(m map[Exchange]string) (*Frame, error) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Decode
|
Decode
|
||||||
b1cb74000c02000000003e05af00af000136020000303030303031320bb2124c56105987e6d10cf212b78fa801ae01293dc54e8bd740acb8670086ca1e0001af36ba0c4102b467b6054203a68a0184094304891992114405862685108d0100000000e8ff320b0136303030303859098005464502468defd10cc005bed2668e05be15804d8ba12cb3b13a0083c3034100badc029d014201bc990384f70443029da503b7af074403a6e501b9db044504a6e2028dd5048d050000000000005909
|
0136
|
||||||
|
0200 数量
|
||||||
|
00 交易所
|
||||||
|
303030303031 股票代码
|
||||||
|
320b 活跃度?
|
||||||
|
b212 昨天收盘价1186
|
||||||
|
4c
|
||||||
|
56
|
||||||
|
10
|
||||||
|
59
|
||||||
|
87e6d10cf212b78fa801ae01293dc54e8bd740acb8670086ca1e0001af36ba0c4102b467b6054203a68a0184094304891992114405862685108d0100000000e8ff320b
|
||||||
|
|
||||||
|
01 深圳交易所
|
||||||
|
363030303038 股票代码
|
||||||
|
5909
|
||||||
|
8005
|
||||||
|
46
|
||||||
|
45
|
||||||
|
02
|
||||||
|
46
|
||||||
|
8defd10c 服务时间
|
||||||
|
c005bed2668e05be15804d8ba12cb3b13a0083c3034100badc029d014201bc990384f70443029da503b7af074403a6e501b9db044504a6e2028dd5048d050000000000005909
|
||||||
*/
|
*/
|
||||||
func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
||||||
|
|
||||||
|
logs.Debug(hex.EncodeToString(bs))
|
||||||
|
|
||||||
resp := SecurityQuotesResp{}
|
resp := SecurityQuotesResp{}
|
||||||
|
|
||||||
//前2字节是什么?
|
//前2字节是什么?
|
||||||
@@ -204,19 +210,19 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
|||||||
|
|
||||||
var p Price
|
var p Price
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
bidele := PriceLevel{}
|
buyLevel := PriceLevel{}
|
||||||
offerele := PriceLevel{}
|
sellLevel := PriceLevel{}
|
||||||
|
|
||||||
bs, p = GetPrice(bs)
|
bs, p = GetPrice(bs)
|
||||||
bidele.Price = p + sec.K.Close
|
buyLevel.Price = p + sec.K.Close
|
||||||
bs, p = GetPrice(bs)
|
bs, p = GetPrice(bs)
|
||||||
offerele.Price = p + sec.K.Close
|
sellLevel.Price = p + sec.K.Close
|
||||||
|
|
||||||
bs, bidele.Vol = CutInt(bs)
|
bs, buyLevel.Number = CutInt(bs)
|
||||||
bs, offerele.Vol = CutInt(bs)
|
bs, sellLevel.Number = CutInt(bs)
|
||||||
|
|
||||||
sec.BidLevels[i] = bidele
|
sec.BuyLevel[i] = buyLevel
|
||||||
sec.AskLevels[i] = offerele
|
sec.SellLevel[i] = sellLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
sec.ReversedBytes4 = Uint16(bs[:2])
|
sec.ReversedBytes4 = Uint16(bs[:2])
|
||||||
@@ -229,6 +235,8 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
|||||||
sec.Rate = float64(sec.ReversedBytes9) / 100
|
sec.Rate = float64(sec.ReversedBytes9) / 100
|
||||||
sec.Active2 = Uint16(bs[2:4])
|
sec.Active2 = Uint16(bs[2:4])
|
||||||
|
|
||||||
|
bs = bs[4:]
|
||||||
|
|
||||||
resp = append(resp, sec)
|
resp = append(resp, sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ func (this Price) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PriceLevel struct {
|
type PriceLevel struct {
|
||||||
Price Price //价
|
Price Price //价 想买卖的价格
|
||||||
Vol int //量,是否是成交量?
|
Number int //量 想买卖的数量
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PriceLevels [5]PriceLevel
|
||||||
|
|
||||||
// K k线图
|
// K k线图
|
||||||
type K struct {
|
type K struct {
|
||||||
Last Price //昨天收盘价
|
Last Price //昨天收盘价
|
||||||
@@ -34,25 +36,26 @@ func (this K) String() string {
|
|||||||
return fmt.Sprintf("昨收:%0.2f, 今开:%0.2f, 最高:%0.2f, 最低:%0.2f, 今收:%0.2f", this.Last.Float64(), this.Open.Float64(), this.High.Float64(), this.Low.Float64(), this.Close.Float64())
|
return fmt.Sprintf("昨收:%0.2f, 今开:%0.2f, 最高:%0.2f, 最低:%0.2f, 今收:%0.2f", this.Last.Float64(), this.Open.Float64(), this.High.Float64(), this.Low.Float64(), this.Close.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodeK 一般是占用6字节
|
||||||
func DecodeK(bs []byte) ([]byte, K) {
|
func DecodeK(bs []byte) ([]byte, K) {
|
||||||
k := K{}
|
k := K{}
|
||||||
|
|
||||||
//当日收盘价
|
//当日收盘价,一般2字节
|
||||||
bs, k.Close = GetPrice(bs)
|
bs, k.Close = GetPrice(bs)
|
||||||
|
|
||||||
//前日收盘价
|
//前日收盘价,一般1字节
|
||||||
bs, k.Last = GetPrice(bs)
|
bs, k.Last = GetPrice(bs)
|
||||||
k.Last += k.Close
|
k.Last += k.Close
|
||||||
|
|
||||||
//当日开盘价
|
//当日开盘价,一般1字节
|
||||||
bs, k.Open = GetPrice(bs)
|
bs, k.Open = GetPrice(bs)
|
||||||
k.Open += k.Close
|
k.Open += k.Close
|
||||||
|
|
||||||
//当日最高价
|
//当日最高价,一般1字节
|
||||||
bs, k.High = GetPrice(bs)
|
bs, k.High = GetPrice(bs)
|
||||||
k.High += k.Close
|
k.High += k.Close
|
||||||
|
|
||||||
//当日最低价
|
//当日最低价,一般1字节
|
||||||
bs, k.Low = GetPrice(bs)
|
bs, k.Low = GetPrice(bs)
|
||||||
k.Low += k.Close
|
k.Low += k.Close
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user