开发中...

This commit is contained in:
injoyai
2024-10-25 16:11:48 +08:00
parent a12b6cafe9
commit 9827688853
6 changed files with 42 additions and 16 deletions

View File

@@ -4,5 +4,8 @@
### 开发进度 ### 开发进度
#### 能通讯,有响应数据,还未解析响应数据 #### 开发进度
* 能通讯,有响应数据,还未解析响应数据
![](docs/plan.png) ![](docs/plan.png)
* 基本信息(5档报价)
![](docs/plan20241025.png)

View File

@@ -1,10 +1,8 @@
package protocol package protocol
import ( import (
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/injoyai/logs"
"strings" "strings"
) )
@@ -109,10 +107,10 @@ type SecurityQuote struct {
InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上) InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上)
OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上) OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上)
ReversedBytes2 int // 保留,未知 ReversedBytes2 int // 保留,未知
ReversedBytes3 int // 保留,未知 ReversedBytes3 int // 保留,未知
BuyLevel [5]PriceLevel // 5档买盘(买1-5) BuyLevel PriceLevels // 5档买盘(买1-5)
SellLevel [5]PriceLevel // 5档卖盘(卖1-5) SellLevel PriceLevels // 5档卖盘(卖1-5)
ReversedBytes4 uint16 // 保留,未知 ReversedBytes4 uint16 // 保留,未知
ReversedBytes5 int // 保留,未知 ReversedBytes5 int // 保留,未知
@@ -125,10 +123,16 @@ type SecurityQuote struct {
} }
func (this *SecurityQuote) String() string { func (this *SecurityQuote) String() string {
return this.K.String() + fmt.Sprintf(", 总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s", return fmt.Sprintf(`%s%s
IntUnitString(this.TotalHand), IntUnitString(this.Intuition), FloatUnitString(this.Amount), %s
IntUnitString(this.InsideDish), IntUnitString(this.OuterDisc)) + "\n" + 总量%s, 现量%s, 总金额%s, 内盘%s, 外盘%s
fmt.Sprintf("%#v\n", this) %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{} type securityQuote struct{}
@@ -180,7 +184,7 @@ c005bed2668e05be15804d8ba12cb3b13a0083c3034100badc029d014201bc990384f70443029da5
*/ */
func (this securityQuote) Decode(bs []byte) SecurityQuotesResp { func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
logs.Debug(hex.EncodeToString(bs)) //logs.Debug(hex.EncodeToString(bs))
resp := SecurityQuotesResp{} resp := SecurityQuotesResp{}
@@ -210,7 +214,7 @@ 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++ {
buyLevel := PriceLevel{} buyLevel := PriceLevel{Buy: true}
sellLevel := PriceLevel{} sellLevel := PriceLevel{}
bs, p = GetPrice(bs) bs, p = GetPrice(bs)

View File

@@ -13,16 +13,32 @@ func (this Price) Float64() float64 {
} }
func (this Price) String() string { func (this Price) String() string {
return fmt.Sprintf("%0.2f 元", this.Float64()) return fmt.Sprintf("%0.2f元", this.Float64())
} }
type PriceLevel struct { type PriceLevel struct {
Buy bool //买卖
Price Price //价 想买卖的价格 Price Price //价 想买卖的价格
Number int //量 想买卖的数量 Number int //量 想买卖的数量
} }
type PriceLevels [5]PriceLevel 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线图 // K k线图
type K struct { type K struct {
Last Price //昨天收盘价 Last Price //昨天收盘价
@@ -33,7 +49,7 @@ type K struct {
} }
func (this K) String() string { 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字节 // DecodeK 一般是占用6字节

View File

@@ -48,6 +48,9 @@ func FloatUnitString(f float64) string {
for i := 0; f > 1e4 && i < len(m); f /= 1e4 { for i := 0; f > 1e4 && i < len(m); f /= 1e4 {
unit = m[i] unit = m[i]
} }
if unit == "" {
return conv.String(f)
}
return fmt.Sprintf("%0.2f%s", f, unit) return fmt.Sprintf("%0.2f%s", f, unit)
} }