package services import ( "encoding/json" "errors" "fmt" "github.com/rdlucklib/rdluck_tools/http" "hongze/hongze_edb_lib/utils" ) type EdbDataFromThs struct { DataVol int64 `json:"dataVol"` Errmsg string `json:"errmsg"` Errorcode int64 `json:"errorcode"` Perf interface{} `json:"perf"` Tables []struct { ID []string `json:"id"` Time []string `json:"time"` Value []float64 `json:"value"` } `json:"tables"` } func GetEdbDataFromThs(edbCode, startDate, endDate string) (item *EdbDataFromThs, err error) { return getEdbDataFromThs(edbCode, startDate, endDate, 0) } // getEdbDataFromThs 获取同花顺接口数据 func getEdbDataFromThs(edbCode, startDate, endDate string, num int) (item *EdbDataFromThs, err error) { thsUrl := utils.Hz_Ths_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s` thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate) utils.FileLog.Info("thsUrl:" + thsUrl) body, err := http.Get(thsUrl) utils.FileLog.Info("ths result:" + string(body)) if err != nil { err = errors.New(" Err:" + err.Error() + ";result:" + string(body)) return } item = new(EdbDataFromThs) err = json.Unmarshal(body, &item) if err != nil { err = errors.New("GetEdbDataFromThs json.Unmarshal Err:" + err.Error()) return } if item.Errorcode != 0 { //session has expired,please re-login after using the system //如果是同花顺登录session失效了,那么就重新请求获取数据 if item.Errorcode == -1020 && num == 0 { return getEdbDataFromThs(edbCode, startDate, endDate, 1) } err = errors.New(string(body)) return } return item, nil }