From 708320318c5a340d70a161177725f670764d0bb9 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 12 Jun 2018 01:05:43 +0300 Subject: [PATCH] Check minimal amount --- freqtrade/freqtradebot.py | 12 +++++++++--- freqtrade/tests/test_freqtradebot.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 1e32aecdf..1477a931e 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -234,7 +234,7 @@ class FreqtradeBot(object): return final_list - def get_target_bid(self, ticker: Dict[str, float]) -> Optional[float]: + def get_target_bid(self, ticker: Dict[str, float]) -> float: """ Calculates bid target between current ask price and last price :param ticker: Ticker to use for getting Ask and Last Price @@ -245,7 +245,7 @@ class FreqtradeBot(object): balance = self.config['bid_strategy']['ask_last_balance'] return ticker['ask'] + balance * (ticker['last'] - ticker['ask']) - def _get_trade_stake_amount(self) -> float: + def _get_trade_stake_amount(self) -> Optional[float]: stake_amount = self.config['stake_amount'] avaliable_amount = exchange.get_balance(self.config['stake_currency']) @@ -254,7 +254,13 @@ class FreqtradeBot(object): if open_trades >= self.config['max_open_trades']: logger.warning('Can\'t open a new trade: max number of trades is reached') return None - return avaliable_amount / (self.config['max_open_trades'] - open_trades) + trade_stake_amount = avaliable_amount / (self.config['max_open_trades'] - open_trades) + if trade_stake_amount < 0.0005: + raise DependencyException( + 'Available balance(%f %s) is lower than minimal' % ( + avaliable_amount, self.config['stake_currency']) + ) + return trade_stake_amount # Check if stake_amount is fulfilled if avaliable_amount < stake_amount: diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index 314d880b6..80b66735d 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -249,11 +249,21 @@ def test_get_trade_stake_amount_no_stake_amount(default_conf, get_balance=MagicMock(return_value=default_conf['stake_amount'] * 0.5) ) + # test defined stake amount freqtrade = FreqtradeBot(default_conf) with pytest.raises(DependencyException, match=r'.*stake amount.*'): freqtrade._get_trade_stake_amount() + # test UNLIMITED_STAKE_AMOUNT + conf = deepcopy(default_conf) + conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT + conf['max_open_trades'] = 2 + freqtrade = FreqtradeBot(conf) + + with pytest.raises(DependencyException, match=r'.*is lower than minimal.*'): + freqtrade._get_trade_stake_amount() + def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker,