ソースを参照

Merge branch 'hotfix/trade_anaylsis_start_date' of eta_server/eta_task into master

xyxie 1 週間 前
コミット
f924c87603

+ 8 - 0
models/data_manage/trade_position_analysis.go

@@ -412,3 +412,11 @@ func GetFirstBaseFromTradeIndexByDate(exchange string) (item *GetFirstBaseFromTr
 	err = o.Raw(sql).QueryRow(&item)
 	return
 }
+
+// 获取持仓分析的最新数据
+func GetTradePositionTopLastedDataTime(exchange string) (data_time time.Time, err error) {
+	o := orm.NewOrm()
+	sql := "SELECT max(data_time) FROM trade_position_" + exchange + "_top"
+	err = o.Raw(sql).QueryRow(&data_time)
+	return
+}

+ 15 - 5
services/data/trade_position_analysis.go

@@ -14,11 +14,21 @@ import (
 // InitPositionTask 统计今日交易所的持仓分析数据
 func InitPositionTask(cont context.Context) (err error) {
 	exchanges := []string{"zhengzhou", "dalian", "shanghai", "cffex", "ine", "guangzhou"} //郑商所,大商所,上期所,中金所,上期能源,广期所
-	for i := 2; i >= 0; i-- {
-		startDate := time.Now().AddDate(0, 0, -i).Format(utils.FormatDate)
-		endDate := startDate
-		for _, v := range exchanges {
-			exchange := v
+	for _, v := range exchanges {
+		exchange := v
+		startDateT, e := data_manage.GetTradePositionTopLastedDataTime(exchange)
+		if e != nil {
+			fmt.Println("InitPositionTask:	获取最后一条数据失败:" + e.Error())
+			utils.FileLog.Info("InitPositionTask:	获取最后一条数据失败:" + e.Error())
+			continue
+		}
+		// 从最新数据的两天开始更新
+		startDateT = startDateT.AddDate(0, 0, -2)
+
+		todayDateT, _ := time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
+		for ; startDateT.Before(todayDateT) || startDateT.Equal(todayDateT); startDateT = startDateT.AddDate(0, 0, 1) {
+			startDate := startDateT.Format(utils.FormatDate)
+			endDate := startDate
 			err = nil
 			fmt.Println("InitPositionTask:	启动:" + exchange)
 			utils.FileLog.Info("InitPositionTask:	启动:" + exchange)