From 66781b07c2f3fad3cbdc00e36d7aaf1580b82155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Sat, 15 Mar 2025 15:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8C=87=E6=95=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F,?= =?UTF-8?q?=E4=BB=8EK=E7=BA=BF=E4=B8=AD=E6=8B=86=E5=87=BA,=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/model_history_minute_trade.go | 4 ++-- protocol/model_kline.go | 25 +++++++++++++------------ protocol/model_minute_trade.go | 4 ++-- protocol/types_price.go | 6 +++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/protocol/model_history_minute_trade.go b/protocol/model_history_minute_trade.go index 049728d..5c9d6e9 100644 --- a/protocol/model_history_minute_trade.go +++ b/protocol/model_history_minute_trade.go @@ -25,7 +25,7 @@ func (this *HistoryMinuteTrade) String() string { // Amount 成交额 func (this *HistoryMinuteTrade) Amount() Price { - return this.Price * Price(this.Volume) * 100 + return this.Price * Price(this.Volume*100) } func (this *HistoryMinuteTrade) StatusString() string { @@ -82,7 +82,7 @@ func (historyMinuteTrade) Decode(bs []byte, code string) (*HistoryMinuteTradeRes } var sub Price bs, sub = GetPrice(bs[2:]) - lastPrice += sub + lastPrice += sub * 10 //把分转成厘 mt.Price = lastPrice / basePrice(number) bs, mt.Volume = CutInt(bs) bs, mt.Status = CutInt(bs) diff --git a/protocol/model_kline.go b/protocol/model_kline.go index 15f7afa..258b71e 100644 --- a/protocol/model_kline.go +++ b/protocol/model_kline.go @@ -51,9 +51,9 @@ type Kline struct { } func (this *Kline) String() string { - return fmt.Sprintf("%s 昨收盘:%s 开盘价:%s 最高价:%s 最低价:%s 收盘价:%s 涨跌:%s 涨跌幅:%0.2f 成交量:%s 成交额:%s 涨跌数: %d/%d", + return fmt.Sprintf("%s 昨收盘:%.3f 开盘价:%.3f 最高价:%.3f 最低价:%.3f 收盘价:%.3f 涨跌:%s 涨跌幅:%0.2f 成交量:%s 成交额:%s 涨跌数: %d/%d", this.Time.Format("2006-01-02 15:04:05"), - this.Last, this.Open, this.High, this.Low, this.Close, + this.Last.Float64(), this.Open.Float64(), this.High.Float64(), this.Low.Float64(), this.Close.Float64(), this.RisePrice(), this.RiseRate(), Int64UnitString(this.Volume), FloatUnitString(this.Amount.Float64()), this.UpCount, this.DownCount, @@ -133,11 +133,11 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) { var low Price bs, low = GetPrice(bs) - k.Last = last / 10 - k.Open = (open + last) / 10 - k.Close = (last + open + _close) / 10 - k.High = (open + last + high) / 10 - k.Low = (open + last + low) / 10 + k.Last = last + k.Open = open + last + k.Close = last + open + _close + k.High = open + last + high + k.Low = open + last + low last = last + open + _close /* @@ -160,11 +160,12 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) { case TypeKlineMinute, TypeKline5Minute, TypeKlineMinute2, TypeKline15Minute, TypeKline30Minute, TypeKlineHour, TypeKlineDay2: k.Volume /= 100 } - k.Amount = Price(getVolume(Uint32(bs[:4])) * 100) //从元转为分,并去除多余的小数 + k.Amount = Price(getVolume(Uint32(bs[:4])) * 1000) //从元转为厘,并去除多余的小数 bs = bs[4:] - //指数和股票的差别,指数多解析4字节,并处理成交量*100 - if !IsStock(c.Code) { + switch c.Kind { + case KindIndex: + //指数和股票的差别,指数多解析4字节,并处理成交量*100 k.Volume *= 100 k.UpCount = conv.Int([]byte{bs[1], bs[0]}) k.DownCount = conv.Int([]byte{bs[3], bs[2]}) @@ -178,6 +179,6 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) { } type KlineCache struct { - Type uint8 - Code string + Type uint8 //1分钟,5分钟,日线等 + Kind string //指数,个股等 } diff --git a/protocol/model_minute_trade.go b/protocol/model_minute_trade.go index 1b7c65a..002c4b3 100644 --- a/protocol/model_minute_trade.go +++ b/protocol/model_minute_trade.go @@ -15,7 +15,7 @@ type MinuteTrade struct { Time string //时间 Price Price //价格 Volume int //成交量 - Number int //单数,历史数据改字段无效 + Number int //单数,历史数据该字段无效 Status int //0是买,1是卖,2无效(汇总出现) } @@ -103,7 +103,7 @@ func (minuteTrade) Decode(bs []byte, code string) (*MinuteTradeResp, error) { } var sub Price bs, sub = GetPrice(bs[2:]) - lastPrice += sub + lastPrice += sub * 10 //把分转换成厘 mt.Price = lastPrice / basePrice(code) bs, mt.Volume = CutInt(bs) bs, mt.Number = CutInt(bs) diff --git a/protocol/types_price.go b/protocol/types_price.go index 3c8e784..83dce2a 100644 --- a/protocol/types_price.go +++ b/protocol/types_price.go @@ -4,11 +4,11 @@ import ( "fmt" ) -// Price 价格,单位分,分时成交的总金额可能会超出范围,后续改成int64 +// Price 价格,单位厘 type Price int64 func (this Price) Float64() float64 { - return float64(this) / 100 + return float64(this) / 1000 } func (this Price) Int64() int64 { @@ -17,7 +17,7 @@ func (this Price) Int64() int64 { func (this Price) String() string { return fmt.Sprintf("%s元", FloatUnitString(this.Float64())) - return fmt.Sprintf("%0.2f元", this.Float64()) + return fmt.Sprintf("%0.3f元", this.Float64()) } type PriceLevel struct {