manage None or string value returned by custom_entry_price and add unit test for those cases
This commit is contained in:
parent
612b88e993
commit
ae11be3970
@ -479,13 +479,17 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
buy_limit_requested = price
|
buy_limit_requested = price
|
||||||
else:
|
else:
|
||||||
# Calculate price
|
# Calculate price
|
||||||
buy_limit_requested = self.exchange.get_rate(pair, refresh=True, side="buy")
|
proposed_buy_rate = self.exchange.get_rate(pair, refresh=True, side="buy")
|
||||||
custom_entry_price = strategy_safe_wrapper(self.strategy.custom_entry_price,
|
custom_entry_price = strategy_safe_wrapper(self.strategy.custom_entry_price,
|
||||||
default_retval=buy_limit_requested)(
|
default_retval=proposed_buy_rate)(
|
||||||
pair=pair, current_time=datetime.now(timezone.utc),
|
pair=pair, current_time=datetime.now(timezone.utc),
|
||||||
proposed_rate=buy_limit_requested)
|
proposed_rate=proposed_buy_rate)
|
||||||
|
|
||||||
buy_limit_requested = custom_entry_price
|
if custom_entry_price and (isinstance(custom_entry_price, int)
|
||||||
|
or isinstance(custom_entry_price, float)):
|
||||||
|
buy_limit_requested = custom_entry_price
|
||||||
|
else:
|
||||||
|
buy_limit_requested = proposed_buy_rate
|
||||||
|
|
||||||
if not buy_limit_requested:
|
if not buy_limit_requested:
|
||||||
raise PricingError('Could not determine buy price.')
|
raise PricingError('Could not determine buy price.')
|
||||||
|
@ -913,6 +913,30 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
assert trade
|
assert trade
|
||||||
assert trade.open_rate_requested == 0.77
|
assert trade.open_rate_requested == 0.77
|
||||||
|
|
||||||
|
# In case of custom entry price set to None
|
||||||
|
limit_buy_order['status'] = 'open'
|
||||||
|
limit_buy_order['id'] = '5567'
|
||||||
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: None
|
||||||
|
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
get_rate=MagicMock(return_value=10),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert freqtrade.execute_buy(pair, stake_amount)
|
||||||
|
trade = Trade.query.all()[7]
|
||||||
|
assert trade
|
||||||
|
assert trade.open_rate_requested == 10
|
||||||
|
|
||||||
|
# In case of custom entry price not float type
|
||||||
|
limit_buy_order['status'] = 'open'
|
||||||
|
limit_buy_order['id'] = '5568'
|
||||||
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price"
|
||||||
|
assert freqtrade.execute_buy(pair, stake_amount)
|
||||||
|
trade = Trade.query.all()[8]
|
||||||
|
assert trade
|
||||||
|
assert trade.open_rate_requested == 10
|
||||||
|
|
||||||
|
|
||||||
def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user