ok
This commit is contained in:
58
schema/stock_daily.go
Normal file
58
schema/stock_daily.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package schema
|
||||
|
||||
import "strconv"
|
||||
|
||||
// StockDaily 股票日线数据(两仓库结构一致)。
|
||||
type StockDaily struct {
|
||||
ID uint `gorm:"primarykey;autoIncrement" json:"id"`
|
||||
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"`
|
||||
TradeDate int `gorm:"index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
|
||||
Open float64 `gorm:"type:decimal(10,4);comment:开盘价" json:"open"`
|
||||
High float64 `gorm:"type:decimal(10,4);comment:最高价" json:"high"`
|
||||
Low float64 `gorm:"type:decimal(10,4);comment:最低价" json:"low"`
|
||||
Close float64 `gorm:"type:decimal(10,4);comment:收盘价" json:"close"`
|
||||
PreClose float64 `gorm:"type:decimal(10,4);comment:昨收价(除权价)" json:"pre_close"`
|
||||
Change float64 `gorm:"type:decimal(10,4);comment:涨跌额" json:"change"`
|
||||
PctChg float64 `gorm:"type:decimal(10,6);comment:涨跌幅(%)" json:"pct_chg"`
|
||||
DayChg float64 `gorm:"type:decimal(6,2);comment:日均振幅(%)" json:"day_chg"`
|
||||
Vol float64 `gorm:"type:decimal(15,2);comment:成交量(手)" json:"vol"`
|
||||
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
|
||||
}
|
||||
|
||||
func (StockDaily) TableName() string {
|
||||
return "stock_daily"
|
||||
}
|
||||
|
||||
// Key 业务主键:ts_code + 交易日。
|
||||
func (d *StockDaily) Key() string {
|
||||
if d.TsCode == "" && d.TradeDate == 0 {
|
||||
return ""
|
||||
}
|
||||
return d.TsCode + "#" + strconv.Itoa(d.TradeDate)
|
||||
}
|
||||
|
||||
// IsRising 是否收涨(昨收有效且收盘高于昨收)。
|
||||
func (d *StockDaily) IsRising() bool {
|
||||
return d.PreClose > 0 && d.Close > d.PreClose
|
||||
}
|
||||
|
||||
// IsFalling 是否收跌。
|
||||
func (d *StockDaily) IsFalling() bool {
|
||||
return d.PreClose > 0 && d.Close < d.PreClose
|
||||
}
|
||||
|
||||
// PctChangeFromPre 由昨收计算的涨跌幅(%);昨收无效时返回 0。
|
||||
func (d *StockDaily) PctChangeFromPre() float64 {
|
||||
if d.PreClose <= 0 {
|
||||
return 0
|
||||
}
|
||||
return (d.Close - d.PreClose) / d.PreClose * 100
|
||||
}
|
||||
|
||||
// AmplitudePct 振幅(相对昨收,%):(最高-最低)/昨收*100。
|
||||
func (d *StockDaily) AmplitudePct() float64 {
|
||||
if d.PreClose <= 0 {
|
||||
return 0
|
||||
}
|
||||
return (d.High - d.Low) / d.PreClose * 100
|
||||
}
|
||||
Reference in New Issue
Block a user