This commit is contained in:
yanweidong
2026-01-21 19:08:44 +08:00
parent c589839e12
commit 1ebe7ac8ab
7 changed files with 78 additions and 65 deletions

View File

@@ -4,7 +4,7 @@ import "git.apinb.com/dataset/stock/internal/logic/a"
func Boot() {
a.NewApiClient()
a.GetStockBasic()
a.GetStockDaily()
a.GetStockIndicator()
//a.GetStockBasic()
//a.GetStockDaily()
//a.GetStockIndicator()
}

View File

@@ -2,9 +2,9 @@ package a
import (
"log"
"os"
"time"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/dataset/stock/internal/impl"
"git.apinb.com/dataset/stock/internal/models"
)
@@ -16,7 +16,7 @@ func GetStockDaily() {
var last models.StockDaily
err := impl.DBService.Where("ts_code=?", code).Order("trade_date DESC").First(&last).Error
if err == nil {
start = last.TradeDate.Format("20060102")
start = utils.Int2String(last.TradeDate)
}
params := map[string]string{
"ts_code": code,
@@ -35,17 +35,17 @@ func GetStockDaily() {
return
}
records := make([]*models.StockDaily, 0)
for _, item := range reply.Data.Items {
var cnt int64
impl.DBService.Model(&models.StockDaily{}).Where("ts_code=? and trade_date=?", item[0].(string), item[1].(string)).Count(&cnt)
os.Exit(1)
if cnt == 0 {
t, err := time.Parse("20060102", item[1].(string))
if err != nil {
continue
}
t := utils.String2Int(item[1].(string))
if t == 0 {
continue
}
impl.DBService.Create(&models.StockDaily{
var cnt int64
impl.DBService.Model(&models.StockDaily{}).Where("ts_code=? and trade_date=?", item[0].(string), t).Count(&cnt)
if cnt == 0 {
records = append(records, &models.StockDaily{
TsCode: item[0].(string),
TradeDate: t,
Open: item[2].(float64),
@@ -61,6 +61,10 @@ func GetStockDaily() {
}
}
if len(records) > 0 {
impl.DBService.CreateInBatches(records, 100)
}
time.Sleep(200 * time.Microsecond)
}

View File

@@ -5,6 +5,7 @@ import (
"strings"
"time"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/dataset/stock/internal/impl"
"git.apinb.com/dataset/stock/internal/models"
)
@@ -15,8 +16,8 @@ func GetFinaIndicator() {
var start string = "20230101"
var last models.StockFinaIndicator
err := impl.DBService.Where("ts_code=?", code).Order("ann_date DESC").First(&last).Error
if err == nil && last.AnnDate != "" {
start = last.AnnDate
if err == nil {
start = utils.Int2String(last.AnnDate)
}
params := map[string]string{
"ts_code": code,
@@ -36,12 +37,17 @@ func GetFinaIndicator() {
}
for _, item := range reply.Data.Items {
t := utils.String2Int(item[1].(string))
if t == 0 {
continue
}
var cnt int64
impl.DBService.Model(&models.StockFinaIndicator{}).Where("ts_code=? and AnnDate=?", item[0].(string), item[1].(string)).Count(&cnt)
impl.DBService.Model(&models.StockFinaIndicator{}).Where("ts_code=? and AnnDate=?", item[0].(string), t).Count(&cnt)
if cnt == 0 {
impl.DBService.Create(&models.StockFinaIndicator{
TsCode: item[0].(string),
AnnDate: item[1].(string),
AnnDate: t,
})
}
}

View File

@@ -2,10 +2,10 @@ package a
import (
"log"
"os"
"strings"
"time"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/dataset/stock/internal/impl"
"git.apinb.com/dataset/stock/internal/models"
)
@@ -17,7 +17,7 @@ func GetStockIndicator() {
var last models.StockIndicator
err := impl.DBService.Where("ts_code=?", code).Order("trade_date DESC").First(&last).Error
if err == nil {
start = last.TradeDate.Format("20060102")
start = utils.Int2String(last.TradeDate)
}
params := map[string]string{
"ts_code": code,
@@ -36,16 +36,17 @@ func GetStockIndicator() {
return
}
records := make([]*models.StockIndicator, 0)
for _, item := range reply.Data.Items {
t := utils.String2Int(item[1].(string))
if t == 0 {
continue
}
var cnt int64
impl.DBService.Model(&models.StockIndicator{}).Where("ts_code=? and trade_date=?", item[0].(string), item[1].(string)).Count(&cnt)
os.Exit(1)
impl.DBService.Model(&models.StockIndicator{}).Where("ts_code=? and trade_date=?", item[0].(string), t).Count(&cnt)
if cnt == 0 {
t, err := time.Parse("20060102", item[1].(string))
if err != nil {
continue
}
impl.DBService.Create(&models.StockIndicator{
records = append(records, &models.StockIndicator{
TsCode: item[0].(string),
TradeDate: t,
Close: Any2Float(item[2]),
@@ -67,5 +68,11 @@ func GetStockIndicator() {
})
}
}
if len(records) > 0 {
impl.DBService.CreateInBatches(records, 100)
}
time.Sleep(200 * time.Microsecond)
}
}

View File

@@ -1,25 +1,23 @@
package models
import (
"time"
"git.apinb.com/bsm-sdk/core/database"
)
// LastDaily 股票日线数据
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 time.Time `gorm:"type:date;not null;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"`
Vol float64 `gorm:"type:decimal(15,2);comment:成交量(手)" json:"vol"`
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
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"`
Vol float64 `gorm:"type:decimal(15,2);comment:成交量(手)" json:"vol"`
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
}
func init() {

View File

@@ -8,9 +8,9 @@ import (
// StockFinaIndicator 财务指标模型
type StockFinaIndicator struct {
gorm.Model
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;comment:TS代码"`
AnnDate string `gorm:"type:date;not null;index:idx_ann_date;comment:公告日期"`
EndDate string `gorm:"type:date;not null;index:idx_end_date;comment:报告期"`
TsCode string `gorm:"type:varchar(20);not null;index:fi_ts_code;comment:TS代码"`
AnnDate int `gorm:"index:idx_ann_date;comment:公告日期"`
EndDate string `gorm:"index:idx_end_date;comment:报告期"`
// 每股指标
Eps float64 `gorm:"type:decimal(20,4);comment:基本每股收益"`

View File

@@ -1,32 +1,30 @@
package models
import (
"time"
"git.apinb.com/bsm-sdk/core/database"
)
// StockIndicator 股票日线数据模型
type StockIndicator struct {
ID uint `gorm:"primarykey;autoIncrement"`
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"`
TradeDate time.Time `gorm:"type:date;not null;index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
Close float64 `gorm:"type:decimal(10,4);comment:当日收盘价"`
TurnoverRate float64 `gorm:"type:decimal(10,6);comment:换手率(%)"`
TurnoverRateF float64 `gorm:"type:decimal(10,6);comment:换手率(自由流通股)"`
VolumeRatio float64 `gorm:"type:decimal(10,4);comment:量比"`
Pe float64 `gorm:"type:decimal(10,4);comment:市盈率(总市值/净利润)"`
PeTtm float64 `gorm:"type:decimal(10,4);comment:市盈率(TTM)"`
Pb float64 `gorm:"type:decimal(10,4);comment:市净率"`
Ps float64 `gorm:"type:decimal(10,4);comment:市销率"`
PsTtm float64 `gorm:"type:decimal(10,4);comment:市销率(TTM)"`
DvRatio float64 `gorm:"type:decimal(10,6);comment:股息率(%)"`
DvTtm float64 `gorm:"type:decimal(10,6);comment:股息率(TTM)(%)"`
TotalShare float64 `gorm:"type:decimal(15,2);comment:总股本(万股)"`
FloatShare float64 `gorm:"type:decimal(15,2);comment:流通股本(万股)"`
FreeShare float64 `gorm:"type:decimal(15,2);comment:自由流通股本(万)"`
TotalMv float64 `gorm:"type:decimal(15,2);comment:总市值(万元)"`
CircMv float64 `gorm:"type:decimal(15,2);comment:流通市值(万元)"`
ID uint `gorm:"primarykey;autoIncrement"`
TsCode string `gorm:"type:varchar(20);not null;index:si_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"`
TradeDate int `gorm:"index:si_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
Close float64 `gorm:"type:decimal(10,4);comment:当日收盘价"`
TurnoverRate float64 `gorm:"type:decimal(10,6);comment:换手率(%)"`
TurnoverRateF float64 `gorm:"type:decimal(10,6);comment:换手率(自由流通股)"`
VolumeRatio float64 `gorm:"type:decimal(10,4);comment:量比"`
Pe float64 `gorm:"type:decimal(10,4);comment:市盈率(总市值/净利润)"`
PeTtm float64 `gorm:"type:decimal(10,4);comment:市盈率(TTM)"`
Pb float64 `gorm:"type:decimal(10,4);comment:市净率"`
Ps float64 `gorm:"type:decimal(10,4);comment:市销率"`
PsTtm float64 `gorm:"type:decimal(10,4);comment:市销率(TTM)"`
DvRatio float64 `gorm:"type:decimal(10,6);comment:股息率(%)"`
DvTtm float64 `gorm:"type:decimal(10,6);comment:股息率(TTM)(%)"`
TotalShare float64 `gorm:"type:decimal(15,2);comment:总股本(万股)"`
FloatShare float64 `gorm:"type:decimal(15,2);comment:流通股本(万股)"`
FreeShare float64 `gorm:"type:decimal(15,2);comment:自由流通股本(万)"`
TotalMv float64 `gorm:"type:decimal(15,2);comment:总市值(万元)"`
CircMv float64 `gorm:"type:decimal(15,2);comment:流通市值(万元)"`
}
func init() {