Include transaction fees into balance check determination of being able to trade

This commit is contained in:
Ramon Bastiaans 2018-02-05 22:38:33 +01:00
parent 71636e8326
commit e99afe7597
2 changed files with 9 additions and 4 deletions

View File

@ -435,10 +435,15 @@ def create_trade(stake_amount: float, interval: int) -> bool:
stake_amount
)
whitelist = copy.deepcopy(_CONF['exchange']['pair_whitelist'])
# Check if stake_amount is fulfilled
if exchange.get_balance(_CONF['stake_currency']) < stake_amount:
# We need minimum funds of: stake amount + 2x transaction (buy+sell) fee to create a trade
min_required_funds = stake_amount + (stake_amount * (exchange.get_fee() * 2))
# Check if we have enough funds to be able to trade
if exchange.get_balance(_CONF['stake_currency']) < min_required_funds:
raise DependencyException(
'stake amount is not fulfilled (currency={})'.format(_CONF['stake_currency'])
'not enough funds to create trade (balance={}, required={})'.format(
_CONF['stake_currency'], min_required_funds)
)
# Remove currently opened and latest pairs from whitelist

View File

@ -220,7 +220,7 @@ def test_create_trade_no_stake_amount(default_conf, ticker, mocker):
get_ticker=ticker,
buy=MagicMock(return_value='mocked_limit_buy'),
get_balance=MagicMock(return_value=default_conf['stake_amount'] * 0.5))
with pytest.raises(DependencyException, match=r'.*stake amount.*'):
with pytest.raises(DependencyException, match=r'.*not enough funds.*'):
create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval']))