add custom_price_max_distance_percent security to get_valid_price, update tests
This commit is contained in:
parent
c456cfc312
commit
3ea4b2ba00
@ -1401,10 +1401,21 @@ class FreqtradeBot(LoggingMixin):
|
||||
"""
|
||||
if custom_price:
|
||||
try:
|
||||
valid_price = float(custom_price)
|
||||
valid_custom_price = float(custom_price)
|
||||
except ValueError:
|
||||
valid_price = proposed_price
|
||||
valid_custom_price = proposed_price
|
||||
else:
|
||||
valid_price = proposed_price
|
||||
valid_custom_price = proposed_price
|
||||
|
||||
cust_p_max_dist_pct = self.config.get('custom_price_max_distance_percent', 2.0)
|
||||
min_custom_price_allowed = proposed_price - ((proposed_price * cust_p_max_dist_pct) / 100)
|
||||
max_custom_price_allowed = proposed_price + ((proposed_price * cust_p_max_dist_pct) / 100)
|
||||
|
||||
if valid_custom_price > max_custom_price_allowed:
|
||||
valid_price = max_custom_price_allowed
|
||||
elif valid_custom_price < min_custom_price_allowed:
|
||||
valid_price = min_custom_price_allowed
|
||||
else:
|
||||
valid_price = valid_custom_price
|
||||
|
||||
return valid_price
|
||||
|
@ -4594,19 +4594,25 @@ def test_get_valid_price(mocker, default_conf) -> None:
|
||||
patch_RPCManager(mocker)
|
||||
patch_exchange(mocker)
|
||||
freqtrade = FreqtradeBot(default_conf)
|
||||
freqtrade.config['custom_price_max_distance_percent'] = 2.0
|
||||
|
||||
custom_price_string = "10"
|
||||
custom_price_badstring = "10abc"
|
||||
custom_price_float = 10.0
|
||||
custom_price_int = 10
|
||||
|
||||
proposed_price = 12.2
|
||||
custom_price_over_max_alwd = 11.0
|
||||
custom_price_under_min_alwd = 9.0
|
||||
proposed_price = 10.1
|
||||
|
||||
valid_price_from_string = freqtrade.get_valid_price(custom_price_string, proposed_price)
|
||||
valid_price_from_badstring = freqtrade.get_valid_price(custom_price_badstring, proposed_price)
|
||||
valid_price_from_int = freqtrade.get_valid_price(custom_price_int, proposed_price)
|
||||
valid_price_from_float = freqtrade.get_valid_price(custom_price_float, proposed_price)
|
||||
|
||||
valid_price_at_max_alwd = freqtrade.get_valid_price(custom_price_over_max_alwd, proposed_price)
|
||||
valid_price_at_min_alwd = freqtrade.get_valid_price(custom_price_under_min_alwd, proposed_price)
|
||||
|
||||
assert isinstance(valid_price_from_string, float)
|
||||
assert isinstance(valid_price_from_badstring, float)
|
||||
assert isinstance(valid_price_from_int, float)
|
||||
@ -4616,3 +4622,9 @@ def test_get_valid_price(mocker, default_conf) -> None:
|
||||
assert valid_price_from_badstring == proposed_price
|
||||
assert valid_price_from_int == custom_price_int
|
||||
assert valid_price_from_float == custom_price_float
|
||||
|
||||
assert valid_price_at_max_alwd != custom_price_over_max_alwd
|
||||
assert valid_price_at_max_alwd > proposed_price
|
||||
|
||||
assert valid_price_at_min_alwd != custom_price_under_min_alwd
|
||||
assert valid_price_at_min_alwd < proposed_price
|
||||
|
Loading…
Reference in New Issue
Block a user