mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
优化指数数据的获取方式,从K线中拆出,方便解析
This commit is contained in:
@@ -25,7 +25,7 @@ func (this *HistoryMinuteTrade) String() string {
|
|||||||
|
|
||||||
// Amount 成交额
|
// Amount 成交额
|
||||||
func (this *HistoryMinuteTrade) Amount() Price {
|
func (this *HistoryMinuteTrade) Amount() Price {
|
||||||
return this.Price * Price(this.Volume) * 100
|
return this.Price * Price(this.Volume*100)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HistoryMinuteTrade) StatusString() string {
|
func (this *HistoryMinuteTrade) StatusString() string {
|
||||||
@@ -82,7 +82,7 @@ func (historyMinuteTrade) Decode(bs []byte, code string) (*HistoryMinuteTradeRes
|
|||||||
}
|
}
|
||||||
var sub Price
|
var sub Price
|
||||||
bs, sub = GetPrice(bs[2:])
|
bs, sub = GetPrice(bs[2:])
|
||||||
lastPrice += sub
|
lastPrice += sub * 10 //把分转成厘
|
||||||
mt.Price = lastPrice / basePrice(number)
|
mt.Price = lastPrice / basePrice(number)
|
||||||
bs, mt.Volume = CutInt(bs)
|
bs, mt.Volume = CutInt(bs)
|
||||||
bs, mt.Status = CutInt(bs)
|
bs, mt.Status = CutInt(bs)
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ type Kline struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Kline) String() string {
|
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.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(),
|
this.RisePrice(), this.RiseRate(),
|
||||||
Int64UnitString(this.Volume), FloatUnitString(this.Amount.Float64()),
|
Int64UnitString(this.Volume), FloatUnitString(this.Amount.Float64()),
|
||||||
this.UpCount, this.DownCount,
|
this.UpCount, this.DownCount,
|
||||||
@@ -133,11 +133,11 @@ func (kline) Decode(bs []byte, c KlineCache) (*KlineResp, error) {
|
|||||||
var low Price
|
var low Price
|
||||||
bs, low = GetPrice(bs)
|
bs, low = GetPrice(bs)
|
||||||
|
|
||||||
k.Last = last / 10
|
k.Last = last
|
||||||
k.Open = (open + last) / 10
|
k.Open = open + last
|
||||||
k.Close = (last + open + _close) / 10
|
k.Close = last + open + _close
|
||||||
k.High = (open + last + high) / 10
|
k.High = open + last + high
|
||||||
k.Low = (open + last + low) / 10
|
k.Low = open + last + low
|
||||||
last = last + open + _close
|
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:
|
case TypeKlineMinute, TypeKline5Minute, TypeKlineMinute2, TypeKline15Minute, TypeKline30Minute, TypeKlineHour, TypeKlineDay2:
|
||||||
k.Volume /= 100
|
k.Volume /= 100
|
||||||
}
|
}
|
||||||
k.Amount = Price(getVolume(Uint32(bs[:4])) * 100) //从元转为分,并去除多余的小数
|
k.Amount = Price(getVolume(Uint32(bs[:4])) * 1000) //从元转为厘,并去除多余的小数
|
||||||
bs = bs[4:]
|
bs = bs[4:]
|
||||||
|
|
||||||
|
switch c.Kind {
|
||||||
|
case KindIndex:
|
||||||
//指数和股票的差别,指数多解析4字节,并处理成交量*100
|
//指数和股票的差别,指数多解析4字节,并处理成交量*100
|
||||||
if !IsStock(c.Code) {
|
|
||||||
k.Volume *= 100
|
k.Volume *= 100
|
||||||
k.UpCount = conv.Int([]byte{bs[1], bs[0]})
|
k.UpCount = conv.Int([]byte{bs[1], bs[0]})
|
||||||
k.DownCount = conv.Int([]byte{bs[3], bs[2]})
|
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 KlineCache struct {
|
||||||
Type uint8
|
Type uint8 //1分钟,5分钟,日线等
|
||||||
Code string
|
Kind string //指数,个股等
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type MinuteTrade struct {
|
|||||||
Time string //时间
|
Time string //时间
|
||||||
Price Price //价格
|
Price Price //价格
|
||||||
Volume int //成交量
|
Volume int //成交量
|
||||||
Number int //单数,历史数据改字段无效
|
Number int //单数,历史数据该字段无效
|
||||||
Status int //0是买,1是卖,2无效(汇总出现)
|
Status int //0是买,1是卖,2无效(汇总出现)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ func (minuteTrade) Decode(bs []byte, code string) (*MinuteTradeResp, error) {
|
|||||||
}
|
}
|
||||||
var sub Price
|
var sub Price
|
||||||
bs, sub = GetPrice(bs[2:])
|
bs, sub = GetPrice(bs[2:])
|
||||||
lastPrice += sub
|
lastPrice += sub * 10 //把分转换成厘
|
||||||
mt.Price = lastPrice / basePrice(code)
|
mt.Price = lastPrice / basePrice(code)
|
||||||
bs, mt.Volume = CutInt(bs)
|
bs, mt.Volume = CutInt(bs)
|
||||||
bs, mt.Number = CutInt(bs)
|
bs, mt.Number = CutInt(bs)
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Price 价格,单位分,分时成交的总金额可能会超出范围,后续改成int64
|
// Price 价格,单位厘
|
||||||
type Price int64
|
type Price int64
|
||||||
|
|
||||||
func (this Price) Float64() float64 {
|
func (this Price) Float64() float64 {
|
||||||
return float64(this) / 100
|
return float64(this) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Price) Int64() int64 {
|
func (this Price) Int64() int64 {
|
||||||
@@ -17,7 +17,7 @@ func (this Price) Int64() int64 {
|
|||||||
|
|
||||||
func (this Price) String() string {
|
func (this Price) String() string {
|
||||||
return fmt.Sprintf("%s元", FloatUnitString(this.Float64()))
|
return fmt.Sprintf("%s元", FloatUnitString(this.Float64()))
|
||||||
return fmt.Sprintf("%0.2f元", this.Float64())
|
return fmt.Sprintf("%0.3f元", this.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
type PriceLevel struct {
|
type PriceLevel struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user