bloomberg.go 3.2 KB

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