mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 23:16:48 +00:00
kucoin: Fix fetching fee rates for multiple pairs (#1370)
* kucoin: Fix fetching fee rates for multiple pairs * Update exchanges/kucoin/kucoin_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * NITS: WOW * glorious: nits --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -1647,13 +1647,14 @@ func (ku *Kucoin) GetBasicFee(ctx context.Context, currencyType string) (*Fees,
|
||||
}
|
||||
|
||||
// GetTradingFee get fee rate of trading pairs
|
||||
func (ku *Kucoin) GetTradingFee(ctx context.Context, symbols string) ([]Fees, error) {
|
||||
params := url.Values{}
|
||||
if symbols != "" {
|
||||
params.Set("symbols", symbols)
|
||||
// WARNING: There is a limit of 10 currency pairs allowed to be requested per call.
|
||||
func (ku *Kucoin) GetTradingFee(ctx context.Context, pairs currency.Pairs) ([]Fees, error) {
|
||||
if len(pairs) == 0 {
|
||||
return nil, currency.ErrCurrencyPairsEmpty
|
||||
}
|
||||
path := kucoinTradingFee + "?symbols=" + pairs.Upper().Join()
|
||||
var resp []Fees
|
||||
return resp, ku.SendAuthHTTPRequest(ctx, exchange.RestSpot, defaultSpotEPL, http.MethodGet, common.EncodeURLValues(kucoinTradingFee, params), nil, &resp)
|
||||
return resp, ku.SendAuthHTTPRequest(ctx, exchange.RestSpot, defaultSpotEPL, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
|
||||
@@ -1096,11 +1096,45 @@ func TestGetBasicFee(t *testing.T) {
|
||||
|
||||
func TestGetTradingFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := ku.GetTradingFee(context.Background(), nil)
|
||||
if !errors.Is(err, currency.ErrCurrencyPairsEmpty) {
|
||||
t.Fatalf("received %v, expected %v", err, currency.ErrCurrencyPairsEmpty)
|
||||
}
|
||||
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, ku)
|
||||
|
||||
_, err := ku.GetTradingFee(context.Background(), "BTC-USDT")
|
||||
avail, err := ku.GetAvailablePairs(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("GetTradingFee() error", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pairs := currency.Pairs{avail[0]}
|
||||
btcusdTradingFee, err := ku.GetTradingFee(context.Background(), pairs)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received %v, expected %v", err, nil)
|
||||
}
|
||||
|
||||
if len(btcusdTradingFee) != 1 {
|
||||
t.Error("GetTradingFee() error, expected 1 pair")
|
||||
}
|
||||
|
||||
// NOTE: Test below will error out from an external call as this will exceed
|
||||
// the allowed pairs. If this does not error then this endpoint will allow
|
||||
// more items to be requested.
|
||||
pairs = append(pairs, avail[1:11]...)
|
||||
_, err = ku.GetTradingFee(context.Background(), pairs)
|
||||
if errors.Is(err, nil) {
|
||||
t.Fatalf("received %v, expected %v", err, "code: 200000 message: symbols size invalid.")
|
||||
}
|
||||
|
||||
got, err := ku.GetTradingFee(context.Background(), pairs[:10])
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received %v, expected %v", err, nil)
|
||||
}
|
||||
|
||||
if len(got) != 10 {
|
||||
t.Error("GetTradingFee() error, expected 10 pairs")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,14 @@ func (e Error) GetError() error {
|
||||
return err
|
||||
}
|
||||
switch code {
|
||||
case 200000, 200:
|
||||
case 200:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("code: %s message: %s", e.Code, e.Msg)
|
||||
case 200000:
|
||||
if e.Msg == "" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("code: %s message: %s", e.Code, e.Msg)
|
||||
}
|
||||
|
||||
// SymbolInfo stores symbol information
|
||||
|
||||
@@ -1351,7 +1351,7 @@ func (ku *Kucoin) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuil
|
||||
switch feeBuilder.FeeType {
|
||||
case exchange.CryptocurrencyWithdrawalFee,
|
||||
exchange.CryptocurrencyTradeFee:
|
||||
fee, err := ku.GetTradingFee(ctx, feeBuilder.Pair.String())
|
||||
fee, err := ku.GetTradingFee(ctx, currency.Pairs{feeBuilder.Pair})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user