package future_good import ( "errors" "eta/eta_task/models/data_manage/future_good" "eta/eta_task/services/alarm_msg" "eta/eta_task/utils" "fmt" "strings" "time" ) // RefreshFutureGoodDataFromThs 刷新同花顺的商品期货数据 func RefreshFutureGoodDataFromThs() (err error) { errMsgList := make([]string, 0) defer func() { if err != nil { tips := fmt.Sprintf("RefreshFutureGoodDataFromThs Err: %v", err) //fmt.Println(tips) utils.FileLog.Info(tips) go alarm_msg.SendAlarmMsg(tips, 3) } if len(errMsgList) > 0 { tips := fmt.Sprintf("RefreshFutureGoodDataFromThs部分商品刷新失败, ErrMsg: %s", strings.Join(errMsgList, "\n")) utils.FileLog.Info(tips) go alarm_msg.SendAlarmMsg(tips, 3) } }() var condition string var pars []interface{} // 查询继续更新的指标 condition += " AND is_stop=? " pars = append(pars, 0) //condition += " AND exchange=? " //pars = append(pars, "上海期货") list, err := future_good.GetFutureGoodEdbInfoList(condition, pars) if err != nil { err = errors.New("GetEdbInfoByCondition:" + err.Error()) return } lenList := len(list) fmt.Println("总共", lenList, "条") // 简单限制一下请求速度, 同花顺EDB函数限制为5/s ticker := time.NewTicker(250 * time.Millisecond) defer ticker.Stop() for k, v := range list { <-ticker.C fmt.Println("剩余", lenList-k-1, "条") fmt.Println("编码:", v.FutureGoodEdbCode, ";名称:", v.FutureGoodEdbName) var startDateTime time.Time startDateTime = v.EndDate // 如果指标结束日期不是空的话,那么就按照刷配置的刷新周期进行兼容性的刷新吧 if v.EndDate.IsZero() { startDateTime = time.Now() } startDate := startDateTime.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) resp, err := RefreshEdbData(v.FutureGoodEdbInfoId, v.FutureGoodEdbCode, startDate) if err != nil { errMsgList = append(errMsgList, fmt.Sprint(v.FutureGoodEdbCode, ";刷新数据失败,err:", err.Error())) continue } if resp.Ret != 200 { errMsgList = append(errMsgList, fmt.Sprint(v.FutureGoodEdbCode, ";刷新数据失败,err:", resp.Msg, ";ErrMsg:", resp.ErrMsg)) continue } } return err }