Skip to content

Commit

Permalink
move pairlist filters out of config[]
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Nov 19, 2019
1 parent 66a273b commit c22b00b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
5 changes: 1 addition & 4 deletions config_full.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@
}
},
{"method": "PrecisionFilter"},
{"method": "LowPriceFilter",
"config": {
"low_price_percent": 0.01
}
{"method": "LowPriceFilter", "low_price_ratio": 0.01
}
],
"exchange": {
Expand Down
22 changes: 8 additions & 14 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,9 @@ It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklis
```json
"pairlists": [{
"method": "VolumePairList",
"config": {
"number_assets": 20,
"sort_key": "quoteVolume",
"ttl": 1800,
}
"number_assets": 20,
"sort_key": "quoteVolume",
"ttl": 1800,
],
```

Expand All @@ -430,7 +428,7 @@ Filters low-value coins which would not allow setting a stoploss.

#### Low Price Pair Filter

The `LowPriceFilter` allows filtering of pairs where a raise of 1 price unit is below the `low_price_percent` ratio.
The `LowPriceFilter` allows filtering of pairs where a raise of 1 price unit is below the `low_price_ratio` ratio.
This option is disabled by default, and will only apply if set to <> 0.

Calculation example:
Expand All @@ -450,16 +448,12 @@ The below example blacklists `BNB/BTC`, uses `VolumePairList` with `20` assets,
"pairlists": [
{
"method": "VolumePairList",
"config": {
"number_assets": 20,
"sort_key": "quoteVolume",
},
"number_assets": 20,
"sort_key": "quoteVolume",
},
{"method": "PrecisionFilter"},
{"method": "LowPriceFilter",
"config": {"low_price_percent": 0.01}
}
}],
{"method": "LowPriceFilter", "low_price_ratio": 0.01}
],
```

## Switch to Dry-run mode
Expand Down
8 changes: 4 additions & 4 deletions freqtrade/pairlist/LowPriceFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict,
pairlist_pos: int) -> None:
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)

self._low_price_percent = pairlistconfig.get('low_price_percent', 0)
self._low_price_ratio = pairlistconfig.get('low_price_ratio', 0)

@property
def needstickers(self) -> bool:
Expand All @@ -28,7 +28,7 @@ def short_desc(self) -> str:
"""
Short whitelist method description - used for startup-messages
"""
return f"{self.name} - Filtering pairs priced below {self._low_price_percent * 100}%."
return f"{self.name} - Filtering pairs priced below {self._low_price_ratio * 100}%."

def _validate_ticker_lowprice(self, ticker) -> bool:
"""
Expand All @@ -41,7 +41,7 @@ def _validate_ticker_lowprice(self, ticker) -> bool:

compare = ticker['last'] + 1 / pow(10, precision)
changeperc = (compare - ticker['last']) / ticker['last']
if changeperc > self._low_price_percent:
if changeperc > self._low_price_ratio:
logger.info(f"Removed {ticker['symbol']} from whitelist, "
f"because 1 unit is {changeperc * 100:.3f}%")
return False
Expand All @@ -63,7 +63,7 @@ def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
pairlist.remove(p)

# Filter out assets which would not allow setting a stoploss
if self._low_price_percent and not self._validate_ticker_lowprice(ticker):
if self._low_price_ratio and not self._validate_ticker_lowprice(ticker):
pairlist.remove(p)

return pairlist
2 changes: 1 addition & 1 deletion freqtrade/pairlist/pairlistmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, exchange, config: dict) -> None:
exchange=exchange,
pairlistmanager=self,
config=config,
pairlistconfig=pl.get('config'),
pairlistconfig=pl,
pairlist_pos=len(self._pairlists)
).pairlist
self._tickers_needed = pairl.needstickers or self._tickers_needed
Expand Down
30 changes: 14 additions & 16 deletions tests/pairlist/test_pairlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def whitelist_conf(default_conf):
default_conf['pairlists'] = [
{
"method": "VolumePairList",
"config": {
"number_assets": 5,
"sort_key": "quoteVolume",
}
"number_assets": 5,
"sort_key": "quoteVolume",
},
]
return default_conf
Expand Down Expand Up @@ -136,37 +134,37 @@ def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):


@pytest.mark.parametrize("pairlists,base_currency,whitelist_result", [
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}],
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'HOT/BTC', 'FUEL/BTC']),
# Different sorting depending on quote or bid volume
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}}],
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}],
"BTC", ['HOT/BTC', 'FUEL/BTC', 'LTC/BTC', 'TKN/BTC', 'ETH/BTC']),
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}],
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
"USDT", ['ETH/USDT']),
# No pair for ETH ...
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}],
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
"ETH", []),
# Precisionfilter and quote volume
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}},
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
{"method": "PrecisionFilter"}], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']),
# Precisionfilter bid
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}},
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"},
{"method": "PrecisionFilter"}], "BTC", ['FUEL/BTC', 'LTC/BTC', 'TKN/BTC', 'ETH/BTC']),
# Lowpricefilter and VolumePairList
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}},
{"method": "LowPriceFilter", "config": {"low_price_percent": 0.03}}],
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
{"method": "LowPriceFilter", "low_price_ratio": 0.03}],
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']),
# Hot is removed by precision_filter, Fuel by low_price_filter.
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}},
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
{"method": "PrecisionFilter"},
{"method": "LowPriceFilter", "config": {"low_price_percent": 0.02}}
{"method": "LowPriceFilter", "low_price_ratio": 0.02}
], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
# StaticPairlist Only
([{"method": "StaticPairList"},
], "BTC", ['ETH/BTC', 'TKN/BTC']),
# Static Pairlist before VolumePairList - sorting changes
([{"method": "StaticPairList"},
{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}},
{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"},
], "BTC", ['TKN/BTC', 'ETH/BTC']),
])
def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, tickers,
Expand Down Expand Up @@ -257,7 +255,7 @@ def test__whitelist_for_active_markets(mocker, whitelist_conf, markets, pairlist


def test_volumepairlist_invalid_sortvalue(mocker, markets, whitelist_conf):
whitelist_conf['pairlists'][0]['config'].update({"sort_key": "asdf"})
whitelist_conf['pairlists'][0].update({"sort_key": "asdf"})

mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
with pytest.raises(OperationalException,
Expand Down
2 changes: 1 addition & 1 deletion tests/rpc/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def test_rpc_whitelist(mocker, default_conf) -> None:

def test_rpc_whitelist_dynamic(mocker, default_conf) -> None:
default_conf['pairlists'] = [{'method': 'VolumePairList',
'config': {'number_assets': 4}
'number_assets': 4,
}]
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
Expand Down
2 changes: 1 addition & 1 deletion tests/rpc/test_rpc_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None:
)
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
default_conf['pairlists'] = [{'method': 'VolumePairList',
'config': {'number_assets': 4}
'number_assets': 4
}]
freqtradebot = get_patched_freqtradebot(mocker, default_conf)

Expand Down

0 comments on commit c22b00b

Please sign in to comment.