校对数据,多条数据已全部成功解析

This commit is contained in:
钱纯净
2024-10-24 23:18:16 +08:00
parent 9c7923d939
commit a12b6cafe9
2 changed files with 59 additions and 48 deletions

View File

@@ -1,8 +1,10 @@
package protocol
import (
"encoding/hex"
"errors"
"fmt"
"github.com/injoyai/logs"
"strings"
)
@@ -95,7 +97,7 @@ func (this SecurityQuotesResp) String() string {
type SecurityQuote struct {
Exchange Exchange // 市场
Code string // 代码
Code string // 股票代码 6个ascii字符串
Active1 uint16 // 活跃度
K K //k线
ServerTime string // 时间
@@ -107,37 +109,18 @@ type SecurityQuote struct {
InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上)
OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上)
ReversedBytes2 int // 保留
ReversedBytes3 int // 保留
BidLevels [5]PriceLevel
AskLevels [5]PriceLevel
Bid1 float64
Ask1 float64
BidVol1 int
AskVol1 int
Bid2 float64
Ask2 float64
BidVol2 int
AskVol2 int
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 // 涨速
ReversedBytes2 int // 保留,未知
ReversedBytes3 int // 保留,未知
BuyLevel [5]PriceLevel // 5档买盘(买1-5)
SellLevel [5]PriceLevel // 5档卖盘(卖1-5)
ReversedBytes4 uint16 // 保留,未知
ReversedBytes5 int // 保留,未知
ReversedBytes6 int // 保留,未知
ReversedBytes7 int // 保留,未知
ReversedBytes8 int // 保留,未知
ReversedBytes9 uint16 // 保留,未知
Rate float64 // 涨速好像都是0
Active2 uint16 // 活跃度
}
@@ -172,10 +155,33 @@ func (this securityQuote) Frame(m map[Exchange]string) (*Frame, error) {
/*
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 {
logs.Debug(hex.EncodeToString(bs))
resp := SecurityQuotesResp{}
//前2字节是什么?
@@ -204,19 +210,19 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
var p Price
for i := 0; i < 5; i++ {
bidele := PriceLevel{}
offerele := PriceLevel{}
buyLevel := PriceLevel{}
sellLevel := PriceLevel{}
bs, p = GetPrice(bs)
bidele.Price = p + sec.K.Close
buyLevel.Price = p + sec.K.Close
bs, p = GetPrice(bs)
offerele.Price = p + sec.K.Close
sellLevel.Price = p + sec.K.Close
bs, bidele.Vol = CutInt(bs)
bs, offerele.Vol = CutInt(bs)
bs, buyLevel.Number = CutInt(bs)
bs, sellLevel.Number = CutInt(bs)
sec.BidLevels[i] = bidele
sec.AskLevels[i] = offerele
sec.BuyLevel[i] = buyLevel
sec.SellLevel[i] = sellLevel
}
sec.ReversedBytes4 = Uint16(bs[:2])
@@ -229,6 +235,8 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
sec.Rate = float64(sec.ReversedBytes9) / 100
sec.Active2 = Uint16(bs[2:4])
bs = bs[4:]
resp = append(resp, sec)
}

View File

@@ -17,10 +17,12 @@ func (this Price) String() string {
}
type PriceLevel struct {
Price Price //价
Vol int //量,是否是成交量?
Price Price //价 想买卖的价格
Number int //量 想买卖的数量
}
type PriceLevels [5]PriceLevel
// K k线图
type K struct {
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())
}
// DecodeK 一般是占用6字节
func DecodeK(bs []byte) ([]byte, K) {
k := K{}
//当日收盘价
//当日收盘价一般2字节
bs, k.Close = GetPrice(bs)
//前日收盘价
//前日收盘价一般1字节
bs, k.Last = GetPrice(bs)
k.Last += k.Close
//当日开盘价
//当日开盘价一般1字节
bs, k.Open = GetPrice(bs)
k.Open += k.Close
//当日最高价
//当日最高价一般1字节
bs, k.High = GetPrice(bs)
k.High += k.Close
//当日最低价
//当日最低价一般1字节
bs, k.Low = GetPrice(bs)
k.Low += k.Close