Parametrize fetch_order retry counts

This commit is contained in:
Matthias 2020-08-22 17:35:42 +02:00
parent 3d7e800ff2
commit 674b510d23
6 changed files with 23 additions and 19 deletions

View File

@ -9,7 +9,11 @@ from freqtrade.exceptions import (DDosProtection, RetryableOrderError,
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Maximum default retry count.
# Functions are always called RETRY_COUNT + 1 times (for the original call)
API_RETRY_COUNT = 4 API_RETRY_COUNT = 4
API_FETCH_ORDER_RETRY_COUNT = 3
BAD_EXCHANGES = { BAD_EXCHANGES = {
"bitmex": "Various reasons.", "bitmex": "Various reasons.",
"bitstamp": "Does not provide history. " "bitstamp": "Does not provide history. "

View File

@ -23,7 +23,8 @@ from freqtrade.exceptions import (DDosProtection, ExchangeError,
InsufficientFundsError, InsufficientFundsError,
InvalidOrderException, OperationalException, InvalidOrderException, OperationalException,
RetryableOrderError, TemporaryError) RetryableOrderError, TemporaryError)
from freqtrade.exchange.common import BAD_EXCHANGES, retrier, retrier_async from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT,
BAD_EXCHANGES, retrier, retrier_async)
from freqtrade.misc import deep_merge_dicts, safe_value_fallback2 from freqtrade.misc import deep_merge_dicts, safe_value_fallback2
CcxtModuleType = Any CcxtModuleType = Any
@ -1010,7 +1011,7 @@ class Exchange:
return order return order
@retrier(retries=5) @retrier(retries=API_FETCH_ORDER_RETRY_COUNT)
def fetch_order(self, order_id: str, pair: str) -> Dict: def fetch_order(self, order_id: str, pair: str) -> Dict:
if self._config['dry_run']: if self._config['dry_run']:
try: try:

View File

@ -8,7 +8,7 @@ from freqtrade.exceptions import (DDosProtection, InsufficientFundsError,
InvalidOrderException, OperationalException, InvalidOrderException, OperationalException,
TemporaryError) TemporaryError)
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
from freqtrade.exchange.common import retrier from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT, retrier
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -78,7 +78,7 @@ class Ftx(Exchange):
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) from e raise OperationalException(e) from e
@retrier(retries=5) @retrier(retries=API_FETCH_ORDER_RETRY_COUNT)
def fetch_stoploss_order(self, order_id: str, pair: str) -> Dict: def fetch_stoploss_order(self, order_id: str, pair: str) -> Dict:
if self._config['dry_run']: if self._config['dry_run']:
try: try:

View File

@ -1,5 +1,3 @@
# pragma pylint: disable=missing-docstring, C0103, bad-continuation, global-statement
# pragma pylint: disable=protected-access
import copy import copy
import logging import logging
from datetime import datetime, timezone from datetime import datetime, timezone
@ -11,10 +9,12 @@ import ccxt
import pytest import pytest
from pandas import DataFrame from pandas import DataFrame
from freqtrade.exceptions import (DependencyException, InvalidOrderException, DDosProtection, from freqtrade.exceptions import (DDosProtection, DependencyException,
OperationalException, TemporaryError) InvalidOrderException, OperationalException,
TemporaryError)
from freqtrade.exchange import Binance, Exchange, Kraken from freqtrade.exchange import Binance, Exchange, Kraken
from freqtrade.exchange.common import API_RETRY_COUNT, calculate_backoff from freqtrade.exchange.common import (API_RETRY_COUNT, API_FETCH_ORDER_RETRY_COUNT,
calculate_backoff)
from freqtrade.exchange.exchange import (market_is_active, symbol_is_pair, from freqtrade.exchange.exchange import (market_is_active, symbol_is_pair,
timeframe_to_minutes, timeframe_to_minutes,
timeframe_to_msecs, timeframe_to_msecs,
@ -1894,12 +1894,14 @@ def test_fetch_order(default_conf, mocker, exchange_name):
# Ensure backoff is called # Ensure backoff is called
assert tm.call_args_list[0][0][0] == 1 assert tm.call_args_list[0][0][0] == 1
assert tm.call_args_list[1][0][0] == 2 assert tm.call_args_list[1][0][0] == 2
assert tm.call_args_list[2][0][0] == 5 if API_FETCH_ORDER_RETRY_COUNT > 2:
assert tm.call_args_list[3][0][0] == 10 assert tm.call_args_list[2][0][0] == 5
assert api_mock.fetch_order.call_count == 6 if API_FETCH_ORDER_RETRY_COUNT > 3:
assert tm.call_args_list[3][0][0] == 10
assert api_mock.fetch_order.call_count == API_FETCH_ORDER_RETRY_COUNT + 1
ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name, ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name,
'fetch_order', 'fetch_order', retries=6, 'fetch_order', 'fetch_order', retries=API_FETCH_ORDER_RETRY_COUNT + 1,
order_id='_', pair='TKN/BTC') order_id='_', pair='TKN/BTC')
@ -1932,7 +1934,7 @@ def test_fetch_stoploss_order(default_conf, mocker, exchange_name):
ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name, ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name,
'fetch_stoploss_order', 'fetch_order', 'fetch_stoploss_order', 'fetch_order',
retries=6, retries=API_FETCH_ORDER_RETRY_COUNT + 1,
order_id='_', pair='TKN/BTC') order_id='_', pair='TKN/BTC')

View File

@ -1,5 +1,3 @@
# pragma pylint: disable=missing-docstring, C0103, bad-continuation, global-statement
# pragma pylint: disable=protected-access
from random import randint from random import randint
from unittest.mock import MagicMock from unittest.mock import MagicMock
@ -7,6 +5,7 @@ import ccxt
import pytest import pytest
from freqtrade.exceptions import DependencyException, InvalidOrderException from freqtrade.exceptions import DependencyException, InvalidOrderException
from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT
from tests.conftest import get_patched_exchange from tests.conftest import get_patched_exchange
from .test_exchange import ccxt_exceptionhandlers from .test_exchange import ccxt_exceptionhandlers
@ -154,5 +153,5 @@ def test_fetch_stoploss_order(default_conf, mocker):
ccxt_exceptionhandlers(mocker, default_conf, api_mock, 'ftx', ccxt_exceptionhandlers(mocker, default_conf, api_mock, 'ftx',
'fetch_stoploss_order', 'fetch_orders', 'fetch_stoploss_order', 'fetch_orders',
retries=6, retries=API_FETCH_ORDER_RETRY_COUNT + 1,
order_id='_', pair='TKN/BTC') order_id='_', pair='TKN/BTC')

View File

@ -1,5 +1,3 @@
# pragma pylint: disable=missing-docstring, C0103, bad-continuation, global-statement
# pragma pylint: disable=protected-access
from random import randint from random import randint
from unittest.mock import MagicMock from unittest.mock import MagicMock