bloomberg.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package pcsg
  2. import (
  3. "strings"
  4. "time"
  5. )
  6. // PythonBloombergGeneralData 通用数据格式
  7. type PythonBloombergGeneralData struct {
  8. IDENTIFIER string `json:"IDENTIFIER" description:"指标编码"`
  9. PX_LAST_EOD *float64 `json:"PX_LAST_EOD" description:"数据值, 可能为null"`
  10. LAST_UPDATE_DATE_EOD string `json:"LAST_UPDATE_DATE_EOD" description:"数据日期, 可能为null"`
  11. NAME string `json:"NAME" description:"指标名称, 可能为null"`
  12. }
  13. // PythonBloombergGeneralResult API响应体
  14. type PythonBloombergGeneralResult struct {
  15. Code int `json:"code"`
  16. Msg string `json:"msg"`
  17. Data []PythonBloombergGeneralData `json:"data"`
  18. }
  19. // BaseFromBloombergApiIndexAndData Bloomberg原始指标及数据
  20. type BaseFromBloombergApiIndexAndData struct {
  21. BaseFromBloombergIndexId int `description:"指标ID"`
  22. IndexCode string `description:"指标编码"`
  23. IndexName string `description:"指标名称"`
  24. Unit string `description:"单位"`
  25. Source string `description:"来源"`
  26. Frequency string `description:"频度"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"修改时间"`
  29. Data []BaseFromBloombergApiIndexData `description:"数据列表"`
  30. }
  31. // BaseFromBloombergApiIndexData Bloomberg原始指标数据
  32. type BaseFromBloombergApiIndexData struct {
  33. DataTime time.Time `description:"数据日期"`
  34. Value float64 `description:"数据值"`
  35. }
  36. func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency string) (item BaseFromBloombergApiIndexAndData) {
  37. if origin.IDENTIFIER == "" {
  38. return
  39. }
  40. item.IndexCode = strings.TrimSpace(origin.IDENTIFIER)
  41. item.IndexName = strings.TrimSpace(origin.NAME)
  42. item.Frequency = frequency
  43. item.Unit = "无"
  44. item.Data = make([]BaseFromBloombergApiIndexData, 0)
  45. // 值可能为nil
  46. if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_LAST_EOD != nil {
  47. t, _ := time.ParseInLocation(time.DateOnly, origin.LAST_UPDATE_DATE_EOD, time.Local)
  48. item.Data = append(item.Data, BaseFromBloombergApiIndexData{
  49. DataTime: t,
  50. Value: *origin.PX_LAST_EOD,
  51. })
  52. }
  53. return
  54. }