mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Rename process_maybe_execute_sells() --> exit_positions()
This commit is contained in:
parent
b00406a7eb
commit
84918ad424
|
@ -132,8 +132,8 @@ class FreqtradeBot:
|
||||||
self.dataprovider.refresh(self._create_pair_whitelist(self.active_pair_whitelist),
|
self.dataprovider.refresh(self._create_pair_whitelist(self.active_pair_whitelist),
|
||||||
self.strategy.informative_pairs())
|
self.strategy.informative_pairs())
|
||||||
|
|
||||||
# First process current opened trades
|
# First process current opened trades (positions)
|
||||||
self.process_maybe_execute_sells(trades)
|
self.exit_positions(trades)
|
||||||
|
|
||||||
# Then looking for buy opportunities
|
# Then looking for buy opportunities
|
||||||
if self.get_free_open_trades():
|
if self.get_free_open_trades():
|
||||||
|
@ -493,9 +493,9 @@ class FreqtradeBot:
|
||||||
|
|
||||||
return trades_created
|
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
|
trades_closed = 0
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
|
|
|
@ -990,7 +990,7 @@ def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None
|
||||||
trade.is_open = True
|
trade.is_open = True
|
||||||
trades = [trade]
|
trades = [trade]
|
||||||
|
|
||||||
freqtrade.process_maybe_execute_sells(trades)
|
freqtrade.exit_positions(trades)
|
||||||
assert trade.stoploss_order_id == '13434334'
|
assert trade.stoploss_order_id == '13434334'
|
||||||
assert stoploss_limit.call_count == 1
|
assert stoploss_limit.call_count == 1
|
||||||
assert trade.is_open is True
|
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)
|
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)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
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_order_id = '123'
|
||||||
trade.open_fee = 0.001
|
trade.open_fee = 0.001
|
||||||
trades = [trade]
|
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
|
# Test amount not modified by fee-logic
|
||||||
assert not log_has(
|
assert not log_has(
|
||||||
'Applying fee to amount for Trade {} from 90.99181073 to 90.81'.format(trade), caplog
|
'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)
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', return_value=90.81)
|
||||||
# test amount modified by fee-logic
|
# 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,
|
def test_exit_positions_exception(mocker, default_conf, limit_buy_order, caplog) -> None:
|
||||||
limit_buy_order, caplog) -> None:
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_order', return_value=limit_buy_order)
|
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',
|
'freqtrade.freqtradebot.FreqtradeBot.update_trade_state',
|
||||||
side_effect=DependencyException()
|
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)
|
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
|
assert trade
|
||||||
trades = [trade]
|
trades = [trade]
|
||||||
|
|
||||||
freqtrade.process_maybe_execute_sells(trades)
|
freqtrade.exit_positions(trades)
|
||||||
|
|
||||||
# Increase the price and sell it
|
# Increase the price and sell it
|
||||||
mocker.patch.multiple(
|
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()
|
freqtrade.process_maybe_execute_buys()
|
||||||
trade = Trade.query.first()
|
trade = Trade.query.first()
|
||||||
trades = [trade]
|
trades = [trade]
|
||||||
freqtrade.process_maybe_execute_sells(trades)
|
freqtrade.exit_positions(trades)
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.stoploss_order_id == '123'
|
assert trade.stoploss_order_id == '123'
|
||||||
assert trade.open_order_id is None
|
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)
|
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.stoploss_order_id is None
|
||||||
assert trade.is_open is False
|
assert trade.is_open is False
|
||||||
assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value
|
assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value
|
||||||
|
|
|
@ -90,7 +90,8 @@ def test_may_execute_sell_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
||||||
trade.stoploss_order_id = 3
|
trade.stoploss_order_id = 3
|
||||||
trade.open_order_id = None
|
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
|
assert should_sell_mock.call_count == 2
|
||||||
|
|
||||||
# Only order for 3rd trade needs to be cancelled
|
# 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
|
assert len(trades) == 5
|
||||||
bals = freqtrade.wallets.get_all_balances()
|
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()
|
trades = Trade.get_open_trades()
|
||||||
# One trade sold
|
# One trade sold
|
||||||
assert len(trades) == 4
|
assert len(trades) == 4
|
||||||
|
|
Loading…
Reference in New Issue
Block a user