hsun 2 months ago
parent
commit
47787e780b
2 changed files with 37 additions and 15 deletions
  1. 33 13
      models/pcsg/bloomberg.go
  2. 4 2
      services/index_data/pcsg_bloomberg.go

+ 33 - 13
models/pcsg/bloomberg.go

@@ -1,25 +1,33 @@
 package pcsg
 
 import (
+	"eta/eta_bridge/global"
 	"eta/eta_bridge/utils"
+	"fmt"
 	"strings"
 	"time"
 )
 
+const (
+	TaskKey0000      = "IDpcsgDailySnap0000"
+	SubOneDayTaskKey = "IDpcsgDailySnap0330" // 日期-1的key
+)
+
 // 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:"数据日期, 可能为null"`
-	DATE                 string   `json:"DATE" description:"数据日期, 可能为null"`
-	PX_SETTLE            *float64 `json:"PX_SETTLE" description:"数据值, 可能为null"`
-	PX_SETTLE_LAST_DT    string   `json:"PX_SETTLE_LAST_DT" description:"数据日期, 可能为null"`
-	OPEN_INT             *float64 `json:"OPEN_INT"`
-	OPEN_INT_DATE        string   `json:"OPEN_INT_DATE"`
+	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:"数据日期"`
 }
 
 // PythonBloombergGeneralResult API响应体
@@ -48,7 +56,7 @@ type BaseFromBloombergApiIndexData struct {
 	Value    float64   `description:"数据值"`
 }
 
-func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency string) (item BaseFromBloombergApiIndexAndData) {
+func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency, taskKey string) (item BaseFromBloombergApiIndexAndData) {
 	if origin.IDENTIFIER == "" {
 		return
 	}
@@ -85,6 +93,18 @@ func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, fr
 		dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.OPEN_INT_DATE, time.Local)
 		val = origin.OPEN_INT
 	}
+	if (taskKey == TaskKey0000 || taskKey == SubOneDayTaskKey) && origin.DL_SNAPSHOT_START_TIME != "" && origin.PX_LAST != nil {
+		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,

+ 4 - 2
services/index_data/pcsg_bloomberg.go

@@ -20,7 +20,7 @@ func GetPCSGBloombergGeneralIndex(taskKey, frequency string) (indexes []pcsg.Bas
 		return
 	}
 	for _, v := range apiData {
-		t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
+		t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency, taskKey)
 		if t.IndexCode != "" {
 			indexes = append(indexes, t)
 		}
@@ -40,7 +40,6 @@ func CurlPCSGBloombergGeneralDataApi(taskKey string) (resultData []pcsg.PythonBl
 	}
 	url := fmt.Sprintf("%s/api/bloomberg/general_data?task_key=%s", global.CONFIG.PCSG.BloombergApiUrl, taskKey)
 
-	//resp, e := http.Post(url, "application/json", bytes.NewBuffer([]byte("")))
 	resp, e := http.Get(url)
 	if e != nil {
 		err = fmt.Errorf("http post err: %s", e.Error())
@@ -58,6 +57,9 @@ func CurlPCSGBloombergGeneralDataApi(taskKey string) (resultData []pcsg.PythonBl
 		return
 	}
 
+	//str := `{"Code":200,"Msg":"","Data":[{"DL_REQUEST_ID":"IDpcsgDailySnap0330","DL_REQUEST_NAME":"contractsLastHistory","DL_SNAPSHOT_START_TIME":"2024-07-09T08:30:03","DL_SNAPSHOT_TZ":"JST","IDENTIFIER":"Comdty B001","RC":0,"DATE":"2024-05-09","PX_LAST":1183.88},{"DL_REQUEST_ID":"IDpcsgDailySnap0330","DL_REQUEST_NAME":"contractsLastHistory","DL_SNAPSHOT_START_TIME":"2024-07-10T08:30:03","DL_SNAPSHOT_TZ":"JST","IDENTIFIER":"Comdty B001","RC":0,"DATE":"2024-05-10","PX_LAST":1182.79},{"DL_REQUEST_ID":"IDpcsgDailySnap0330","DL_REQUEST_NAME":"contractsLastHistory","DL_SNAPSHOT_START_TIME":"2024-07-09T08:30:03","DL_SNAPSHOT_TZ":"JST","IDENTIFIER":"Comdty B002","RC":0,"DATE":"2024-05-10","PX_LAST":1162.63}]}`
+	//b := []byte(str)
+
 	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))