diff --git a/app/admin/service/line_pre_order.go b/app/admin/service/line_pre_order.go index ba8601d..2afa552 100644 --- a/app/admin/service/line_pre_order.go +++ b/app/admin/service/line_pre_order.go @@ -26,6 +26,7 @@ import ( "go-admin/app/admin/models" "go-admin/app/admin/service/dto" + "go-admin/app/admin/service/messages" "go-admin/common/actions" cDto "go-admin/common/dto" ) @@ -1378,23 +1379,37 @@ func (e *LinePreOrder) SetBinanceMarginType(req *dto.MarginTypeReq, users []mode "marginType": req.MarginType, "symbol": s, } - resp, _, err := client.SendFuturesRequestAuth("/fapi/v1/marginType", "POST", params) + _, _, err := client.SendFuturesRequestAuth("/fapi/v1/marginType", "POST", params) if err != nil { - *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, err.Error())) - continue - } - var dataMap map[string]interface{} - if err := sonic.Unmarshal(resp, &dataMap); err != nil { - *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, err.Error())) - continue - } - code, ok := dataMap["code"] - if !ok { - *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, dataMap["message"])) - continue - } - if code.(float64) != 200 { - *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, dataMap["message"])) + var dataMap map[string]interface{} + if err := sonic.Unmarshal([]byte(err.Error()), &dataMap); err != nil { + *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, err.Error())) + continue + } + code, ok := dataMap["code"] + if !ok { + *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, dataMap["message"])) + continue + } + + if code.(float64) != 200 { + var msg string + codeInt := utility.ToInt(code) + + if codeInt == -4046 { + continue + } + + if val, ok := messages.BinanceFutureMessage[codeInt]; ok { + msg = val + } else { + msg = dataMap["message"].(string) + } + + *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, msg)) + continue + } + // *errs = append(*errs, fmt.Errorf("api_id:%d 交易对:%s 设置仓位失败:%+v", user.Id, s, err.Error())) continue } } diff --git a/app/admin/service/messages/binance_message.go b/app/admin/service/messages/binance_message.go new file mode 100644 index 0000000..4aeda26 --- /dev/null +++ b/app/admin/service/messages/binance_message.go @@ -0,0 +1,7 @@ +package messages + +var BinanceFutureMessage = map[int]string{ + -4168: "多资产模式下无法使用逐仓", + -4167: "因有交易对在逐仓模式,无法切换多资产模式", + -4046: "不需要切换仓位模式。", +} diff --git a/services/binanceservice/spotsymbolservice.go b/services/binanceservice/spotsymbolservice.go index cd1948a..0871fb2 100644 --- a/services/binanceservice/spotsymbolservice.go +++ b/services/binanceservice/spotsymbolservice.go @@ -45,7 +45,7 @@ func GetSpotSymbols() (map[string]models.TradeSet, []string, error) { tradeSet.MaxQty = utility.StringAsFloat(filter.MaxQty) case "MARKET_LOT_SIZE": tradeSet.MarketMinQty = utility.StringAsFloat(filter.MinQty) - tradeSet.MarketMinQty = utility.StringAsFloat(filter.MaxQty) + tradeSet.MarketMaxQty = utility.StringAsFloat(filter.MaxQty) } }