123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package services
- import (
- "encoding/json"
- "eta/eta_crawler_local/services/alarm_msg"
- "eta/eta_crawler_local/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- "time"
- )
- 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 Message struct {
- Position Position `json:"o_cursor"`
- Length string `json:"showlength"`
- Code string `json:"o_code"`
- Msg string `json:"o_msg"`
- ReportDate string `json:"report_date"`
- UpdateDate string `json:"update_date"`
- PrintDate string `json:"print_date"`
- }
- // SyncRankingFromShangHai 上海商品交易所持单排名
- func SyncRankingFromShangHai() {
- var err error
- defer func() {
- if err != nil {
- msg := "失败提醒" + "SyncRankingFromShangHai ErrMsg:" + err.Error()
- fmt.Println("msg:", msg)
- go alarm_msg.SendAlarmMsg(msg, 3)
- }
- }()
- //获取新的指标信息
- for i := 1; i >= 0; i-- {
- var message Message
- var resp BaseResponse
- shUrl := "https://www.shfe.com.cn/data/tradedata/future/dailydata/pm%s.dat"
- date := time.Now().AddDate(0, 0, -i)
- dateStr := date.Format(utils.FormatDateUnSpace)
- shUrl = fmt.Sprintf(shUrl, dateStr)
- utils.FileLog.Info("shUrl:" + shUrl)
- req, _ := http.NewRequest("GET", shUrl, nil)
- req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36")
- client := http.Client{}
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- // 读取响应的内容
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- err = json.Unmarshal(body, &message)
- if err != nil {
- fmt.Println("Unmarshal Err:", err)
- utils.FileLog.Info("Unmarshal Err:" + err.Error())
- continue
- }
- param := make(map[string]interface{})
- param["Date"] = date.Format(utils.FormatDate)
- param["Data"] = message
- urlStr := `exchange_crawler/refresh/sh`
- postUrl := utils.EDB_LIB_URL + urlStr
- postData, err := json.Marshal(param)
- if err != nil {
- utils.FileLog.Info("Marshal Err:" + err.Error())
- fmt.Println(err)
- return
- }
- result, err := HttpPost(postUrl, string(postData), "application/json")
- if err != nil {
- utils.FileLog.Info("HttpPost Err:" + err.Error())
- fmt.Println(err)
- return
- }
- err = json.Unmarshal(result, &resp)
- if err != nil {
- utils.FileLog.Info("Unmarshal resp Err:" + err.Error())
- return
- }
- }
- utils.FileLog.Info("end")
- fmt.Println("end")
- }
- type BaseResponse struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data interface{}
- Success bool `description:"true 执行成功,false 执行失败"`
- IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
- IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
- }
|