Initial commit
This commit is contained in:
78
internal/logic/a/indicator.go
Normal file
78
internal/logic/a/indicator.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package a
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/dataset/stock/internal/impl"
|
||||
"git.apinb.com/dataset/stock/internal/models"
|
||||
)
|
||||
|
||||
func GetStockIndicator() {
|
||||
end := time.Now().Format("20060102")
|
||||
for _, code := range GetStockCodes() {
|
||||
var start string = "20230101"
|
||||
var last models.StockIndicator
|
||||
err := impl.DBService.Where("ts_code=?", code).Order("trade_date DESC").First(&last).Error
|
||||
if err == nil {
|
||||
start = utils.Int2String(last.TradeDate)
|
||||
}
|
||||
params := map[string]string{
|
||||
"ts_code": code,
|
||||
"start_date": start,
|
||||
"end_date": end,
|
||||
}
|
||||
|
||||
if start == end {
|
||||
continue
|
||||
}
|
||||
|
||||
fields := strings.Split("ts_code,trade_date,close,turnover_rate,turnover_rate_f,volume_ratio,pe,pe_ttm,pb,ps,ps_ttm,dv_ratio,dv_ttm,total_share,float_share,free_share,total_mv,circ_mv", ",")
|
||||
reply, err := TushareClient.DailyBasic(params, fields)
|
||||
if err != nil {
|
||||
log.Println("ERROR", "GetStockIndicator", err, "PARAMS", params)
|
||||
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), t).Count(&cnt)
|
||||
if cnt == 0 {
|
||||
records = append(records, &models.StockIndicator{
|
||||
TsCode: item[0].(string),
|
||||
TradeDate: t,
|
||||
Close: Any2Float(item[2]),
|
||||
TurnoverRate: Any2Float(item[3]),
|
||||
TurnoverRateF: Any2Float(item[4]),
|
||||
VolumeRatio: Any2Float(item[5]),
|
||||
Pe: Any2Float(item[6]),
|
||||
PeTtm: Any2Float(item[7]),
|
||||
Pb: Any2Float(item[8]),
|
||||
Ps: Any2Float(item[9]),
|
||||
PsTtm: Any2Float(item[10]),
|
||||
DvRatio: Any2Float(item[11]),
|
||||
DvTtm: Any2Float(item[12]),
|
||||
TotalShare: Any2Float(item[13]),
|
||||
FloatShare: Any2Float(item[14]),
|
||||
FreeShare: Any2Float(item[15]),
|
||||
TotalMv: Any2Float(item[16]),
|
||||
CircMv: Any2Float(item[17]),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(records) > 0 {
|
||||
impl.DBService.CreateInBatches(records, 100)
|
||||
}
|
||||
|
||||
time.Sleep(200 * time.Microsecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user