准备增加流通股总股本

This commit is contained in:
injoyai
2025-11-13 16:57:53 +08:00
parent 5fb1a212c6
commit ffe0cb2c92
12 changed files with 892 additions and 31 deletions

View File

@@ -15,6 +15,14 @@ import (
"xorm.io/xorm"
)
type ICodes interface {
Get(code string) *CodeModel
GetName(code string) string
GetStocks(limit ...int) []string
GetETFs(limit ...int) []string
Update() error
}
// DefaultCodes 增加单例,部分数据需要通过Codes里面的信息计算
var DefaultCodes *Codes
@@ -312,28 +320,35 @@ func (*UpdateModel) TableName() string {
}
type CodeModel struct {
ID int64 `json:"id"` //主键
Name string `json:"name"` //名称,有时候名称会变,例STxxx
Code string `json:"code" xorm:"index"` //代码
Exchange string `json:"exchange" xorm:"index"` //交易所
Multiple uint16 `json:"multiple"` //倍数
Decimal int8 `json:"decimal"` //小数位
LastPrice float64 `json:"lastPrice"` //昨收价格
EditDate int64 `json:"editDate" xorm:"updated"` //修改时间
InDate int64 `json:"inDate" xorm:"created"` //创建时间
ID int64 `json:"id"` //主键
Name string `json:"name"` //名称,有时候名称会变,例STxxx
Code string `json:"code" xorm:"index"` //代码
Exchange string `json:"exchange" xorm:"index"` //交易所
Multiple uint16 `json:"multiple"` //倍数
Decimal int8 `json:"decimal"` //小数位
LastPrice float64 `json:"lastPrice"` //昨收价格
FloatStock float64 `json:"floatStock"` //流通股
TotalStock float64 `json:"totalStock"` //总股本
EditDate int64 `json:"editDate" xorm:"updated"` //修改时间
InDate int64 `json:"inDate" xorm:"created"` //创建时间
}
func (*CodeModel) TableName() string {
return "codes"
}
// FullCode 获取完整代码 sz000001
func (this *CodeModel) FullCode() string {
return this.Exchange + this.Code
}
// Turnover 换手率
func (this *CodeModel) Turnover(volume float64) float64 {
return volume / (this.FloatStock * 100)
}
func (this *CodeModel) Price(p protocol.Price) protocol.Price {
return protocol.Price(float64(p) * math.Pow10(int(2-this.Decimal)))
//return p * protocol.Price(math.Pow10(int(2-this.Decimal)))
}
func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error {