base_from_lt.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_index_lib/utils"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. )
  8. type EdbDataFromLt struct {
  9. Close map[int64]interface{} `json:"CLOSE"`
  10. Value map[int64]interface{} `json:"VALUE"`
  11. }
  12. // GetEdbDataFromLt 获取路透数据
  13. func GetEdbDataFromLt(edbCode, startDate, endDate, frequency, edbTerminalCode string) (dataList map[int64]interface{}, err error) {
  14. /*if utils.Hz_LT_Data_Url == `` {
  15. err = errors.New("路透社接口未配置")
  16. return
  17. }*/
  18. terminal, err := GetTerminal(utils.DATA_SOURCE_LT, edbTerminalCode)
  19. if err != nil {
  20. err = fmt.Errorf("获取路透社接口配置出错 Err: %s", err)
  21. return
  22. }
  23. if terminal.ServerUrl == "" {
  24. err = fmt.Errorf("路透社接口未配置")
  25. return
  26. }
  27. if edbTerminalCode == "" {
  28. // 设置指标与终端关系的缓存
  29. terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
  30. _ = utils.Rc.Put(terminalCodeCacheKey, terminal.TerminalCode, utils.GetTodayLastSecond())
  31. }
  32. //'tick','minute',"hour','daily','weekly', 'monthly','quarterly', 'yearly'(Default 'daily')
  33. ltFrequency := `daily`
  34. switch frequency {
  35. case "周度":
  36. ltFrequency = `weekly`
  37. case "月度":
  38. ltFrequency = `monthly`
  39. case "季度":
  40. ltFrequency = `quarterly`
  41. case "年度":
  42. ltFrequency = `yearly`
  43. }
  44. dataList = make(map[int64]interface{})
  45. ltUrl := terminal.ServerUrl + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s&Frequency=%s`
  46. ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate, ltFrequency)
  47. utils.FileLog.Info("ltUrl:%s", ltUrl)
  48. body, err := http.Get(ltUrl)
  49. utils.FileLog.Info("lt result:%s", string(body))
  50. if err != nil {
  51. return
  52. }
  53. item := new(EdbDataFromLt)
  54. err = json.Unmarshal(body, &item)
  55. if err != nil {
  56. return
  57. }
  58. if len(item.Close) > 0 {
  59. dataList = item.Close
  60. } else {
  61. dataList = item.Value
  62. }
  63. return
  64. }