From a12b6cafe9b6e2f08f6753fb739deeebac482dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Thu, 24 Oct 2024 23:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E5=AF=B9=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E6=9D=A1=E6=95=B0=E6=8D=AE=E5=B7=B2=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/model.go | 90 ++++++++++++++++++++++++--------------------- protocol/model_k.go | 17 +++++---- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/protocol/model.go b/protocol/model.go index 42e11bf..1bc4782 100644 --- a/protocol/model.go +++ b/protocol/model.go @@ -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) } diff --git a/protocol/model_k.go b/protocol/model_k.go index d260b6e..83fb48f 100644 --- a/protocol/model_k.go +++ b/protocol/model_k.go @@ -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