freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
28.08k stars 6.02k forks source link

Error - kucoin fetchOrderBook limit argument must be None, 20 or 100 #4723

Closed cydantor856 closed 3 years ago

cydantor856 commented 3 years ago

Describe your environment

Your question

I tried a strategy with live account which using order book enabled in kucoin exchange. below are the related config if helps

"bid_strategy": {
    "ask_last_balance": 1.0,
    "use_order_book": true,
    "order_book_top": 1,
    "check_depth_of_market": {
        "enabled": false,
        "bids_to_ask_delta": 1
    }
},
"ask_strategy": {
    "use_order_book": false,
    "order_book_min": 1,
    "order_book_max": 1,
    "use_sell_signal": true,
    "sell_profit_only": false,
    "ignore_roi_if_buy_signal": false
},

related terminal messages are here :

2021-04-12 10:37:11,382 - freqtrade.freqtradebot - INFO - Buy signal found: about create a new trade with stake_amount: 0.0012924855900000001 ... 2021-04-12 10:37:11,382 - freqtrade.freqtradebot - INFO - Executing Buy for VID/BTC 2021-04-12 10:37:11,382 - freqtrade.freqtradebot - INFO - Getting price from order book Bid side. 2021-04-12 10:37:11,383 - freqtrade.exchange.common - WARNING - fetch_l2_order_book() returned exception: "Could not get order book due to ExchangeError. Message: kucoin fetchOrderBook limit argument must be None, 20 or 100" 2021-04-12 10:37:11,383 - freqtrade.exchange.common - WARNING - retrying fetch_l2_order_book() still for 4 times 2021-04-12 10:37:11,383 - freqtrade.exchange.common - WARNING - fetch_l2_order_book() returned exception: "Could not get order book due to ExchangeError. Message: kucoin fetchOrderBook limit argument must be None, 20 or 100" 2021-04-12 10:37:11,384 - freqtrade.exchange.common - WARNING - retrying fetch_l2_order_book() still for 3 times 2021-04-12 10:37:11,384 - freqtrade.exchange.common - WARNING - fetch_l2_order_book() returned exception: "Could not get order book due to ExchangeError. Message: kucoin fetchOrderBook limit argument must be None, 20 or 100" 2021-04-12 10:37:11,384 - freqtrade.exchange.common - WARNING - retrying fetch_l2_order_book() still for 2 times 2021-04-12 10:37:11,385 - freqtrade.exchange.common - WARNING - fetch_l2_order_book() returned exception: "Could not get order book due to ExchangeError. Message: kucoin fetchOrderBook limit argument must be None, 20 or 100" 2021-04-12 10:37:11,385 - freqtrade.exchange.common - WARNING - retrying fetch_l2_order_book() still for 1 times 2021-04-12 10:37:11,385 - freqtrade.exchange.common - WARNING - fetch_l2_order_book() returned exception: "Could not get order book due to ExchangeError. Message: kucoin fetchOrderBook limit argument must be None, 20 or 100" 2021-04-12 10:37:11,386 - freqtrade.exchange.common - WARNING - Giving up retrying: fetch_l2_order_book() 2021-04-12 10:37:11,386 - f

FYI in dry run mode all works just fine which does not use order book at all. Only this occur when I try live with order book with above config. And also key related I use structure lise this

"exchange": {
    "name": "kucoin",
    "key": "api key here",
    "secret": "api secret here",
    "password": "api passphrase here", 
},
xmatthias commented 3 years ago

For quick help - simply set "use_order_book" to false? Kucoin is not an officially supported exchange - so while it may work, certain things may not (like orderbook apparently) due to some exchange specifics.

Apart from that (in general, not necessarily related to this exchange in particular) - you should use use_order_book consistently across buy and sell settings, otherwise you might encounter some odd effects (its not guaranteed the 2 values are 100% aligned by the exchange api's ... ).

cydantor856 commented 3 years ago

FYI, i tried use_order_book to false in the live run and it works fine but I would like to use use_order_book in order to get a better entry price etc if possible. Can I know if this has to be fixed at kucoin or ccxt or freqtrade end? i tried even adding ccxt settings like below but not luck. don't know if I put it in the right manner.

"exchange": {
    "name": "kucoin",
    "key": "",
    "secret": "",
    "password": "",

     "ccxt_config": {
         "enableRateLimit": true,
         "limit ": 20
     },
     "ccxt_async_config": {
         "enableRateLimit": true,
         "rateLimit": 200,
         "limit ": 20
     }
},

I found this link in ccxt issues section and I am bit confused how to implement the code as mentioned there in freqtrade. kindly have a look : https://github.com/ccxt/ccxt/issues/8138

I feel like freqtrade code has to be modified according to those changes. i saw similar incident regarding bittrex at : https://github.com/freqtrade/freqtrade/issues/3865

Additionally, unlike Binance exchange settings, I had to add a password tag to the exchange config for the passphrase created at kucoin for each API other than key and secret (mentioned in the first post) so I think it is better if you can mention that on exchange specific notes section on freqtrade website. normally in Binance settings, we do not have to use the password attribute. that's why.

xmatthias commented 3 years ago

@cydantor856 please IMMEDIATELY revoke your exchange keys - i edited them out from the above post - but they'll stil be in the history.

xmatthias commented 3 years ago

Yes, it'll either need a custom setting (for kucoin) - or a change (subclassing) for the kucoin exchange.

It's not something that can be done by ccxt, but should be handled at freqtrade level (we do however not have the capacity to test all exchanges / implement all "oddities" for all exchanges).

in theory, you should be able to add the following to your exchange config:

"_ft_has_params": {
   "l2_limit_range": [20, 100]
}

Additionally, unlike Binance exchange settings, I had to add a password tag to the exchange config for the passphrase created at kucoin for each API other than key and secret (mentioned in the first post) so I think it is better if you can mention that on exchange specific notes section on freqtrade website. normally in Binance settings, we do not have to use the password attribute. that's why.

You're correct, it's not mentioned, you're probably the first to use the kucoin exchange - and exchange-specific notes are there only for actively supported exchanges as they may have to change over time - and i can't maintain these notes for exchanges i don't use.

cydantor856 commented 3 years ago

hi thanks a lot for reminding exchange keys. and kucoin is also very popular exchange and the fifth one at cmc ranking : https://coinmarketcap.com/rankings/exchanges/ just after big exchanges binance, coinbase, kraken etc. and lots of people using kucoin because it has listed lots of coins comparing other exchanges FYI. Please kindly if possible add the necessary kucoin specific changes to freqtrade code according to your schedule. love your work and thanks a lot for the support. i will check _ft_has_params and let you know status.

cydantor856 commented 3 years ago

_ft_has_params seems to do the trick for now. Thanks a lot. I added as below in exchange config and running on live mode at the moment and I can confirm that error kucoin fetchOrderBook limit argument must be None, 20 or 100 not happening.

    "_ft_has_params": {
        "l2_limit_range": [
            20,
            100
        ]
    }
xmatthias commented 3 years ago

With the latest develop version this should now work without this "config fix/hack".

obviously it'll populate to the next release ....