diff --git a/internal/tick_recv.go b/internal/tick_recv.go index dd049ba..c348ae9 100644 --- a/internal/tick_recv.go +++ b/internal/tick_recv.go @@ -10,6 +10,28 @@ import ( "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() @@ -21,7 +43,7 @@ func TickRecv(c *gin.Context) { return } - data := map[string]any{} + data := map[string]Tick{} // Gin 的 Bind 方法会自动根据 Content-Type 解析 if err := c.Bind(&data); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -30,7 +52,10 @@ func TickRecv(c *gin.Context) { for key, value := range data { if utils.ArrayInString(key, stocks) { - RedisService.Set(key, value, 1*time.Hour) + err := RedisService.Set(key, value, 1*time.Hour) + if err != nil { + log.Println("Error: Redis Set", err.Error()) + } } }