From 8a0050998751cc28c339bdeeb7c190dc03bc2fa2 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 Dec 2021 19:44:07 +0800 Subject: [PATCH] kucoin: check data pointer and return error --- pkg/exchange/kucoin/kucoinapi/trade.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/exchange/kucoin/kucoinapi/trade.go b/pkg/exchange/kucoin/kucoinapi/trade.go index 1ea93b5c4..dd3c91952 100644 --- a/pkg/exchange/kucoin/kucoinapi/trade.go +++ b/pkg/exchange/kucoin/kucoinapi/trade.go @@ -356,16 +356,20 @@ func (r *CancelOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, erro return nil, err } - var orderResponse struct { + var apiResponse struct { Code string `json:"code"` Message string `json:"msg"` Data *CancelOrderResponse `json:"data"` } - if err := response.DecodeJSON(&orderResponse); err != nil { + if err := response.DecodeJSON(&apiResponse); err != nil { return nil, err } - return orderResponse.Data, nil + if apiResponse.Data == nil { + return nil, errors.New("api error: [" + apiResponse.Code + "] " + apiResponse.Message) + } + + return apiResponse.Data, nil } type CancelAllOrderRequest struct { @@ -392,17 +396,21 @@ func (r *CancelAllOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, e return nil, err } - var orderResponse struct { + var apiResponse struct { Code string `json:"code"` Message string `json:"msg"` Data *CancelOrderResponse `json:"data"` } - if err := response.DecodeJSON(&orderResponse); err != nil { + if err := response.DecodeJSON(&apiResponse); err != nil { return nil, err } - return orderResponse.Data, nil + if apiResponse.Data == nil { + return nil, errors.New("api error: [" + apiResponse.Code + "] " + apiResponse.Message) + } + + return apiResponse.Data, nil } // Request via this endpoint to place 5 orders at the same time.