package excservice

import (
	"go-admin/pkg/httputils"

	"github.com/bytedance/sonic"
	"go.uber.org/zap"

	log "github.com/go-admin-team/go-admin-core/logger"
)

var (
//	DefaultHttpClientConfig = &HttpClientConfig{
//		Proxy:        nil,
//		HttpTimeout:  5 * time.Second,
//		MaxIdleConns: 10}
)
var (
	timeOffset int64 = 0
)

//var INERNAL_KLINE_PERIOD_CONVERTER = map[int]string{
//	models.KLINE_1MIN:  "1m",
//	models.KLINE_3MIN:  "3m",
//	models.KLINE_5MIN:  "5m",
//	models.KLINE_15MIN: "15m",
//	models.KLINE_30MIN: "30m",
//	models.KLINE_60MIN: "1h",
//	//models.KLINE_1H:     "1h",
//	models.KLINE_2H:     "2h",
//	models.KLINE_4H:     "4h",
//	models.KLINE_6H:     "6h",
//	models.KLINE_8H:     "8h",
//	models.KLINE_12H:    "12h",
//	models.KLINE_1DAY:   "1d",
//	models.KLINE_3DAY:   "3d",
//	models.KLINE_1WEEK:  "1w",
//	models.KLINE_1MONTH: "1M",
//}

type Filter struct {
	FilterType     string `json:"filterType"`
	MaxPrice       string `json:"maxPrice"`
	MinPrice       string `json:"minPrice"`
	TickSize       string `json:"tickSize"`
	MultiplierUp   string `json:"multiplierUp,string"`
	MultiplierDown string `json:"multiplierDown,string"`
	MinQty         string `json:"minQty"`
	MaxQty         string `json:"maxQty"`
	StepSize       string `json:"stepSize"`
	MinNotional    string `json:"minNotional"`
}

//
//type RateLimit struct {
//	Interval      string `json:"interval"`
//	IntervalNum   int64  `json:"intervalNum"`
//	Limit         int64  `json:"limit"`
//	RateLimitType string `json:"rateLimitType"`
//}

type TradeSymbol struct {
	Symbol                   string   `json:"symbol"`
	Status                   string   `json:"status"`
	BaseAsset                string   `json:"baseAsset"`           //基础币种
	QuoteAsset               string   `json:"quoteAsset"`          //计价币种
	BaseAssetPrecision       int      `json:"baseAssetPrecision"`  //基础币种小数点位数
	QuotePrecision           int      `json:"quotePrecision"`      //价格小数点位数 添加新字段 quoteAssetPrecision。此字段和 quotePrecision 重复。在未来的版本(v4)中 quotePrecision 会被移除
	QuoteAssetPrecision      int      `json:"quoteAssetPrecision"` //
	BaseCommissionPrecision  int      `json:"baseCommissionPrecision"`
	QuoteCommissionPrecision int      `json:"quoteCommissionPrecision"`
	OrderTypes               []string `json:"orderTypes"`
	Filters                  []Filter `json:"filters"`
}
type ExchangeInfo struct {
	Timezone   string `json:"timezone"`
	ServerTime int    `json:"serverTime"`
	//ExchangeFilters []interface{} `json:"exchangeFilters,omitempty"`
	//RateLimits      []RateLimit   `json:"rateLimits"`
	Symbols []TradeSymbol `json:"symbols"`
}

// 获取exchangeInfo
func GetExchangeInfoPro() ([]TradeSymbol, error) {
	respData, err := httputils.NewHttpRequestWithFasthttp("GET", apiUrl+"/api/v3/exchangeInfo", "", nil)
	if err != nil {
		log.Error("获取exchangeInfo", zap.Error(err))
		return nil, err
	}
	var info ExchangeInfo
	sonic.Unmarshal(respData, &info)

	return info.Symbols, nil
}
