From 98276888536b85ba6ec3bbdaf86089383e7afec6 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Fri, 25 Oct 2024 16:11:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=B8=AD...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++-- protocol/{model.go => model_quote.go} | 28 +++++++++++-------- .../{model_test.go => model_quote_test.go} | 0 protocol/{model_k.go => types_price.go} | 20 +++++++++++-- .../{model_k_test.go => types_price_test.go} | 0 protocol/unit.go | 3 ++ 6 files changed, 42 insertions(+), 16 deletions(-) rename protocol/{model.go => model_quote.go} (88%) rename protocol/{model_test.go => model_quote_test.go} (100%) rename protocol/{model_k.go => types_price.go} (87%) rename protocol/{model_k_test.go => types_price_test.go} (100%) diff --git a/README.md b/README.md index c4fa867..82af32e 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,8 @@ ### 开发进度 -#### 能通讯,有响应数据,还未解析响应数据 -![](docs/plan.png) \ No newline at end of file +#### 开发进度 +* 能通讯,有响应数据,还未解析响应数据 +![](docs/plan.png) +* 基本信息(5档报价) +![](docs/plan20241025.png) \ No newline at end of file diff --git a/protocol/model.go b/protocol/model_quote.go similarity index 88% rename from protocol/model.go rename to protocol/model_quote.go index 1bc4782..dad9114 100644 --- a/protocol/model.go +++ b/protocol/model_quote.go @@ -1,10 +1,8 @@ package protocol import ( - "encoding/hex" "errors" "fmt" - "github.com/injoyai/logs" "strings" ) @@ -109,10 +107,10 @@ type SecurityQuote struct { InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上) OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上) - ReversedBytes2 int // 保留,未知 - ReversedBytes3 int // 保留,未知 - BuyLevel [5]PriceLevel // 5档买盘(买1-5) - SellLevel [5]PriceLevel // 5档卖盘(卖1-5) + ReversedBytes2 int // 保留,未知 + ReversedBytes3 int // 保留,未知 + BuyLevel PriceLevels // 5档买盘(买1-5) + SellLevel PriceLevels // 5档卖盘(卖1-5) ReversedBytes4 uint16 // 保留,未知 ReversedBytes5 int // 保留,未知 @@ -125,10 +123,16 @@ type SecurityQuote struct { } func (this *SecurityQuote) String() string { - return this.K.String() + fmt.Sprintf(", 总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s", - IntUnitString(this.TotalHand), IntUnitString(this.Intuition), FloatUnitString(this.Amount), - IntUnitString(this.InsideDish), IntUnitString(this.OuterDisc)) + "\n" + - fmt.Sprintf("%#v\n", this) + return fmt.Sprintf(`%s%s +%s +总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s +%s%s +`, + this.Exchange.String(), this.Code, this.K, + IntUnitString(this.TotalHand), IntUnitString(this.Intuition), + FloatUnitString(this.Amount), IntUnitString(this.InsideDish), IntUnitString(this.OuterDisc), + this.SellLevel.String(), this.BuyLevel.String(), + ) } type securityQuote struct{} @@ -180,7 +184,7 @@ c005bed2668e05be15804d8ba12cb3b13a0083c3034100badc029d014201bc990384f70443029da5 */ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp { - logs.Debug(hex.EncodeToString(bs)) + //logs.Debug(hex.EncodeToString(bs)) resp := SecurityQuotesResp{} @@ -210,7 +214,7 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp { var p Price for i := 0; i < 5; i++ { - buyLevel := PriceLevel{} + buyLevel := PriceLevel{Buy: true} sellLevel := PriceLevel{} bs, p = GetPrice(bs) diff --git a/protocol/model_test.go b/protocol/model_quote_test.go similarity index 100% rename from protocol/model_test.go rename to protocol/model_quote_test.go diff --git a/protocol/model_k.go b/protocol/types_price.go similarity index 87% rename from protocol/model_k.go rename to protocol/types_price.go index 83fb48f..a197a86 100644 --- a/protocol/model_k.go +++ b/protocol/types_price.go @@ -13,16 +13,32 @@ func (this Price) Float64() float64 { } func (this Price) String() string { - return fmt.Sprintf("%0.2f 元", this.Float64()) + return fmt.Sprintf("%0.2f元", this.Float64()) } type PriceLevel struct { + Buy bool //买卖 Price Price //价 想买卖的价格 Number int //量 想买卖的数量 } type PriceLevels [5]PriceLevel +func (this PriceLevels) String() string { + s := "" + if this[0].Buy { + for i, v := range this { + s += fmt.Sprintf("买%d %s %s\n", i+1, v.Price, IntUnitString(v.Number)) + } + + } else { + for i := 4; i >= 0; i-- { + s += fmt.Sprintf("卖%d %s %s\n", i+1, this[i].Price, IntUnitString(this[i].Number)) + } + } + return s +} + // K k线图 type K struct { Last Price //昨天收盘价 @@ -33,7 +49,7 @@ type K struct { } 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("昨收:%s, 今开:%s, 最高:%s, 最低:%s, 今收:%s", this.Last, this.Open, this.High, this.Low, this.Close) } // DecodeK 一般是占用6字节 diff --git a/protocol/model_k_test.go b/protocol/types_price_test.go similarity index 100% rename from protocol/model_k_test.go rename to protocol/types_price_test.go diff --git a/protocol/unit.go b/protocol/unit.go index 5af69cf..f5a40f3 100644 --- a/protocol/unit.go +++ b/protocol/unit.go @@ -48,6 +48,9 @@ func FloatUnitString(f float64) string { for i := 0; f > 1e4 && i < len(m); f /= 1e4 { unit = m[i] } + if unit == "" { + return conv.String(f) + } return fmt.Sprintf("%0.2f%s", f, unit) }