123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package pcsg
- import (
- "eta/eta_bridge/utils"
- "strings"
- "time"
- )
- // PythonBloombergGeneralData 通用数据格式
- type PythonBloombergGeneralData struct {
- NAME string `json:"NAME" description:"指标名称, 可能为null"`
- IDENTIFIER string `json:"IDENTIFIER" description:"指标编码"`
- PX_LAST_EOD *float64 `json:"PX_LAST_EOD" description:"数据值, 可能为null"`
- PX_VOLUME_EOD *float64 `json:"PX_VOLUME_EOD" description:"数据值, 可能为null"`
- PX_LAST *float64 `json:"PX_LAST" description:"数据值, 可能为null"`
- LAST_UPDATE_DATE_EOD string `json:"LAST_UPDATE_DATE_EOD" description:"数据日期, 可能为null"`
- DATE string `json:"DATE" description:"数据日期, 可能为null"`
- }
- // PythonBloombergGeneralResult API响应体
- type PythonBloombergGeneralResult struct {
- Code int `json:"code"`
- Msg string `json:"msg"`
- Data []PythonBloombergGeneralData `json:"data"`
- }
- // BaseFromBloombergApiIndexAndData Bloomberg原始指标及数据
- type BaseFromBloombergApiIndexAndData struct {
- BaseFromBloombergIndexId int `description:"指标ID"`
- IndexCode string `description:"指标编码"`
- IndexName string `description:"指标名称"`
- Unit string `description:"单位"`
- Source string `description:"来源"`
- Frequency string `description:"频度"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- Data []BaseFromBloombergApiIndexData `description:"数据列表"`
- }
- // BaseFromBloombergApiIndexData Bloomberg原始指标数据
- type BaseFromBloombergApiIndexData struct {
- DataTime time.Time `description:"数据日期"`
- Value float64 `description:"数据值"`
- }
- func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency string) (item BaseFromBloombergApiIndexAndData) {
- if origin.IDENTIFIER == "" {
- return
- }
- item.IndexCode = strings.TrimSpace(origin.IDENTIFIER)
- item.IndexName = strings.TrimSpace(origin.NAME)
- item.Frequency = frequency
- item.Unit = "无"
- item.Data = make([]BaseFromBloombergApiIndexData, 0)
- // 数据来源的值和日期对应字段不同
- var dataTime time.Time
- var val *float64
- if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_LAST_EOD != nil {
- dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.LAST_UPDATE_DATE_EOD, time.Local)
- val = origin.PX_LAST_EOD
- }
- if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_VOLUME_EOD != nil {
- dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.LAST_UPDATE_DATE_EOD, time.Local)
- val = origin.PX_VOLUME_EOD
- }
- if origin.DATE != "" && origin.PX_LAST != nil {
- dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.DATE, time.Local)
- val = origin.PX_LAST
- }
- if !dataTime.IsZero() && val != nil {
- item.Data = append(item.Data, BaseFromBloombergApiIndexData{
- DataTime: dataTime,
- Value: *val,
- })
- }
- return
- }
|