|
@@ -0,0 +1,198 @@
|
|
|
+package index_data
|
|
|
+
|
|
|
+import (
|
|
|
+ "bytes"
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_bridge/global"
|
|
|
+ "eta/eta_bridge/models/pcsg"
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ PCSGBloombergPythonApiDaily = "/api/bloomberg/daily_data"
|
|
|
+ PCSGBloombergPythonApiWeekly = "/api/bloomberg/weekly_data"
|
|
|
+ PCSGBloombergPythonApiMonthly = "/api/bloomberg/monthly_data"
|
|
|
+)
|
|
|
+
|
|
|
+// GetPCSGBloombergDailyIndex 获取彭博日度指标
|
|
|
+func GetPCSGBloombergDailyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
+ apiData, e := CurlPCSGBloombergDailyApi()
|
|
|
+ if e != nil {
|
|
|
+ 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.GeneralData) > 0 {
|
|
|
+ frequency := "日度"
|
|
|
+ for _, v := range apiData.GeneralData {
|
|
|
+ t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
|
|
|
+ if t.IndexCode != "" {
|
|
|
+ indexes = append(indexes, t)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetPCSGBloombergWeeklyIndex 获取彭博周度指标
|
|
|
+func GetPCSGBloombergWeeklyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
+ apiData, e := CurlPCSGBloombergWeeklyApi()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("GetPCSGBloombergWeeklyIndex err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(apiData) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ frequency := "周度"
|
|
|
+ for _, v := range apiData {
|
|
|
+ t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
|
|
|
+ if t.IndexCode != "" {
|
|
|
+ indexes = append(indexes, t)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetPCSGBloombergMonthlyIndex 获取彭博月度指标
|
|
|
+func GetPCSGBloombergMonthlyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
+ apiData, e := CurlPCSGBloombergMonthlyApi()
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("GetPCSGBloombergMonthlyIndex err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(apiData) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ frequency := "月度"
|
|
|
+ for _, v := range apiData {
|
|
|
+ t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
|
|
|
+ if t.IndexCode != "" {
|
|
|
+ indexes = append(indexes, t)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// CurlPCSGBloombergDailyApi 请求日度指标接口
|
|
|
+func CurlPCSGBloombergDailyApi() (resultData pcsg.PythonBloombergDailyResultData, err error) {
|
|
|
+ if global.CONFIG.PCSG.BloombergApiUrl == "" {
|
|
|
+ err = fmt.Errorf("服务地址为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url := fmt.Sprint(global.CONFIG.PCSG.BloombergApiUrl, PCSGBloombergPythonApiDaily)
|
|
|
+
|
|
|
+ resp, e := http.Post(url, "application/json", bytes.NewBuffer([]byte("")))
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http post err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ b, e := ioutil.ReadAll(resp.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("resp body read err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(b) == 0 {
|
|
|
+ err = fmt.Errorf("resp body is empty")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ result := new(pcsg.PythonBloombergDailyResult)
|
|
|
+ if e = json.Unmarshal(b, &result); e != nil {
|
|
|
+ err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Code != 200 {
|
|
|
+ err = fmt.Errorf("result: %s", string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultData = result.Data
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// CurlPCSGBloombergWeeklyApi 请求周度指标接口
|
|
|
+func CurlPCSGBloombergWeeklyApi() (resultData []pcsg.PythonBloombergGeneralData, err error) {
|
|
|
+ if global.CONFIG.PCSG.BloombergApiUrl == "" {
|
|
|
+ err = fmt.Errorf("服务地址为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url := fmt.Sprint(global.CONFIG.PCSG.BloombergApiUrl, PCSGBloombergPythonApiWeekly)
|
|
|
+
|
|
|
+ resp, e := http.Post(url, "application/json", bytes.NewBuffer([]byte("")))
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http post err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ b, e := ioutil.ReadAll(resp.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("resp body read err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(b) == 0 {
|
|
|
+ err = fmt.Errorf("resp body is empty")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ result := new(pcsg.PythonBloombergWeeklyResult)
|
|
|
+ if e = json.Unmarshal(b, &result); e != nil {
|
|
|
+ err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Code != 200 {
|
|
|
+ err = fmt.Errorf("result: %s", string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultData = result.Data
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// CurlPCSGBloombergMonthlyApi 请求月度指标接口
|
|
|
+func CurlPCSGBloombergMonthlyApi() (resultData []pcsg.PythonBloombergGeneralData, err error) {
|
|
|
+ if global.CONFIG.PCSG.BloombergApiUrl == "" {
|
|
|
+ err = fmt.Errorf("服务地址为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url := fmt.Sprint(global.CONFIG.PCSG.BloombergApiUrl, PCSGBloombergPythonApiMonthly)
|
|
|
+
|
|
|
+ resp, e := http.Post(url, "application/json", bytes.NewBuffer([]byte("")))
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http post err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ b, e := ioutil.ReadAll(resp.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("resp body read err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(b) == 0 {
|
|
|
+ err = fmt.Errorf("resp body is empty")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ result := new(pcsg.PythonBloombergMonthlyResult)
|
|
|
+ if e = json.Unmarshal(b, &result); e != nil {
|
|
|
+ err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Code != 200 {
|
|
|
+ err = fmt.Errorf("result: %s", string(b))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultData = result.Data
|
|
|
+ return
|
|
|
+}
|