mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
增加了Last字段,是昨日收盘价,东方财富的涨幅都是根据昨日收盘价(和今日开盘价不一定一致)来计算的,但是协议没有返回昨日收盘价,是通过获取列表,然后取上一条数据的收盘价来赋值,所以列表第一条数据无法获取昨日收盘价
This commit is contained in:
@@ -37,6 +37,7 @@ type StockKlineResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StockKline struct {
|
type StockKline struct {
|
||||||
|
Last Price //昨日收盘价,这个是列表的上一条数据的收盘价,如果没有上条数据,那么这个值为0
|
||||||
Open Price //开盘价
|
Open Price //开盘价
|
||||||
High Price //最高价
|
High Price //最高价
|
||||||
Low Price //最低价
|
Low Price //最低价
|
||||||
@@ -47,13 +48,34 @@ type StockKline struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *StockKline) String() string {
|
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.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),
|
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{}
|
type stockKline struct{}
|
||||||
|
|
||||||
func (stockKline) Frame(Type TypeKline, req *StockKlineReq) (*Frame, error) {
|
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:]
|
bs = bs[2:]
|
||||||
|
|
||||||
var last Price
|
var last Price //上条数据(昨天)的收盘价
|
||||||
for i := uint16(0); i < resp.Count; i++ {
|
for i := uint16(0); i < resp.Count; i++ {
|
||||||
k := &StockKline{
|
k := &StockKline{
|
||||||
Time: GetTime([4]byte(bs[:4]), Type),
|
Time: GetTime([4]byte(bs[:4]), Type),
|
||||||
@@ -95,11 +117,11 @@ func (stockKline) Decode(bs []byte, Type TypeKline) (*StockKlineResp, error) {
|
|||||||
var low Price
|
var low Price
|
||||||
bs, low = GetPrice(bs)
|
bs, low = GetPrice(bs)
|
||||||
|
|
||||||
|
k.Last = last / 10
|
||||||
k.Open = (open + 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.High = (open + last + high) / 10
|
||||||
k.Low = (open + last + low) / 10
|
k.Low = (open + last + low) / 10
|
||||||
|
|
||||||
last = last + open + _close
|
last = last + open + _close
|
||||||
|
|
||||||
k.Volume = getVolume(Uint32(bs[:4]))
|
k.Volume = getVolume(Uint32(bs[:4]))
|
||||||
|
|||||||
Reference in New Issue
Block a user