package pcsg import ( "eta/eta_bridge/global" "eta/eta_bridge/utils" "fmt" "strings" "time" ) const ( TaskKey0000 = "IDpcsgDailySnap0000" SubOneDayTaskKey = "IDpcsgDailySnap0330" // 日期-1的key TaskKey0345 = "IDpcsgDailySnap0345" ) // PythonBloombergGeneralData 通用数据格式(有空改成Map吧...然后做成配置方便加新字段...) 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"` PX_VOLUME *float64 `json:"PX_VOLUME" description:"数据值, 可能为null"` LAST_UPDATE_DATE_EOD string `json:"LAST_UPDATE_DATE_EOD" description:"数据日期"` DATE string `json:"DATE" description:"数据日期"` PX_SETTLE *float64 `json:"PX_SETTLE" description:"数据值, 可能为null"` PX_SETTLE_LAST_DT string `json:"PX_SETTLE_LAST_DT" description:"数据日期"` OPEN_INT *float64 `json:"OPEN_INT"` OPEN_INT_DATE string `json:"OPEN_INT_DATE"` DL_SNAPSHOT_START_TIME string `json:"DL_SNAPSHOT_START_TIME" description:"数据日期"` LAST_UPDATE string `json:"LAST_UPDATE" description:"IDpcsgDailySnap0000和IDpcsgDailySnap0330判断用的"` PX_CLOSE_DT string `json:"PX_CLOSE_DT" description:"数据日期"` LAST_UPDATE_DT string `json:"LAST_UPDATE_DT" description:"数据日期"` HEATING_DAYS *float64 `json:"HEATING_DAYS" description:"数据值, 可能为null"` COOLING_DAYS *float64 `json:"COOLING_DAYS" 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, taskKey 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 origin.DATE != "" && origin.PX_VOLUME != nil { dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.DATE, time.Local) val = origin.PX_VOLUME } if origin.PX_SETTLE_LAST_DT != "" && origin.PX_SETTLE != nil { dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.PX_SETTLE_LAST_DT, time.Local) val = origin.PX_SETTLE } if origin.OPEN_INT_DATE != "" && origin.OPEN_INT != nil { dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.OPEN_INT_DATE, time.Local) val = origin.OPEN_INT } if taskKey == TaskKey0345 && origin.PX_CLOSE_DT != "" && origin.PX_LAST != nil { dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.PX_CLOSE_DT, time.Local) val = origin.PX_LAST } if (taskKey == TaskKey0000 || taskKey == SubOneDayTaskKey) && origin.DL_SNAPSHOT_START_TIME != "" && origin.PX_LAST != nil { // 根据LAST_UPDATE的格式进行判断, 仅加入格式为hh:mm:ss的 _, e := time.ParseInLocation("15:04:05", origin.LAST_UPDATE, time.Local) if e != nil { return } d, e := time.ParseInLocation("2006-01-02T15:04:05", origin.DL_SNAPSHOT_START_TIME, time.Local) if e != nil { global.LOG.Info(fmt.Sprintf("DL_SNAPSHOT_START_TIME日期解析失败, %s", origin.DL_SNAPSHOT_START_TIME)) } dataTime = d // 这个任务日期需要-1 if taskKey == SubOneDayTaskKey { dataTime = dataTime.AddDate(0, 0, -1) } val = origin.PX_LAST } if !dataTime.IsZero() && val != nil { item.Data = append(item.Data, BaseFromBloombergApiIndexData{ DataTime: dataTime, Value: *val, }) } return } func FormatPythonBloombergDailyRun11Data2Base(origin PythonBloombergGeneralData, frequency, taskKey string) (items []BaseFromBloombergApiIndexAndData) { if origin.IDENTIFIER == "" { return } if origin.LAST_UPDATE_DT == "" { return } dataTime, err := time.ParseInLocation(utils.FormatDate, origin.LAST_UPDATE_DT, time.Local) if err != nil { return } items = make([]BaseFromBloombergApiIndexAndData, 0) // WER1UK00 Index, WER1UK00 Index HDD, WER1UK00 Index CDD item := BaseFromBloombergApiIndexAndData{} item.IndexCode = strings.TrimSpace(origin.IDENTIFIER) item.IndexName = strings.TrimSpace(origin.NAME) item.Frequency = frequency item.Unit = "无" item.Data = make([]BaseFromBloombergApiIndexData, 0) itemHDD := BaseFromBloombergApiIndexAndData{} itemHDD.IndexCode = strings.TrimSpace(origin.IDENTIFIER) itemHDD.IndexCode = fmt.Sprintf("%s HDD", itemHDD.IndexCode) itemHDD.IndexName = strings.TrimSpace(origin.NAME) itemHDD.IndexName = fmt.Sprintf("%s HDD", itemHDD.IndexName) itemHDD.Frequency = frequency itemHDD.Unit = "无" itemHDD.Data = make([]BaseFromBloombergApiIndexData, 0) itemCDD := BaseFromBloombergApiIndexAndData{} itemCDD.IndexCode = strings.TrimSpace(origin.IDENTIFIER) itemCDD.IndexCode = fmt.Sprintf("%s CDD", itemCDD.IndexCode) itemCDD.IndexName = strings.TrimSpace(origin.NAME) itemCDD.IndexName = fmt.Sprintf("%s CDD", itemCDD.IndexName) itemCDD.Frequency = frequency itemCDD.Unit = "无" itemCDD.Data = make([]BaseFromBloombergApiIndexData, 0) // 数据来源的值和日期对应字段不同 if origin.PX_LAST != nil { val := origin.PX_LAST item.Data = append(item.Data, BaseFromBloombergApiIndexData{ DataTime: dataTime, Value: *val, }) } if origin.HEATING_DAYS != nil { val := origin.HEATING_DAYS itemHDD.Data = append(itemHDD.Data, BaseFromBloombergApiIndexData{ DataTime: dataTime, Value: *val, }) } if origin.COOLING_DAYS != nil { val := origin.COOLING_DAYS itemCDD.Data = append(itemCDD.Data, BaseFromBloombergApiIndexData{ DataTime: dataTime, Value: *val, }) } items = append(items, item, itemHDD, itemCDD) return } func FormatPythonBloombergDailyRunHistV1Data2Base(origin PythonBloombergGeneralData, frequency, taskKey string) (item BaseFromBloombergApiIndexAndData) { if origin.IDENTIFIER == "" { return } item.IndexCode = strings.TrimSpace(origin.IDENTIFIER) if item.IndexCode == "TZT1 COMB Comdty" { item.IndexCode = "TZT1 COMB V Comdty" } 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.DATE != "" && origin.PX_VOLUME != nil { dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.DATE, time.Local) val = origin.PX_VOLUME } if !dataTime.IsZero() && val != nil { item.Data = append(item.Data, BaseFromBloombergApiIndexData{ DataTime: dataTime, Value: *val, }) } return }