diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index 3dd7b1f2c..37109767b 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -49,20 +49,22 @@ def patch_edge(mocker) -> None: # "LTC/BTC", # "XRP/BTC", # "NEO/BTC" - pair_info = namedtuple('pair_info', 'stoploss, winrate, risk_reward_ratio, required_risk_reward, expectancy') + pair_info = namedtuple( + 'pair_info', + 'stoploss, winrate, risk_reward_ratio, required_risk_reward, expectancy') mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock( return_value={ 'NEO/BTC': pair_info(-0.20, 0.66, 3.71, 0.50, 1.71), 'LTC/BTC': pair_info(-0.21, 0.66, 3.71, 0.50, 1.71), } )) - mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value = -0.20)) - mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value = True)) + mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value=-0.20)) + mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value=True)) def get_patched_edge(mocker, config) -> Edge: patch_edge(mocker) - edge=Edge(config) + edge = Edge(config) return edge # Functions for recurrent object patching @@ -86,15 +88,15 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot: return FreqtradeBot(config) -def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]]=None) -> None: +def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None: """ Mocker to coinmarketcap to speed up tests :param mocker: mocker to patch coinmarketcap class :return: None """ - tickermock=MagicMock(return_value={'price_usd': 12345.0}) - listmock=MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', + tickermock = MagicMock(return_value={'price_usd': 12345.0}) + listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', 'website_slug': 'bitcoin'}, {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'website_slug': 'ethereum'} @@ -110,7 +112,7 @@ def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]]=None) -> None: @pytest.fixture(scope="function") def default_conf(): """ Returns validated configuration suitable for most tests """ - configuration={ + configuration = { "max_open_trades": 1, "stake_currency": "BTC", "stake_amount": 0.001, diff --git a/freqtrade/tests/edge/test_edge.py b/freqtrade/tests/edge/test_edge.py index 710920e91..18e934352 100644 --- a/freqtrade/tests/edge/test_edge.py +++ b/freqtrade/tests/edge/test_edge.py @@ -64,7 +64,7 @@ def _validate_ohlc(buy_ohlc_sell_matrice): def _build_dataframe(buy_ohlc_sell_matrice): _validate_ohlc(buy_ohlc_sell_matrice) - tickers= [] + tickers = [] for ohlc in buy_ohlc_sell_matrice: ticker = { 'date': ticker_start_time.shift( @@ -82,9 +82,9 @@ def _build_dataframe(buy_ohlc_sell_matrice): frame = DataFrame(tickers) frame['date'] = to_datetime(frame['date'], - unit = 'ms', - utc = True, - infer_datetime_format = True) + unit='ms', + utc=True, + infer_datetime_format=True) return frame @@ -95,17 +95,17 @@ def _time_on_candle(number): def test_edge_heartbeat_calculate(mocker, default_conf): - exchange=get_patched_exchange(mocker, default_conf) - edge=Edge(default_conf, exchange) - heartbeat=default_conf['edge']['process_throttle_secs'] + exchange = get_patched_exchange(mocker, default_conf) + edge = Edge(default_conf, exchange) + heartbeat = default_conf['edge']['process_throttle_secs'] # should not recalculate if heartbeat not reached - edge._last_updated=arrow.utcnow().timestamp - heartbeat + 1 + edge._last_updated = arrow.utcnow().timestamp - heartbeat + 1 assert edge.calculate() is False -def mocked_load_data(datadir, pairs = [], ticker_interval = '0m', refresh_pairs = False, +def mocked_load_data(datadir, pairs=[], ticker_interval='0m', refresh_pairs=False, timerange=None, exchange=None): hz = 0.1 base = 0.001 @@ -213,6 +213,8 @@ def test_process_expectancy(mocker, default_conf): assert round(final['TEST/BTC'].expectancy, 10) == 101.5128205128 # 1) Open trade should be removed from the end + + def test_case_1(mocker, default_conf): exchange = get_patched_exchange(mocker, default_conf) edge = Edge(default_conf, exchange)