mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
update get_valid_price function and test cases to handle inputs with try catch
This commit is contained in:
parent
dbf7f34ecb
commit
20cc60bfde
|
@ -1400,11 +1400,9 @@ class FreqtradeBot(LoggingMixin):
|
||||||
:return: valid price for the order
|
:return: valid price for the order
|
||||||
"""
|
"""
|
||||||
if custom_price:
|
if custom_price:
|
||||||
if isinstance(custom_price, int):
|
try:
|
||||||
valid_price = float(custom_price)
|
valid_price = float(custom_price)
|
||||||
elif isinstance(custom_price, float):
|
except ValueError:
|
||||||
valid_price = custom_price
|
|
||||||
else:
|
|
||||||
valid_price = proposed_price
|
valid_price = proposed_price
|
||||||
else:
|
else:
|
||||||
valid_price = proposed_price
|
valid_price = proposed_price
|
||||||
|
|
|
@ -4596,19 +4596,23 @@ def test_get_valid_price(mocker, default_conf) -> None:
|
||||||
freqtrade = FreqtradeBot(default_conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
|
|
||||||
custom_price_string = "10"
|
custom_price_string = "10"
|
||||||
|
custom_price_badstring = "10abc"
|
||||||
custom_price_float = 10.0
|
custom_price_float = 10.0
|
||||||
custom_price_int = 10
|
custom_price_int = 10
|
||||||
|
|
||||||
proposed_price = 12.2
|
proposed_price = 12.2
|
||||||
|
|
||||||
valid_price_from_string = freqtrade.get_valid_price(custom_price_string, proposed_price)
|
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_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_from_float = freqtrade.get_valid_price(custom_price_float, proposed_price)
|
||||||
|
|
||||||
assert isinstance(valid_price_from_string, float)
|
assert isinstance(valid_price_from_string, float)
|
||||||
|
assert isinstance(valid_price_from_badstring, float)
|
||||||
assert isinstance(valid_price_from_int, float)
|
assert isinstance(valid_price_from_int, float)
|
||||||
assert isinstance(valid_price_from_float, float)
|
assert isinstance(valid_price_from_float, float)
|
||||||
|
|
||||||
assert valid_price_from_string == proposed_price
|
assert valid_price_from_string == custom_price_float
|
||||||
|
assert valid_price_from_badstring == proposed_price
|
||||||
assert valid_price_from_int == custom_price_int
|
assert valid_price_from_int == custom_price_int
|
||||||
assert valid_price_from_float == custom_price_float
|
assert valid_price_from_float == custom_price_float
|
||||||
|
|
Loading…
Reference in New Issue
Block a user