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:
52
internal/repo/webapi/coinglass/liq_heatmap.go
Normal file
52
internal/repo/webapi/coinglass/liq_heatmap.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package coinglass
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"cryptoHermes/internal/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
liqHeatMapPath = "/api/index/v2/liqHeatMap"
|
||||
defaultLiqInterval = "5"
|
||||
defaultLiqLimit = 288
|
||||
maxLiqHeatMapLimit = 1000
|
||||
cgBinanceSymbolPrefix = "Binance_"
|
||||
)
|
||||
|
||||
func (c *Client) GetLiqHeatMap(ctx context.Context, symbol, interval string, limit int) (*entity.CGLiqHeatMap, error) {
|
||||
symbol = normalizeBinanceMarketSymbol(symbol)
|
||||
if interval == "" {
|
||||
interval = defaultLiqInterval
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = defaultLiqLimit
|
||||
}
|
||||
if limit > maxLiqHeatMapLimit {
|
||||
limit = maxLiqHeatMapLimit
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("merge", "true")
|
||||
q.Set("symbol", coinglassBinanceSymbol(symbol))
|
||||
q.Set("interval", interval)
|
||||
q.Set("limit", strconv.Itoa(limit))
|
||||
|
||||
plaintext, err := c.GetPlaintext(ctx, liqHeatMapPath, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return MapLiqHeatMap(symbol, interval, c.now().UnixMilli(), plaintext)
|
||||
}
|
||||
|
||||
func coinglassBinanceSymbol(symbol string) string {
|
||||
return cgBinanceSymbolPrefix + symbol
|
||||
}
|
||||
|
||||
func normalizeBinanceMarketSymbol(symbol string) string {
|
||||
symbol = strings.ToUpper(strings.TrimSpace(symbol))
|
||||
return strings.TrimPrefix(symbol, "BINANCE_")
|
||||
}
|
||||
Reference in New Issue
Block a user