123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- 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"
- PCSGBloombergPythonApiDailyRun3 = "/api/bloomberg/daily_data_run3"
- )
- // 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) == 0 {
- return
- }
- frequency := "日度"
- for _, v := range apiData {
- 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
- }
- // 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("服务地址为空")
- 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)
- 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
- }
|