Browse Source

PCSG-Bloomberg接口调整

hsun 10 months ago
parent
commit
46fc5551f5
2 changed files with 27 additions and 76 deletions
  1. 15 57
      models/pcsg/bloomberg.go
  2. 12 19
      services/index_data/pcsg_bloomberg.go

+ 15 - 57
models/pcsg/bloomberg.go

@@ -5,44 +5,16 @@ import (
 	"time"
 )
 
-// PythonBloombergDailyPriceData 日度-价格数据
-type PythonBloombergDailyPriceData struct {
-	IDENTIFIER    string  `json:"IDENTIFIER" description:"指标编码"`
-	PX_YEST_CLOSE float64 `json:"PX_YEST_CLOSE" description:"数据值"`
-	PX_CLOSE_DT   string  `json:"PX_CLOSE_DT" description:"数据日期"`
-	NAME          string  `json:"NAME" description:"指标名称"`
-}
-
-// PythonBloombergGeneralData 通用数据
+// PythonBloombergGeneralData 通用数据格式
 type PythonBloombergGeneralData struct {
-	IDENTIFIER     string  `json:"IDENTIFIER" description:"指标编码"`
-	NAME           string  `json:"NAME" description:"指标名称"`
-	PX_LAST        float64 `json:"PX_LAST" description:"数据值"`
-	LAST_UPDATE_DT string  `json:"LAST_UPDATE_DT" description:"数据日期"`
-}
-
-// PythonBloombergDailyResult 日度指标API响应体
-type PythonBloombergDailyResult struct {
-	Code int                            `json:"code"`
-	Msg  string                         `json:"msg"`
-	Data PythonBloombergDailyResultData `json:"data"`
-}
-
-// PythonBloombergDailyResultData 日度指标API响应数据
-type PythonBloombergDailyResultData struct {
-	PriceData   []PythonBloombergDailyPriceData `json:"price_data" description:"价格数据"`
-	GeneralData []PythonBloombergGeneralData    `json:"general_data" description:"一般数据"`
-}
-
-// PythonBloombergWeeklyResult 周度指标API响应体
-type PythonBloombergWeeklyResult struct {
-	Code int                          `json:"code"`
-	Msg  string                       `json:"msg"`
-	Data []PythonBloombergGeneralData `json:"data"`
+	IDENTIFIER           string   `json:"IDENTIFIER" description:"指标编码"`
+	PX_LAST_EOD          *float64 `json:"PX_LAST_EOD" description:"数据值, 可能为null"`
+	LAST_UPDATE_DATE_EOD string   `json:"LAST_UPDATE_DATE_EOD" description:"数据日期, 可能为null"`
+	NAME                 string   `json:"NAME" description:"指标名称, 可能为null"`
 }
 
-// PythonBloombergMonthlyResult 月度指标API响应体
-type PythonBloombergMonthlyResult struct {
+// PythonBloombergGeneralResult API响应体
+type PythonBloombergGeneralResult struct {
 	Code int                          `json:"code"`
 	Msg  string                       `json:"msg"`
 	Data []PythonBloombergGeneralData `json:"data"`
@@ -67,23 +39,6 @@ type BaseFromBloombergApiIndexData struct {
 	Value    float64   `description:"数据值"`
 }
 
-func FormatPythonBloombergDailyPriceData2Base(origin PythonBloombergDailyPriceData) (item BaseFromBloombergApiIndexAndData) {
-	if origin.IDENTIFIER == "" {
-		return
-	}
-	item.IndexCode = strings.TrimSpace(origin.IDENTIFIER)
-	item.IndexName = strings.TrimSpace(origin.NAME)
-	item.Frequency = "日度"
-	item.Unit = "无"
-	item.Data = make([]BaseFromBloombergApiIndexData, 0)
-	t, _ := time.ParseInLocation(time.DateOnly, origin.PX_CLOSE_DT, time.Local)
-	item.Data = append(item.Data, BaseFromBloombergApiIndexData{
-		DataTime: t,
-		Value:    origin.PX_YEST_CLOSE,
-	})
-	return
-}
-
 func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency string) (item BaseFromBloombergApiIndexAndData) {
 	if origin.IDENTIFIER == "" {
 		return
@@ -93,10 +48,13 @@ func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, fr
 	item.Frequency = frequency
 	item.Unit = "无"
 	item.Data = make([]BaseFromBloombergApiIndexData, 0)
-	t, _ := time.ParseInLocation(time.DateOnly, origin.LAST_UPDATE_DT, time.Local)
-	item.Data = append(item.Data, BaseFromBloombergApiIndexData{
-		DataTime: t,
-		Value:    origin.PX_LAST,
-	})
+	// 值可能为nil
+	if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_LAST_EOD != nil {
+		t, _ := time.ParseInLocation(time.DateOnly, origin.LAST_UPDATE_DATE_EOD, time.Local)
+		item.Data = append(item.Data, BaseFromBloombergApiIndexData{
+			DataTime: t,
+			Value:    *origin.PX_LAST_EOD,
+		})
+	}
 	return
 }

+ 12 - 19
services/index_data/pcsg_bloomberg.go

@@ -23,21 +23,14 @@ func GetPCSGBloombergDailyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndDa
 		err = fmt.Errorf("CurlPCSGBloombergDailyApi err: %s", e.Error())
 		return
 	}
-	if len(apiData.PriceData) > 0 {
-		for _, v := range apiData.PriceData {
-			t := pcsg.FormatPythonBloombergDailyPriceData2Base(v)
-			if t.IndexCode != "" {
-				indexes = append(indexes, t)
-			}
-		}
+	if len(apiData) == 0 {
+		return
 	}
-	if len(apiData.GeneralData) > 0 {
-		frequency := "日度"
-		for _, v := range apiData.GeneralData {
-			t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
-			if t.IndexCode != "" {
-				indexes = append(indexes, t)
-			}
+	frequency := "日度"
+	for _, v := range apiData {
+		t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
+		if t.IndexCode != "" {
+			indexes = append(indexes, t)
 		}
 	}
 	return
@@ -84,7 +77,7 @@ func GetPCSGBloombergMonthlyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAnd
 }
 
 // CurlPCSGBloombergDailyApi 请求日度指标接口
-func CurlPCSGBloombergDailyApi() (resultData pcsg.PythonBloombergDailyResultData, err error) {
+func CurlPCSGBloombergDailyApi() (resultData []pcsg.PythonBloombergGeneralData, err error) {
 	if global.CONFIG.PCSG.BloombergApiUrl == "" {
 		err = fmt.Errorf("服务地址为空")
 		return
@@ -108,7 +101,7 @@ func CurlPCSGBloombergDailyApi() (resultData pcsg.PythonBloombergDailyResultData
 		return
 	}
 
-	result := new(pcsg.PythonBloombergDailyResult)
+	result := new(pcsg.PythonBloombergGeneralResult)
 	if e = json.Unmarshal(b, &result); e != nil {
 		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
 		return
@@ -146,8 +139,8 @@ func CurlPCSGBloombergWeeklyApi() (resultData []pcsg.PythonBloombergGeneralData,
 		return
 	}
 
-	result := new(pcsg.PythonBloombergWeeklyResult)
-	if e = json.Unmarshal(b, &result); e != nil {
+	result := new(pcsg.PythonBloombergGeneralResult)
+	if e := json.Unmarshal(b, &result); e != nil {
 		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
 		return
 	}
@@ -184,7 +177,7 @@ func CurlPCSGBloombergMonthlyApi() (resultData []pcsg.PythonBloombergGeneralData
 		return
 	}
 
-	result := new(pcsg.PythonBloombergMonthlyResult)
+	result := new(pcsg.PythonBloombergGeneralResult)
 	if e = json.Unmarshal(b, &result); e != nil {
 		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
 		return