From 4b091bf3ff10d81e7621474457eaee51e3ad6dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Wed, 30 Oct 2024 21:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86Last=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E6=98=AF=E6=98=A8=E6=97=A5=E6=94=B6=E7=9B=98?= =?UTF-8?q?=E4=BB=B7=EF=BC=8C=E4=B8=9C=E6=96=B9=E8=B4=A2=E5=AF=8C=E7=9A=84?= =?UTF-8?q?=E6=B6=A8=E5=B9=85=E9=83=BD=E6=98=AF=E6=A0=B9=E6=8D=AE=E6=98=A8?= =?UTF-8?q?=E6=97=A5=E6=94=B6=E7=9B=98=E4=BB=B7=EF=BC=88=E5=92=8C=E4=BB=8A?= =?UTF-8?q?=E6=97=A5=E5=BC=80=E7=9B=98=E4=BB=B7=E4=B8=8D=E4=B8=80=E5=AE=9A?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=89=E6=9D=A5=E8=AE=A1=E7=AE=97=E7=9A=84?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E5=8D=8F=E8=AE=AE=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=98=A8=E6=97=A5=E6=94=B6=E7=9B=98=E4=BB=B7?= =?UTF-8?q?=EF=BC=8C=E6=98=AF=E9=80=9A=E8=BF=87=E8=8E=B7=E5=8F=96=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E7=84=B6=E5=90=8E=E5=8F=96=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E6=9D=A1=E6=95=B0=E6=8D=AE=E7=9A=84=E6=94=B6=E7=9B=98=E4=BB=B7?= =?UTF-8?q?=E6=9D=A5=E8=B5=8B=E5=80=BC=EF=BC=8C=E6=89=80=E4=BB=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=AC=AC=E4=B8=80=E6=9D=A1=E6=95=B0=E6=8D=AE=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E6=98=A8=E6=97=A5=E6=94=B6=E7=9B=98?= =?UTF-8?q?=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/model_stock_kline.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/protocol/model_stock_kline.go b/protocol/model_stock_kline.go index 32b0c38..1f9c0dc 100644 --- a/protocol/model_stock_kline.go +++ b/protocol/model_stock_kline.go @@ -37,6 +37,7 @@ type StockKlineResp struct { } type StockKline struct { + Last Price //昨日收盘价,这个是列表的上一条数据的收盘价,如果没有上条数据,那么这个值为0 Open Price //开盘价 High Price //最高价 Low Price //最低价 @@ -47,13 +48,34 @@ type StockKline struct { } func (this *StockKline) String() string { - return fmt.Sprintf("%s 开盘价:%s 最高价:%s 最低价:%s 收盘价:%s 成交量:%s 成交额:%s", + return fmt.Sprintf("%s 昨收盘:%s 开盘价:%s 最高价:%s 最低价:%s 收盘价:%s 涨跌:%s 涨跌幅:%0.2f 成交量:%s 成交额:%s", this.Time.Format("2006-01-02 15:04:05"), - this.Open, this.High, this.Low, this.Close, + this.Last, this.Open, this.High, this.Low, this.Close, + this.RisePrice(), this.RiseRate(), FloatUnitString(this.Volume), FloatUnitString(this.Amount), ) } +// MaxDifference 最大差值,最高-最低 +func (this *StockKline) MaxDifference() Price { + return this.High - this.Low +} + +// RisePrice 涨跌金额,第一个数据不准,仅做参考 +func (this *StockKline) RisePrice() Price { + if this.Last == 0 { + //稍微数据准确点,没减去0这么夸张,还是不准的 + return this.Close - this.Open + } + return this.Close - this.Last + +} + +// RiseRate 涨跌比例/涨跌幅,第一个数据不准,仅做参考 +func (this *StockKline) RiseRate() float64 { + return float64(this.RisePrice()) / float64(this.Open) * 100 +} + type stockKline struct{} func (stockKline) Frame(Type TypeKline, req *StockKlineReq) (*Frame, error) { @@ -80,7 +102,7 @@ func (stockKline) Decode(bs []byte, Type TypeKline) (*StockKlineResp, error) { bs = bs[2:] - var last Price + var last Price //上条数据(昨天)的收盘价 for i := uint16(0); i < resp.Count; i++ { k := &StockKline{ Time: GetTime([4]byte(bs[:4]), Type), @@ -95,11 +117,11 @@ func (stockKline) Decode(bs []byte, Type TypeKline) (*StockKlineResp, error) { var low Price bs, low = GetPrice(bs) + k.Last = last / 10 k.Open = (open + last) / 10 - k.Close = (open + last + _close) / 10 + k.Close = (last + open + _close) / 10 k.High = (open + last + high) / 10 k.Low = (open + last + low) / 10 - last = last + open + _close k.Volume = getVolume(Uint32(bs[:4]))