feat: 接入 CoinGlass 清算热力图隔离链路
Some checks failed
ci / build + vet + guard + race (push) Has been cancelled
Some checks failed
ci / build + vet + guard + race (push) Has been cancelled
This commit is contained in:
50
internal/controller/restapi/v1/coinglass_routes.go
Normal file
50
internal/controller/restapi/v1/coinglass_routes.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"cryptoHermes/internal/usecase"
|
||||
)
|
||||
|
||||
type CoinglassDeps struct {
|
||||
Enabled bool
|
||||
Query *usecase.CoinglassQueryUsecase
|
||||
}
|
||||
|
||||
func RegisterCoinglass(r fiber.Router, d CoinglassDeps) {
|
||||
g := r.Group("/coinglass")
|
||||
|
||||
g.Get("/liq-heatmap", func(c *fiber.Ctx) error {
|
||||
if !d.Enabled || d.Query == nil {
|
||||
return fiber.NewError(fiber.StatusServiceUnavailable, "service-unavailable: coinglass disabled in config")
|
||||
}
|
||||
|
||||
symbol := strings.ToUpper(strings.TrimSpace(c.Query("symbol")))
|
||||
if symbol == "" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "symbol is required")
|
||||
}
|
||||
|
||||
interval := strings.TrimSpace(c.Query("interval", "5"))
|
||||
if interval == "" {
|
||||
interval = "5"
|
||||
}
|
||||
|
||||
limit := 288
|
||||
if l := c.Query("limit"); l != "" {
|
||||
v, err := strconv.Atoi(l)
|
||||
if err != nil || v <= 0 || v > 1000 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "limit must be between 1 and 1000")
|
||||
}
|
||||
limit = v
|
||||
}
|
||||
|
||||
rows, err := d.Query.GetLiqHeatMap(c.UserContext(), symbol, interval, limit)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return c.JSON(rows)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user