Improve dry-run calculations
This commit is contained in:
parent
f0bbc75038
commit
5a5741878c
@ -232,8 +232,8 @@ class FreqtradeBot:
|
|||||||
# Check if stake_amount is fulfilled
|
# Check if stake_amount is fulfilled
|
||||||
if available_amount < stake_amount:
|
if available_amount < stake_amount:
|
||||||
raise DependencyException(
|
raise DependencyException(
|
||||||
f"Available balance({available_amount} {self.config['stake_currency']}) is "
|
f"Available balance ({available_amount} {self.config['stake_currency']}) is "
|
||||||
f"lower than stake amount({stake_amount} {self.config['stake_currency']})"
|
f"lower than stake amount ({stake_amount} {self.config['stake_currency']})"
|
||||||
)
|
)
|
||||||
|
|
||||||
return stake_amount
|
return stake_amount
|
||||||
|
@ -54,21 +54,20 @@ class Wallets:
|
|||||||
def _update_dry(self) -> None:
|
def _update_dry(self) -> None:
|
||||||
""" Update from database in dry-run mode"""
|
""" Update from database in dry-run mode"""
|
||||||
closed_trades = Trade.get_trades(Trade.is_open.is_(False)).all()
|
closed_trades = Trade.get_trades(Trade.is_open.is_(False)).all()
|
||||||
|
open_trades = Trade.get_trades(Trade.is_open.is_(True)).all()
|
||||||
tot_profit = sum([trade.calc_profit() for trade in closed_trades])
|
tot_profit = sum([trade.calc_profit() for trade in closed_trades])
|
||||||
|
tot_in_trades = sum([trade.stake_amount for trade in open_trades])
|
||||||
|
|
||||||
current_stake = self.start_cap + tot_profit
|
current_stake = self.start_cap + tot_profit - tot_in_trades
|
||||||
self._wallets[self._config['stake_currency']] = Wallet(
|
self._wallets[self._config['stake_currency']] = Wallet(
|
||||||
self._config['stake_currency'],
|
self._config['stake_currency'],
|
||||||
current_stake,
|
current_stake,
|
||||||
0,
|
0,
|
||||||
current_stake
|
current_stake
|
||||||
)
|
)
|
||||||
open_trades = Trade.get_trades(Trade.is_open.is_(True)).all()
|
|
||||||
|
|
||||||
for trade in open_trades:
|
for trade in open_trades:
|
||||||
curr = trade.pair.split('/')[0]
|
curr = trade.pair.split('/')[0]
|
||||||
trade.amount
|
|
||||||
self._wallets[curr] = Wallet(
|
self._wallets[curr] = Wallet(
|
||||||
curr,
|
curr,
|
||||||
trade.amount,
|
trade.amount,
|
||||||
|
@ -3485,3 +3485,33 @@ def test_process_i_am_alive(default_conf, mocker, caplog):
|
|||||||
|
|
||||||
ftbot.process()
|
ftbot.process()
|
||||||
assert log_has_re(message, caplog)
|
assert log_has_re(message, caplog)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
|
def test_sync_wallet_dry_run(mocker, default_conf, ticker, fee, limit_buy_order):
|
||||||
|
default_conf['dry_run'] = True
|
||||||
|
# Initialize to 2 times stake amount
|
||||||
|
default_conf['dry_run_wallet'] = 0.002
|
||||||
|
default_conf['max_open_trades'] = 2
|
||||||
|
patch_exchange(mocker)
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
get_ticker=ticker,
|
||||||
|
buy=MagicMock(return_value={'id': limit_buy_order['id']}),
|
||||||
|
get_fee=fee,
|
||||||
|
)
|
||||||
|
|
||||||
|
bot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
patch_get_signal(bot)
|
||||||
|
assert bot.wallets.get_free('BTC') == 0.002
|
||||||
|
|
||||||
|
bot.create_trades()
|
||||||
|
trades = Trade.query.all()
|
||||||
|
assert len(trades) == 2
|
||||||
|
|
||||||
|
bot.config['max_open_trades'] = 3
|
||||||
|
with pytest.raises(
|
||||||
|
DependencyException,
|
||||||
|
match=r"Available balance \(0 BTC\) is lower than stake amount \(0.001 BTC\)"):
|
||||||
|
bot.create_trades()
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ def test_may_execute_sell_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
|||||||
)
|
)
|
||||||
mocker.patch("freqtrade.strategy.interface.IStrategy.should_sell", should_sell_mock)
|
mocker.patch("freqtrade.strategy.interface.IStrategy.should_sell", should_sell_mock)
|
||||||
wallets_mock = mocker.patch("freqtrade.wallets.Wallets.update", MagicMock())
|
wallets_mock = mocker.patch("freqtrade.wallets.Wallets.update", MagicMock())
|
||||||
|
mocker.patch("freqtrade.wallets.Wallets.get_free", MagicMock(return_value=1))
|
||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
||||||
|
Loading…
Reference in New Issue
Block a user