Kaynağa Gözat

Merge branch 'feature/eta_2.0.3'

hsun 1 ay önce
ebeveyn
işleme
a950cdf2f4
3 değiştirilmiş dosya ile 57 ekleme ve 5 silme
  1. 45 0
      services/data/edb_info.go
  2. 11 5
      services/task.go
  3. 1 0
      utils/constants.go

+ 45 - 0
services/data/edb_info.go

@@ -1322,3 +1322,48 @@ func RefreshBaseDataFromSource(wg *sync.WaitGroup, source int) (err error) {
 	}
 	return err
 }
+
+// RefreshDataFromTradeAnalysis 刷新持仓分析指标
+func RefreshDataFromTradeAnalysis(wg *sync.WaitGroup) (err error) {
+	utils.FileLog.Info(fmt.Sprintf("持仓分析指标刷新开始: %s", time.Now().Format(utils.FormatDateTime)))
+	errMsgList := make([]string, 0)
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("RefreshDataFromTradeAnalysis err: %v", err)
+			utils.FileLog.Info(tips)
+			go alarm_msg.SendAlarmMsg(tips, 3)
+		}
+		if len(errMsgList) > 0 {
+			tips := fmt.Sprintf("RefreshDataFromTradeAnalysis ErrMsg: %s", strings.Join(errMsgList, "\n"))
+			utils.FileLog.Info(tips)
+			go alarm_msg.SendAlarmMsg(tips, 3)
+		}
+		wg.Done()
+	}()
+
+	var condition string
+	var pars []interface{}
+	condition += ` AND source = ? AND no_update = 0 `
+	pars = append(pars, utils.DATA_SOURCE_TRADE_ANALYSIS)
+	items, e := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if e != nil {
+		err = fmt.Errorf("获取持仓分析指标失败, %v", e)
+		return
+	}
+
+	for _, v := range items {
+		// 持仓分析指标只有日度
+		startDate := v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		resp, e := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
+		if e != nil {
+			errMsgList = append(errMsgList, fmt.Sprintf("EdbCode: %s, RefreshEdbData err: %v", v.EdbCode, e))
+			continue
+		}
+		if resp.Ret != 200 {
+			errMsgList = append(errMsgList, fmt.Sprintf("EdbCode: %s, RefreshEdbData err: %v, errMsg: %s", v.EdbCode, e, resp.ErrMsg))
+			continue
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("持仓分析指标刷新结束: %s", time.Now().Format(utils.FormatDateTime)))
+	return err
+}

+ 11 - 5
services/task.go

@@ -33,11 +33,11 @@ func Task() {
 
 	XyTask()
 
-	// TODO:测试-刷新同花顺高频, 上线前删除
-	if utils.RunMode == "debug" {
-		refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 30 12 * * *", data.RefreshBaseFromThsHfIndex)
-		task.AddTask("refreshThsHfBase", refreshThsHfBase)
-	}
+	// 测试-刷新同花顺高频, 上线前删除
+	//if utils.RunMode == "debug" {
+	//	refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 30 12 * * *", data.RefreshBaseFromThsHfIndex)
+	//	task.AddTask("refreshThsHfBase", refreshThsHfBase)
+	//}
 
 	task.StartTask()
 	fmt.Println("task end")
@@ -189,6 +189,12 @@ func RefreshData(cont context.Context) (err error) {
 		_ = data.RefreshDataFromCCF(&wg)
 	}()
 
+	// 持仓分析
+	go func() {
+		wg.Add(1)
+		_ = data.RefreshDataFromTradeAnalysis(&wg)
+	}()
+
 	wg.Wait()
 	////计算指标
 	data.RefreshDataFromCalculateAll()

+ 1 - 0
utils/constants.go

@@ -106,6 +106,7 @@ const (
 	DATA_SOURCE_BLOOMBERG                            = 83       // bloomberg彭博数据
 	DATA_SOURCE_BUSINESS                             = 84       // 来源于自有数据
 	DATA_SOURCE_CCF                                  = 86       // CCF化纤信息
+	DATA_SOURCE_TRADE_ANALYSIS                       = 92       // 持仓分析
 )
 
 // 数据刷新频率