fix bug
This commit is contained in:
@@ -1,16 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/dataset/stock/internal/config"
|
||||
"git.apinb.com/dataset/stock/internal/impl"
|
||||
"git.apinb.com/dataset/stock/internal/logic/a"
|
||||
"git.apinb.com/dataset/stock/internal/models"
|
||||
)
|
||||
|
||||
var (
|
||||
ServiceKey = "stock"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 配置初始化
|
||||
config.New(ServiceKey)
|
||||
|
||||
// 创建实现层
|
||||
impl.NewImpl()
|
||||
|
||||
a.NewApiClient()
|
||||
reply, err := a.SetFinaIndicator("000029.SZ", "20230331")
|
||||
fmt.Println("Err", err)
|
||||
jsonBytes, _ := json.Marshal(reply.Data.Items)
|
||||
fmt.Println("Reply", string(jsonBytes))
|
||||
code := "002463.SZ"
|
||||
end := time.Now().Format("20060102")
|
||||
|
||||
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 {
|
||||
start = utils.Int2String(last.TradeDate)
|
||||
}
|
||||
params := map[string]string{
|
||||
"ts_code": code,
|
||||
"start_date": start,
|
||||
"end_date": end,
|
||||
}
|
||||
|
||||
fields := []string{}
|
||||
reply, err := a.TushareClient.Daily(params, fields)
|
||||
if err != nil {
|
||||
log.Println("ERROR", "GetStockDaily", err)
|
||||
return
|
||||
}
|
||||
|
||||
records := make([]*models.StockDaily, 0)
|
||||
for _, item := range reply.Data.Items {
|
||||
t := utils.String2Int(item[1].(string))
|
||||
if t == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
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),
|
||||
High: item[3].(float64),
|
||||
Low: item[4].(float64),
|
||||
Close: item[5].(float64),
|
||||
PreClose: item[6].(float64),
|
||||
Change: item[7].(float64),
|
||||
PctChg: item[8].(float64),
|
||||
Vol: item[9].(float64),
|
||||
Amount: item[10].(float64),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(records) > 0 {
|
||||
impl.DBService.CreateInBatches(records, 100)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ func GetStockDaily() {
|
||||
"end_date": end,
|
||||
}
|
||||
|
||||
log.Println("GetStockDaily", code, start, end)
|
||||
if start == end {
|
||||
continue
|
||||
}
|
||||
|
||||
fields := []string{}
|
||||
reply, err := TushareClient.Daily(params, fields)
|
||||
if err != nil {
|
||||
@@ -62,7 +62,7 @@ func GetStockDaily() {
|
||||
}
|
||||
|
||||
if len(records) > 0 {
|
||||
impl.DBService.CreateInBatches(records, 100)
|
||||
impl.DBService.CreateInBatches(records, 50)
|
||||
}
|
||||
|
||||
time.Sleep(200 * time.Microsecond)
|
||||
|
||||
@@ -580,7 +580,7 @@ func UpdateFinaIndicator(code, period string, item map[string]any) {
|
||||
upd["q_netprofit_margin"] = Any2Float(item["q_netprofit_margin"])
|
||||
}
|
||||
if old.QGscaleprofitMargin != Any2Float(item["q_gsprofit_margin"]) {
|
||||
upd["q_gsprofit_margin"] = Any2Float(item["q_gsprofit_margin"])
|
||||
upd["q_gscaleprofit_margin"] = Any2Float(item["q_gsprofit_margin"])
|
||||
}
|
||||
if old.QExpToSales != Any2Float(item["q_exp_to_sales"]) {
|
||||
upd["q_exp_to_sales"] = Any2Float(item["q_exp_to_sales"])
|
||||
|
||||
Reference in New Issue
Block a user