Rename process_maybe_execute_sells() --> exit_positions()

This commit is contained in:
hroff-1902 2019-12-30 22:08:36 +03:00
parent b00406a7eb
commit 84918ad424
3 changed files with 20 additions and 16 deletions

View File

@ -132,8 +132,8 @@ class FreqtradeBot:
self.dataprovider.refresh(self._create_pair_whitelist(self.active_pair_whitelist),
self.strategy.informative_pairs())
# First process current opened trades
self.process_maybe_execute_sells(trades)
# First process current opened trades (positions)
self.exit_positions(trades)
# Then looking for buy opportunities
if self.get_free_open_trades():
@ -493,9 +493,9 @@ class FreqtradeBot:
return trades_created
def process_maybe_execute_sells(self, trades: List[Any]) -> int:
def exit_positions(self, trades: List[Any]) -> int:
"""
Tries to execute sell orders for trades in a safe way
Tries to execute sell orders for open trades (positions)
"""
trades_closed = 0
for trade in trades:

View File

@ -990,7 +990,7 @@ def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None
trade.is_open = True
trades = [trade]
freqtrade.process_maybe_execute_sells(trades)
freqtrade.exit_positions(trades)
assert trade.stoploss_order_id == '13434334'
assert stoploss_limit.call_count == 1
assert trade.is_open is True
@ -1463,7 +1463,7 @@ def test_process_maybe_execute_buys_exception(mocker, default_conf, caplog) -> N
assert log_has('Unable to create trade: ', caplog)
def test_process_maybe_execute_sells(mocker, default_conf, limit_buy_order, caplog) -> None:
def test_exit_positions(mocker, default_conf, limit_buy_order, caplog) -> None:
freqtrade = get_patched_freqtradebot(mocker, default_conf)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
@ -1476,7 +1476,8 @@ def test_process_maybe_execute_sells(mocker, default_conf, limit_buy_order, capl
trade.open_order_id = '123'
trade.open_fee = 0.001
trades = [trade]
assert not freqtrade.process_maybe_execute_sells(trades)
n = freqtrade.exit_positions(trades)
assert n == 0
# Test amount not modified by fee-logic
assert not log_has(
'Applying fee to amount for Trade {} from 90.99181073 to 90.81'.format(trade), caplog
@ -1484,11 +1485,11 @@ def test_process_maybe_execute_sells(mocker, default_conf, limit_buy_order, capl
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', return_value=90.81)
# test amount modified by fee-logic
assert not freqtrade.process_maybe_execute_sells(trades)
n = freqtrade.exit_positions(trades)
assert n == 0
def test_process_maybe_execute_sells_exception(mocker, default_conf,
limit_buy_order, caplog) -> None:
def test_exit_positions_exception(mocker, default_conf, limit_buy_order, caplog) -> None:
freqtrade = get_patched_freqtradebot(mocker, default_conf)
mocker.patch('freqtrade.exchange.Exchange.get_order', return_value=limit_buy_order)
@ -1502,7 +1503,8 @@ def test_process_maybe_execute_sells_exception(mocker, default_conf,
'freqtrade.freqtradebot.FreqtradeBot.update_trade_state',
side_effect=DependencyException()
)
freqtrade.process_maybe_execute_sells(trades)
n = freqtrade.exit_positions(trades)
assert n == 0
assert log_has('Unable to sell trade: ', caplog)
@ -2391,7 +2393,7 @@ def test_execute_sell_with_stoploss_on_exchange(default_conf, ticker, fee, ticke
assert trade
trades = [trade]
freqtrade.process_maybe_execute_sells(trades)
freqtrade.exit_positions(trades)
# Increase the price and sell it
mocker.patch.multiple(
@ -2438,7 +2440,7 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, ticker, f
freqtrade.process_maybe_execute_buys()
trade = Trade.query.first()
trades = [trade]
freqtrade.process_maybe_execute_sells(trades)
freqtrade.exit_positions(trades)
assert trade
assert trade.stoploss_order_id == '123'
assert trade.open_order_id is None
@ -2466,7 +2468,7 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, ticker, f
})
mocker.patch('freqtrade.exchange.Exchange.get_order', stoploss_limit_executed)
freqtrade.process_maybe_execute_sells(trades)
freqtrade.exit_positions(trades)
assert trade.stoploss_order_id is None
assert trade.is_open is False
assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value

View File

@ -90,7 +90,8 @@ def test_may_execute_sell_stoploss_on_exchange_multi(default_conf, ticker, fee,
trade.stoploss_order_id = 3
trade.open_order_id = None
freqtrade.process_maybe_execute_sells(trades)
n = freqtrade.exit_positions(trades)
assert n == 2
assert should_sell_mock.call_count == 2
# Only order for 3rd trade needs to be cancelled
@ -170,7 +171,8 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc
assert len(trades) == 5
bals = freqtrade.wallets.get_all_balances()
freqtrade.process_maybe_execute_sells(trades)
n = freqtrade.exit_positions(trades)
assert n == 1
trades = Trade.get_open_trades()
# One trade sold
assert len(trades) == 4