package internal import ( "encoding/json" "log" "net/http" "time" "git.apinb.com/bsm-sdk/core/utils" "github.com/gin-gonic/gin" ) // Tick 行情数据 type Tick struct { LastPrice float64 `json:"lastPrice"` Open float64 `json:"open"` High float64 `json:"high"` Low float64 `json:"low"` LastClose float64 `json:"lastClose"` Volume int64 `json:"volume"` Amount float64 `json:"amount"` PVolume int64 `json:"pvolume"` BidPrice []float64 `json:"bidPrice"` BidVol []int `json:"bidVol"` AskPrice []float64 `json:"askPrice"` AskVol []int `json:"askVol"` Time int64 `json:"time"` TimeTag string `json:"timetag"` StockStatus int `json:"stockStatus"` LastSettlementPrice float64 `json:"lastSettlementPrice"` SettlementPrice float64 `json:"settlementPrice"` OpenInt int `json:"openInt"` } func TickRecv(c *gin.Context) { log.Println("TickRecv called") stocks := GetAllowStocks() if len(stocks) == 0 { c.JSON(http.StatusOK, gin.H{ "status": "OK", "num": len(stocks), }) return } data := map[string]Tick{} // Gin 的 Bind 方法会自动根据 Content-Type 解析 if err := c.Bind(&data); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } for key, value := range data { if utils.ArrayInString(key, stocks) { err := RedisService.Set(key, value, 1*time.Hour) if err != nil { log.Println("Error: Redis Set", err.Error()) } } } // 处理数据... c.JSON(http.StatusOK, gin.H{ "status": "OK", }) } func GetAllowStocks() []string { result, err := utils.HttpGet("http://139.224.247.176:13499/a/pass_codes") if err != nil { log.Println("Error: Http Get pass_codes", err.Error()) return nil } var stocks []string err = json.Unmarshal(result, &stocks) if err != nil { log.Println("Error: Json Unmarshal pass_codes", err.Error()) return nil } return stocks }