add custom_price_max_distance_percent security to get_valid_price, update tests

This commit is contained in:
axel
2021-08-16 15:18:57 -04:00
parent c456cfc312
commit 3ea4b2ba00
2 changed files with 27 additions and 4 deletions

View File

@@ -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