diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 011543a09..334e18dc7 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -740,17 +740,7 @@ class RPC: self._freqtrade.wallets.update() return {'result': f'Created sell order for trade {trade_id}.'} - def _rpc_force_entry(self, pair: str, price: Optional[float], *, - order_type: Optional[str] = None, - order_side: SignalDirection = SignalDirection.LONG, - stake_amount: Optional[float] = None, - enter_tag: Optional[str] = 'force_entry', - leverage: Optional[float] = None) -> Optional[Trade]: - """ - Handler for forcebuy - Buys a pair trade at the given or current price - """ - + def _force_entry_validations(self, pair: str, order_side: SignalDirection): if not self._freqtrade.config.get('force_entry_enable', False): raise RPCException('Force_entry not enabled.') @@ -760,11 +750,26 @@ class RPC: if order_side == SignalDirection.SHORT and self._freqtrade.trading_mode == TradingMode.SPOT: raise RPCException("Can't go short on Spot markets.") + if pair not in self._freqtrade.exchange.get_markets(tradable_only=True): + raise RPCException('Symbol does not exist or market is not active.') # Check if pair quote currency equals to the stake currency. stake_currency = self._freqtrade.config.get('stake_currency') if not self._freqtrade.exchange.get_pair_quote_currency(pair) == stake_currency: raise RPCException( f'Wrong pair selected. Only pairs with stake-currency {stake_currency} allowed.') + + def _rpc_force_entry(self, pair: str, price: Optional[float], *, + order_type: Optional[str] = None, + order_side: SignalDirection = SignalDirection.LONG, + stake_amount: Optional[float] = None, + enter_tag: Optional[str] = 'force_entry', + leverage: Optional[float] = None) -> Optional[Trade]: + """ + Handler for forcebuy + Buys a pair trade at the given or current price + """ + self._force_entry_validations(pair, order_side) + # check if valid pair # check if pair already has an open pair diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 8828b6f33..24b5f1cbe 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -1056,6 +1056,10 @@ def test_rpc_force_entry(mocker, default_conf, ticker, fee, limit_buy_order_open assert trade.pair == pair assert trade.open_rate == 0.0001 + with pytest.raises(RPCException, + match=r'Symbol does not exist or market is not active.'): + rpc._rpc_force_entry('LTC/NOTHING', 0.0001) + # Test buy pair not with stakes with pytest.raises(RPCException, match=r'Wrong pair selected. Only pairs with stake-currency.*'):