binance-trade-bot icon indicating copy to clipboard operation
binance-trade-bot copied to clipboard

Fix fees for US tld

Open Blaklis opened this issue 3 years ago • 9 comments

The API on Binance.us is buggy and return an empty list. They say that "not everyone can access this api" but they have no details, nor any ETA in resolving the issue. Let's default to 0.001 in that case.

Blaklis avatar Apr 13 '21 22:04 Blaklis

Hey @Blaklis, why this default exactly? Could you link a resource specifying this as an acceptable value?

rel-s avatar May 11 '21 08:05 rel-s

0.001 is the default fee on Binance (0.1%).

https://www.binance.us/en/fee/schedule

Blaklis avatar May 12 '21 22:05 Blaklis

Adding #235

Also, @CryptoIsGarbage is correct on the function in the next section failing. I had to comment out the existing code and simply set base_fee = 0.001

def get_fee(self, origin_coin: Coin, target_coin: Coin, selling: bool):
        # fees = self.get_trade_fee()
        # if not fees:
        base_fee = 0.001

        # base_fee = self.get_trade_fees()[origin_coin + target_coin]
        # if not self.get_using_bnb_for_fees():
            # return base_fee

        # The discount is only applied if we have enough BNB to cover the fee
        amount_trading = (
            self._sell_quantity(origin_coin.symbol, target_coin.symbol)
            if selling
            else self._buy_quantity(origin_coin.symbol, target_coin.symbol)
        )

        fee_amount = amount_trading * base_fee * 0.75
        if origin_coin.symbol == "BNB":
            fee_amount_bnb = fee_amount
        else:
            origin_price = self.get_ticker_price(origin_coin + Coin("BNB"))
            if origin_price is None:
                return base_fee
            fee_amount_bnb = fee_amount * origin_price

        bnb_balance = self.get_currency_balance("BNB")

        if bnb_balance >= fee_amount_bnb:
            return base_fee * 0.75
        return base_fee

Amraki avatar May 20 '21 11:05 Amraki

Do you have any log that demonstrates it failing on US tld?

Blaklis avatar May 20 '21 11:05 Blaklis

Full log:

ERROR:crypto_trading_logger:Error while scouting...
Traceback (most recent call last):
  File "/app/binance_trade_bot/scheduler.py", line 25, in _run_job
    super()._run_job(job)
  File "/usr/local/lib/python3.9/site-packages/schedule/__init__.py", line 172, in _run_job
    ret = job.run()
  File "/usr/local/lib/python3.9/site-packages/schedule/__init__.py", line 661, in run
    ret = self.job_func()
  File "/app/binance_trade_bot/strategies/default_strategy.py", line 32, in scout
    self._jump_to_best_coin(current_coin, current_coin_price)
  File "/app/binance_trade_bot/auto_trader.py", line 159, in _jump_to_best_coin
    pair_ratios = self._get_ratios(coin, coin_price)
  File "/app/binance_trade_bot/auto_trader.py", line 146, in _get_ratios
    transaction_fee = self.manager.get_fee(pair.from_coin, self.config.BRIDGE, True) + self.manager.get_fee(
  File "/app/binance_trade_bot/binance_api_manager.py", line 55, in get_fee
    if not self.get_using_bnb_for_fees():
  File "/usr/local/lib/python3.9/site-packages/cachetools/decorators.py", line 26, in wrapper
    v = func(*args, **kwargs)
  File "/app/binance_trade_bot/binance_api_manager.py", line 47, in get_using_bnb_for_fees
    return self.binance_client.get_bnb_burn_spot_margin()["spotBNBBurn"]
  File "/usr/local/lib/python3.9/site-packages/binance/client.py", line 3080, in get_bnb_burn_spot_margin
    return self._request_margin_api('get', 'bnbBurn', signed=True, data=params)
  File "/usr/local/lib/python3.9/site-packages/binance/client.py", line 275, in _request_margin_api
    return self._request(method, uri, signed, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/binance/client.py", line 260, in _request
    return self._handle_response()
  File "/usr/local/lib/python3.9/site-packages/binance/client.py", line 313, in _handle_response
    raise BinanceAPIException(self.response)
  File "/usr/local/lib/python3.9/site-packages/binance/exceptions.py", line 13, in __init__
    self.code = json_res['code']
KeyError: 'code'

CryptoIsGarbage avatar May 20 '21 11:05 CryptoIsGarbage

Yes, posted to #235 we just came from: https://github.com/edeng23/binance-trade-bot/issues/235#issuecomment-844655407

Amraki avatar May 20 '21 12:05 Amraki

Thanks, I'll introduce a new patch soon!

Blaklis avatar May 20 '21 12:05 Blaklis

Awesome, thanks for the help!

Will be glad to see a few Issues get knocked off the list.

Amraki avatar May 20 '21 12:05 Amraki

This should be fixed now - sorry for the delay.

Blaklis avatar Oct 28 '21 21:10 Blaklis