|
@@ -1,7 +1,6 @@
|
|
|
package index_data
|
|
|
|
|
|
import (
|
|
|
- "bytes"
|
|
|
"encoding/json"
|
|
|
"eta/eta_bridge/global"
|
|
|
"eta/eta_bridge/models/pcsg"
|
|
@@ -10,16 +9,9 @@ import (
|
|
|
"net/http"
|
|
|
)
|
|
|
|
|
|
-var (
|
|
|
- PCSGBloombergPythonApiDaily = "/api/bloomberg/daily_data"
|
|
|
- PCSGBloombergPythonApiWeekly = "/api/bloomberg/weekly_data"
|
|
|
- PCSGBloombergPythonApiMonthly = "/api/bloomberg/monthly_data"
|
|
|
- PCSGBloombergPythonApiDailyRun3 = "/api/bloomberg/daily_data_run3"
|
|
|
-)
|
|
|
-
|
|
|
-// GetPCSGBloombergDailyIndex 获取彭博日度指标
|
|
|
-func GetPCSGBloombergDailyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
- apiData, e := CurlPCSGBloombergDailyApi()
|
|
|
+// GetPCSGBloombergGeneralIndex 获取指标信息
|
|
|
+func GetPCSGBloombergGeneralIndex(taskKey, frequency string) (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
+ apiData, e := CurlPCSGBloombergGeneralDataApi(taskKey)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("CurlPCSGBloombergDailyApi err: %s", e.Error())
|
|
|
return
|
|
@@ -27,7 +19,6 @@ func GetPCSGBloombergDailyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndDa
|
|
|
if len(apiData) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- frequency := "日度"
|
|
|
for _, v := range apiData {
|
|
|
t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
|
|
|
if t.IndexCode != "" {
|
|
@@ -37,189 +28,20 @@ func GetPCSGBloombergDailyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAndDa
|
|
|
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
|
|
|
-}
|
|
|
-
|
|
|
-// GetPCSGBloombergDailyIndexRun3 获取彭博日度指标(Run3)
|
|
|
-func GetPCSGBloombergDailyIndexRun3() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
|
|
|
- apiData, e := CurlPCSGBloombergDailyRun3Api()
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("GetPCSGBloombergDailyIndexRun3 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.PythonBloombergGeneralData, 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.PythonBloombergGeneralResult)
|
|
|
- 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("服务地址为空")
|
|
|
+// CurlPCSGBloombergGeneralDataApi 请求通用格式数据接口
|
|
|
+func CurlPCSGBloombergGeneralDataApi(taskKey string) (resultData []pcsg.PythonBloombergGeneralData, err error) {
|
|
|
+ if taskKey == "" {
|
|
|
+ err = fmt.Errorf("任务Key为空")
|
|
|
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.PythonBloombergGeneralResult)
|
|
|
- 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.PythonBloombergGeneralResult)
|
|
|
- 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
|
|
|
-}
|
|
|
-
|
|
|
-// CurlPCSGBloombergDailyRun3Api 请求日度指标(Run3)接口
|
|
|
-func CurlPCSGBloombergDailyRun3Api() (resultData []pcsg.PythonBloombergGeneralData, err error) {
|
|
|
if global.CONFIG.PCSG.BloombergApiUrl == "" {
|
|
|
err = fmt.Errorf("服务地址为空")
|
|
|
return
|
|
|
}
|
|
|
- url := fmt.Sprint(global.CONFIG.PCSG.BloombergApiUrl, PCSGBloombergPythonApiDailyRun3)
|
|
|
+ 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.Post(url, "application/json", bytes.NewBuffer([]byte("")))
|
|
|
+ resp, e := http.Get(url)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("http post err: %s", e.Error())
|
|
|
return
|