fix bug
This commit is contained in:
14
cmd/test/main.go
Normal file
14
cmd/test/main.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
t, err := time.Parse("20060102", "20230101")
|
||||
if err != nil {
|
||||
fmt.Println("error", err)
|
||||
}
|
||||
fmt.Println(t)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package a
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/dataset/stock/internal/impl"
|
||||
@@ -14,8 +15,8 @@ func GetStockDaily() {
|
||||
var start string = "20230101"
|
||||
var last models.StockDaily
|
||||
err := impl.DBService.Where("ts_code=?", code).Order("trade_date DESC").First(&last).Error
|
||||
if err == nil && last.TradeDate != "" {
|
||||
start = last.TradeDate
|
||||
if err == nil {
|
||||
start = last.TradeDate.Format("20060102")
|
||||
}
|
||||
params := map[string]string{
|
||||
"ts_code": code,
|
||||
@@ -37,10 +38,16 @@ func GetStockDaily() {
|
||||
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
|
||||
}
|
||||
|
||||
impl.DBService.Create(&models.StockDaily{
|
||||
TsCode: item[0].(string),
|
||||
TradeDate: item[1].(string),
|
||||
TradeDate: t,
|
||||
Open: item[2].(float64),
|
||||
High: item[3].(float64),
|
||||
Low: item[4].(float64),
|
||||
|
||||
@@ -2,6 +2,7 @@ package a
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -15,8 +16,8 @@ func GetStockIndicator() {
|
||||
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 && last.TradeDate != "" {
|
||||
start = last.TradeDate
|
||||
if err == nil {
|
||||
start = last.TradeDate.Format("20060102")
|
||||
}
|
||||
params := map[string]string{
|
||||
"ts_code": code,
|
||||
@@ -31,17 +32,22 @@ func GetStockIndicator() {
|
||||
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)
|
||||
log.Println("ERROR", "GetStockIndicator", err, "PARAMS", params)
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range reply.Data.Items {
|
||||
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)
|
||||
if cnt == 0 {
|
||||
t, err := time.Parse("20060102", item[1].(string))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
impl.DBService.Create(&models.StockIndicator{
|
||||
TsCode: item[0].(string),
|
||||
TradeDate: item[1].(string),
|
||||
TradeDate: t,
|
||||
Close: Any2Float(item[2]),
|
||||
TurnoverRate: Any2Float(item[3]),
|
||||
TurnoverRateF: Any2Float(item[4]),
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
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 string `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 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"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
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 string `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: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:流通市值(万元)"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user