校对分时成交的金额,价格用int32有点不够,后续改成int64,单位分

This commit is contained in:
钱纯净
2024-10-30 23:07:55 +08:00
parent baecaf36dc
commit 5b22791bff
3 changed files with 17 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ import (
func main() {
common.Test(func(c *tdx.Client) {
resp, err := c.GetStockMinuteTradeAll(protocol.ExchangeSH, "000001")
resp, err := c.GetStockMinuteTrade(protocol.ExchangeSH, "000001", 0, 100)
logs.PanicErr(err)
for _, v := range resp.List {

View File

@@ -10,7 +10,7 @@ type StockMinuteTradeResp struct {
List []*StockMinuteTrade
}
// StockMinuteTrade 分时成交todo 时间没有到秒和没有金额
// StockMinuteTrade 分时成交todo 时间没有到秒,客户端上也没有
type StockMinuteTrade struct {
Time string //时间
Price Price //价格
@@ -20,7 +20,16 @@ type StockMinuteTrade struct {
}
func (this *StockMinuteTrade) String() string {
return fmt.Sprintf("%s \t%s \t%-6d(手) \t%-4d(单) \t%-4s", this.Time, this.Price, this.Volume, this.Number, this.StatusString())
return fmt.Sprintf("%s \t%s \t%-6s \t%-6d(手) \t%-4d(单) \t%-4s", this.Time, this.Price, FloatUnitString(float64(this.Amount2())/100), this.Volume, this.Number, this.StatusString())
}
// Amount 成交额
func (this *StockMinuteTrade) Amount() Price {
return this.Price * Price(this.Volume) * 100
}
func (this *StockMinuteTrade) Amount2() int64 {
return this.Price.Int64() * int64(this.Volume) * 100
}
func (this *StockMinuteTrade) StatusString() string {

View File

@@ -4,13 +4,17 @@ import (
"fmt"
)
// Price 价格,单位分
// Price 价格,单位分,分时成交的总金额可能会超出范围后续改成int64
type Price int32
func (this Price) Float64() float64 {
return float64(this) / 100
}
func (this Price) Int64() int64 {
return int64(this)
}
func (this Price) String() string {
return fmt.Sprintf("%0.2f元", this.Float64())
}