Browse Source

Merge branch 'data_crawler' into debug

ziwen 1 year ago
parent
commit
f09fe160af
2 changed files with 48 additions and 9 deletions
  1. 16 6
      controllers/exchange_crawler.go
  2. 32 3
      models/base_from_sh.go

+ 16 - 6
controllers/exchange_crawler.go

@@ -42,15 +42,25 @@ func (this *ExchangeCrawler) GetOrAdd() {
 		fmt.Println("err:", err)
 		return
 	}
-	var resp models.JSONData
-	err = json.Unmarshal(body, &resp)
-	if err != nil {
-		fmt.Println(err)
-		return
+	if req.Exchange == "ine" {
+		var resp models.IneJSONData
+		err = json.Unmarshal(body, &resp)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		br.Data = resp
+	} else {
+		var resp models.SHMessage
+		err = json.Unmarshal(body, &resp)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		br.Data = resp
 	}
 
 	br.Ret = 200
 	br.Msg = "获取成功"
 	br.Success = true
-	br.Data = resp
 }

+ 32 - 3
models/base_from_sh.go

@@ -264,11 +264,11 @@ func RefreshEdbDataFromSh(edbInfoId int, edbCode, startDate string) (err error)
 }
 
 type RefreshExchangeoReq struct {
-	Url string `description:"交易所链接"`
+	Url      string `description:"交易所链接"`
+	Exchange string `description:"交易所"`
 }
 
-
-type JSONData struct {
+type IneJSONData struct {
 	OCursor    []OCursor   `json:"o_cursor"`
 	OCode      interface{} `json:"o_code"`
 	OMsg       string      `json:"o_msg"`
@@ -293,3 +293,32 @@ type OCursor struct {
 	SoldOut          interface{} `json:"CJ3"`
 	Change2          interface{} `json:"CJ2_CHG"`
 }
+
+type Position []struct {
+	ContractCode     string      `json:"INSTRUMENTID"`
+	ProductSortNo    int         `json:"PRODUCTSORTNO"`
+	Rank             int         `json:"RANK"`
+	ParticipantID1   string      `json:"PARTICIPANTID1"`
+	ParticipantName1 string      `json:"PARTICIPANTABBR1"`
+	Deal             interface{} `json:"CJ1"`
+	Change1          interface{} `json:"CJ1_CHG"`
+	ParticipantID2   string      `json:"PARTICIPANTID2"`
+	ParticipantName2 string      `json:"PARTICIPANTABBR2"`
+	BuyIn            interface{} `json:"CJ2"`
+	Change2          interface{} `json:"CJ2_CHG"`
+	ParticipantID3   string      `json:"PARTICIPANTID3"`
+	ParticipantName3 string      `json:"PARTICIPANTABBR3"`
+	SoldOut          interface{} `json:"CJ3"`
+	Change3          interface{} `json:"CJ3_CHG"`
+	ProductName      string      `json:"PRODUCTNAME"`
+}
+
+type SHMessage struct {
+	Position   Position `json:"o_cursor"`
+	Length     string   `json:"showlength"`
+	Code       int      `json:"o_code"`
+	Msg        string   `json:"o_msg"`
+	ReportDate string   `json:"report_date"`
+	UpdateDate string   `json:"update_date"`
+	PrintDate  string   `json:"print_date"`
+}