From e69f9dd029022053a4501d2938bf2e810a6000ef Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Tue, 2 Jan 2018 23:00:03 +0100 Subject: [PATCH] Bad unittest detected reading coverage report, rewritten and bug found --- freqtrade/main.py | 5 ++- freqtrade/tests/test_acl_pair.py | 65 ++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/freqtrade/main.py b/freqtrade/main.py index 7fc7654ed..08b1f1107 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -35,9 +35,12 @@ def refresh_whitelist(whitelist: List[str]) -> List[str]: known_pairs = set() for status in health: pair = '{}_{}'.format(_CONF['stake_currency'], status['Currency']) - known_pairs.add(pair) + # pair is not int the generated dynamic market, or in the blacklist ... ignore it if pair not in whitelist or pair in _CONF['exchange'].get('pair_blacklist', []): continue + # else the pair is valid + known_pairs.add(pair) + # Market is not active if not status['IsActive']: sanitized_whitelist.remove(pair) logger.info( diff --git a/freqtrade/tests/test_acl_pair.py b/freqtrade/tests/test_acl_pair.py index 1368ac25c..be0bd47e8 100644 --- a/freqtrade/tests/test_acl_pair.py +++ b/freqtrade/tests/test_acl_pair.py @@ -1,4 +1,4 @@ -from freqtrade.main import refresh_whitelist +from freqtrade.main import refresh_whitelist, gen_pair_whitelist # whitelist, blacklist, filtering, all of that will # eventually become some rules to run on a generic ACL engine @@ -23,18 +23,65 @@ def whitelist_conf(): } +def get_market_summaries(): + return [{ + "MarketName": "BTC-TKN", + "High": 0.00000919, + "Low": 0.00000820, + "Volume": 74339.61396015, + "Last": 0.00000820, + "BaseVolume": 1664, + "TimeStamp": "2014-07-09T07:19:30.15", + "Bid": 0.00000820, + "Ask": 0.00000831, + "OpenBuyOrders": 15, + "OpenSellOrders": 15, + "PrevDay": 0.00000821, + "Created": "2014-03-20T06:00:00", + "DisplayMarketName": "" + }, { + "MarketName": "BTC-ETH", + "High": 0.00000072, + "Low": 0.00000001, + "Volume": 166340678.42280999, + "Last": 0.00000005, + "BaseVolume": 42, + "TimeStamp": "2014-07-09T07:21:40.51", + "Bid": 0.00000004, + "Ask": 0.00000005, + "OpenBuyOrders": 18, + "OpenSellOrders": 18, + "PrevDay": 0.00000002, + "Created": "2014-05-30T07:57:49.637", + "DisplayMarketName": "" + }, { + "MarketName": "BTC-BLK", + "High": 0.00000072, + "Low": 0.00000001, + "Volume": 166340678.42280999, + "Last": 0.00000005, + "BaseVolume": 3, + "TimeStamp": "2014-07-09T07:21:40.51", + "Bid": 0.00000004, + "Ask": 0.00000005, + "OpenBuyOrders": 18, + "OpenSellOrders": 18, + "PrevDay": 0.00000002, + "Created": "2014-05-30T07:57:49.637", + "DisplayMarketName": "" + } + ] + + def get_health(): return [{'Currency': 'ETH', - 'IsActive': True, - 'BaseVolume': 42 + 'IsActive': True }, {'Currency': 'TKN', - 'IsActive': True, - 'BaseVolume': 1664 + 'IsActive': True }, {'Currency': 'BLK', - 'IsActive': True, - 'BaseVolume': 4096 + 'IsActive': True } ] @@ -72,9 +119,11 @@ def test_refresh_whitelist_dynamic(mocker): mocker.patch.dict('freqtrade.main._CONF', conf) mocker.patch.multiple('freqtrade.main.exchange', get_wallet_health=get_health) + mocker.patch.multiple('freqtrade.main.exchange', + get_market_summaries=get_market_summaries) # argument: use the whitelist dynamically by exchange-volume whitelist = ['BTC_TKN', 'BTC_ETH'] - refreshedwhitelist = refresh_whitelist(whitelist) + refreshedwhitelist = refresh_whitelist(gen_pair_whitelist(conf['stake_currency'])) assert whitelist == refreshedwhitelist