future_good_edb_info.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package future_good
  2. import (
  3. "errors"
  4. "eta/eta_task/models/data_manage/future_good"
  5. "eta/eta_task/services/alarm_msg"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. "strings"
  9. "time"
  10. )
  11. // RefreshFutureGoodDataFromThs 刷新同花顺的商品期货数据
  12. func RefreshFutureGoodDataFromThs() (err error) {
  13. errMsgList := make([]string, 0)
  14. defer func() {
  15. if err != nil {
  16. tips := fmt.Sprintf("RefreshFutureGoodDataFromThs Err: %v", err)
  17. //fmt.Println(tips)
  18. utils.FileLog.Info(tips)
  19. go alarm_msg.SendAlarmMsg(tips, 3)
  20. }
  21. if len(errMsgList) > 0 {
  22. tips := fmt.Sprintf("RefreshFutureGoodDataFromThs部分商品刷新失败, ErrMsg: %s", strings.Join(errMsgList, "\n"))
  23. utils.FileLog.Info(tips)
  24. go alarm_msg.SendAlarmMsg(tips, 3)
  25. }
  26. }()
  27. var condition string
  28. var pars []interface{}
  29. // 查询继续更新的指标
  30. condition += " AND is_stop=? "
  31. pars = append(pars, 0)
  32. //condition += " AND exchange=? "
  33. //pars = append(pars, "上海期货")
  34. list, err := future_good.GetFutureGoodEdbInfoList(condition, pars)
  35. if err != nil {
  36. err = errors.New("GetEdbInfoByCondition:" + err.Error())
  37. return
  38. }
  39. lenList := len(list)
  40. fmt.Println("总共", lenList, "条")
  41. // 简单限制一下请求速度, 同花顺EDB函数限制为5/s
  42. ticker := time.NewTicker(250 * time.Millisecond)
  43. defer ticker.Stop()
  44. for k, v := range list {
  45. <-ticker.C
  46. fmt.Println("剩余", lenList-k-1, "条")
  47. fmt.Println("编码:", v.FutureGoodEdbCode, ";名称:", v.FutureGoodEdbName)
  48. var startDateTime time.Time
  49. startDateTime = v.EndDate
  50. // 如果指标结束日期不是空的话,那么就按照刷配置的刷新周期进行兼容性的刷新吧
  51. if v.EndDate.IsZero() {
  52. startDateTime = time.Now()
  53. }
  54. startDate := startDateTime.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  55. resp, err := RefreshEdbData(v.FutureGoodEdbInfoId, v.FutureGoodEdbCode, startDate)
  56. if err != nil {
  57. errMsgList = append(errMsgList, fmt.Sprint(v.FutureGoodEdbCode, ";刷新数据失败,err:", err.Error()))
  58. continue
  59. }
  60. if resp.Ret != 200 {
  61. errMsgList = append(errMsgList, fmt.Sprint(v.FutureGoodEdbCode, ";刷新数据失败,err:", resp.Msg, ";ErrMsg:", resp.ErrMsg))
  62. continue
  63. }
  64. }
  65. return err
  66. }