hummingbot: Kucoin - Failed to query trading fees when its running on more than 10 trading pairs

Describe the bug According to Kucoin API doc, its endpoint for trading pair can only handle up to 10 trading pairs at a time. Reference as follows:
https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair

But current implementation _update_trading_fees from kucoin_exchange.py feeds all trading pairs in one call regardless of number of trading pairs from inputs. Therefore, the function raises an error when hummingbot is trading 10+ trading pairs on Kucoin.

Steps To Reproduce Run the following script base bot:

TRADING_PAIRS: Set[str] = set(
    [
        "XRP-USDT",
        "ARB-USDT",
        "USDC-USDT",
        "SOL-USDT",
        "MATIC-USDT",
        "FTM-USDT",
        "LTC-USDT",
        "TON-USDT",
        "APT-USDT",
        "DOGE-USDT",
        "AGIX-USDT",
        "SHIB-USDT",
        "MASK-USDT",
        "STX-USDT",
        "VRA-USDT",
        "BNB-USDT",
        "OP-USDT",
        "ADA-USDT",
        "LUNC-USDT",
        "LDO-USDT",
        "TRX-USDT",
        "SUN-USDT",
        "ATOM-USDT",
        "DYDX-USDT",
        "LINK-USDT",
        "AVAX-USDT",
        "HFT-USDT",
        "EOS-USDT",
        "DOT-USDT",
        "XLM-USDT",
        "ALGO-USDT",
        "BUSD-USDT",
        "LUNA-USDT",
        "APE-USDT",
        "IMX-USDT",
        "FIL-USDT",
        "USTC-USDT",
        "INJ-USDT",
        "BLUR-USDT",
        "ID-USDT",
        "RNDR-USDT",
        "JASMY-USDT",
        "NEAR-USDT",
        "BTC3L-USDT",
        "GRT-USDT",
        "ACH-USDT",
        "MAGIC-USDT",
        "SAND-USDT",
    ]
)

class TestingScriptBase(ScriptStrategyBase):
    trading_pairs = TRADING_PAIRS
    markets = {
        "kucoin": TRADING_PAIRS
    }

	def on_tick(self):
		return

Screenshots NA

Release version dev-1.14.0

Attachments Error Messages:

Traceback (most recent call last):
  File "/home/alexlauwh/hummingbot/hummingbot/connector/exchange_py_base.py", line 785, in _trading_fees_polling_loop
    await safe_gather(self._update_trading_fees())
  File "/home/alexlauwh/hummingbot/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/alexlauwh/hummingbot/hummingbot/connector/exchange/kucoin/kucoin_exchange.py", line 377, in _update_trading_fees
    raise e
  File "/home/alexlauwh/hummingbot/hummingbot/connector/exchange/kucoin/kucoin_exchange.py", line 374, in _update_trading_fees
    fees_json = resp["data"]
KeyError: 'data'

WARNING: Do NOT publish any exchange API keys or your wallet’s private key. Whoever has access to them may steal your assets!

Propose Solutions I made a fix to this in my codebase:

    async def _update_trading_fees(self):
        trading_symbols = [
            await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
            for trading_pair in self._trading_pairs
        ]
        fees_json = []
        for idx in range(0, len(trading_symbols), 10):
            tmp_trading_symbols = trading_symbols[idx : idx + 10]
            params = {"symbols": ",".join(tmp_trading_symbols)}
            resp = await self._api_get(
                path_url=CONSTANTS.FEE_PATH_URL,
                params=params,
                is_auth_required=True,
            )
            try:
                tmp_fees_json = resp["data"]
                fees_json.extend(tmp_fees_json)
            except KeyError as e:
                self.logger().error(f"Error fetching trading fees. Response: {resp}. Error: {e}.")
                raise e

        for fee_json in fees_json:
            trading_pair = await self.trading_pair_associated_to_exchange_symbol(symbol=fee_json["symbol"])
            self._trading_fees[trading_pair] = fee_json

I can make a PR to fix this if you agree

Optional: your discord username: alex_lau#8125

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@riven314 please fill up & submit the AML Policy Form via this link: https://forms.gle/ZeSRvWUU3gBeHPbH6 This is a one-time process for each ETH Address used to receive HBOT bounty.

@riven314 https://docs.hummingbot.org/governance/bounties/#submission Afterwards, Foundation will run tests to assess the fix and conduct an engineering review to ensure it can be merged into the codebase safely.

;P https://github.com/hummingbot/hummingbot/pull/5321 (Not so good proposal)

Your proposal looks good