Reduce KuCoin logs on DDosProtection error messages
KuCoin APIs generate A LOT of error messages. Consequently, logs are flooded with lines like: 2021-12-25 22:30:23 freqtrade.exchange.common: WARNING - _async_get_candle_history() returned exception: "kucoin GET https://openapi-v2.kucoin.com/api/v1/market/candles? symbol=PDEX-USDT&type=5min&startAt=1640317818&endAt=1640467818 429 Too Many Requests {"code":"429000","msg":"Too Many Requests"}" 2021-12-25 22:30:23 freqtrade.exchange.common: WARNING - retrying _async_get_candle_history() still for 3 times 2021-12-25 22:30:23 freqtrade.exchange.common: WARNING - Kucoin 429 error, avoid triggering DDosProtection backoff delay. 2 tries left before giving up 2021-12-25 22:30:24 freqtrade.exchange.common: WARNING - _async_get_candle_history() returned exception: "kucoin GET https://openapi-v2.kucoin.com/api/v1/market/candles? symbol=UBX-USDT&type=5min&startAt=1640317821&endAt=1640467821 429 Too Many Requests {"code":"429000","msg":"Too Many Requests"}" Messages like: Kucoin 429 error, avoid triggering DDosProtection backoff delay. are logged only once for a certain period of time (default is 3600 seconds).
This commit is contained in:
parent
58663180e0
commit
96fbf63d0b
@ -1,12 +1,15 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from functools import wraps
|
from functools import partial, wraps
|
||||||
|
|
||||||
from freqtrade.exceptions import DDosProtection, RetryableOrderError, TemporaryError
|
from freqtrade.exceptions import DDosProtection, RetryableOrderError, TemporaryError
|
||||||
|
from freqtrade.mixins import LoggingMixin
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
logging_mixin = LoggingMixin(logger)
|
||||||
|
log_once_warning = partial(logging_mixin.log_once, logmethod=logger.warning)
|
||||||
|
|
||||||
|
|
||||||
# Maximum default retry count.
|
# Maximum default retry count.
|
||||||
@ -84,7 +87,7 @@ def retrier_async(f):
|
|||||||
if "kucoin" in str(ex) and "429000" in str(ex):
|
if "kucoin" in str(ex) and "429000" in str(ex):
|
||||||
# Temporary fix for 429000 error on kucoin
|
# Temporary fix for 429000 error on kucoin
|
||||||
# see https://github.com/freqtrade/freqtrade/issues/5700 for details.
|
# see https://github.com/freqtrade/freqtrade/issues/5700 for details.
|
||||||
logger.warning(
|
log_once_warning(
|
||||||
f"Kucoin 429 error, avoid triggering DDosProtection backoff delay. "
|
f"Kucoin 429 error, avoid triggering DDosProtection backoff delay. "
|
||||||
f"{count} tries left before giving up")
|
f"{count} tries left before giving up")
|
||||||
else:
|
else:
|
||||||
|
@ -1740,6 +1740,28 @@ async def test__async_get_candle_history(default_conf, mocker, caplog, exchange_
|
|||||||
(arrow.utcnow().int_timestamp - 2000) * 1000)
|
(arrow.utcnow().int_timestamp - 2000) * 1000)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test__async_kucoin_get_candle_history(default_conf, mocker, caplog):
|
||||||
|
caplog.set_level(logging.INFO)
|
||||||
|
api_mock = MagicMock()
|
||||||
|
|
||||||
|
assert not log_has_re('Kucoin 429 error, avoid triggering DDosProtection backoff delay.*',
|
||||||
|
caplog)
|
||||||
|
|
||||||
|
for _ in range(3):
|
||||||
|
with pytest.raises(DDosProtection, match=r'429 Too Many Requests'):
|
||||||
|
api_mock.fetch_ohlcv = MagicMock(side_effect=ccxt.DDoSProtection(
|
||||||
|
"kucoin GET https://openapi-v2.kucoin.com/api/v1/market/candles?"
|
||||||
|
"symbol=ETH-BTC&type=5min&startAt=1640268735&endAt=1640418735"
|
||||||
|
"429 Too Many Requests" '{"code":"429000","msg":"Too Many Requests"}'))
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kucoin")
|
||||||
|
await exchange._async_get_candle_history(
|
||||||
|
'ETH/BTC', "5m", (arrow.utcnow().int_timestamp - 2000) * 1000, count=1)
|
||||||
|
logs_found = sum('Kucoin 429 error, avoid triggering DDosProtection backoff delay' in message
|
||||||
|
for message in caplog.messages)
|
||||||
|
assert logs_found == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test__async_get_candle_history_empty(default_conf, mocker, caplog):
|
async def test__async_get_candle_history_empty(default_conf, mocker, caplog):
|
||||||
""" Test empty exchange result """
|
""" Test empty exchange result """
|
||||||
|
Loading…
Reference in New Issue
Block a user