51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
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)
|
|
})
|
|
}
|