From 0d6c933935f47ea555e0e36ee07254d5f7dad90a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Nov 2021 15:25:57 +0100 Subject: [PATCH] Improve and fix pair detection from available data --- freqtrade/data/history/idatahandler.py | 2 +- freqtrade/rpc/api_server/api_v1.py | 7 ++++++- tests/data/test_history.py | 1 + tests/rpc/test_rpc_apiserver.py | 6 +++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/freqtrade/data/history/idatahandler.py b/freqtrade/data/history/idatahandler.py index 787614c51..1a8e31094 100644 --- a/freqtrade/data/history/idatahandler.py +++ b/freqtrade/data/history/idatahandler.py @@ -173,7 +173,7 @@ class IDataHandler(ABC): Rebuild pair name from filename Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names. """ - res = re.sub(r'^(.{1,7})(_)', r'\g<1>/', pair, 1) + res = re.sub(r'^(([A-Za-z]{1,10})|^([A-Za-z\-]{1,6}))(_)', r'\g<1>/', pair, 1) res = re.sub('_', ':', res, 1) return res diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index 0467e4705..975064adf 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -247,7 +247,7 @@ def get_strategy(strategy: str, config=Depends(get_config)): @router.get('/available_pairs', response_model=AvailablePairs, tags=['candle data']) def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Optional[str] = None, - config=Depends(get_config)): + candletype: Optional[str] = None, config=Depends(get_config)): dh = get_datahandler(config['datadir'], config.get('dataformat_ohlcv', None)) @@ -257,6 +257,11 @@ def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Option pair_interval = [pair for pair in pair_interval if pair[1] == timeframe] if stake_currency: pair_interval = [pair for pair in pair_interval if pair[0].endswith(stake_currency)] + if candletype: + pair_interval = [pair for pair in pair_interval if pair[2] == candletype] + else: + pair_interval = [pair for pair in pair_interval if pair[2] == ''] + pair_interval = sorted(pair_interval, key=lambda x: x[0]) pairs = list({x[0] for x in pair_interval}) diff --git a/tests/data/test_history.py b/tests/data/test_history.py index 8557d05eb..bf3c1a1de 100644 --- a/tests/data/test_history.py +++ b/tests/data/test_history.py @@ -699,6 +699,7 @@ def test_datahandler_ohlcv_regex(filename, pair, timeframe, candletype): ('XRP_USDT_USDT', 'XRP/USDT:USDT'), # futures ('BTC-PERP', 'BTC-PERP'), ('BTC-PERP_USDT', 'BTC-PERP:USDT'), # potential FTX case + ('UNITTEST_USDT', 'UNITTEST/USDT'), ]) def test_rebuild_pair_from_filename(input, expected): diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index e2da51ba1..994d29887 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1332,7 +1332,7 @@ def test_list_available_pairs(botclient): rc = client_get(client, f"{BASE_URI}/available_pairs") assert_response(rc) - assert rc.json()['length'] == 15 + assert rc.json()['length'] == 14 assert isinstance(rc.json()['pairs'], list) rc = client_get(client, f"{BASE_URI}/available_pairs?timeframe=5m") @@ -1352,11 +1352,11 @@ def test_list_available_pairs(botclient): assert len(rc.json()['pair_interval']) == 1 rc = client_get( - client, f"{BASE_URI}/available_pairs?stake_currency=USDT&timeframe=1h&type=mark") + client, f"{BASE_URI}/available_pairs?timeframe=1h&candletype=mark") assert_response(rc) assert rc.json()['length'] == 2 assert rc.json()['pairs'] == ['UNITTEST/USDT', 'XRP/USDT'] - assert len(rc.json()['pair_interval']) == 3 # TODO-lev: What is pair_interval? Should it be 3? + assert len(rc.json()['pair_interval']) == 2 def test_sysinfo(botclient):