Update function name from update_open_order to update_trade_state

This commit is contained in:
Matthias 2019-04-02 07:12:48 +02:00
parent 7be90f71d3
commit 0cfdce0d5e
2 changed files with 13 additions and 21 deletions

View File

@ -502,7 +502,7 @@ class FreqtradeBot(object):
# Update fees if order is closed
if order_status == 'closed':
self.update_open_order(trade, order)
self.update_trade_state(trade, order)
Trade.session.add(trade)
Trade.session.flush()
@ -534,7 +534,7 @@ class FreqtradeBot(object):
:return: True if executed
"""
try:
self.update_open_order(trade)
self.update_trade_state(trade)
if self.strategy.order_types.get('stoploss_on_exchange') and trade.is_open:
result = self.handle_stoploss_on_exchange(trade)
@ -599,7 +599,7 @@ class FreqtradeBot(object):
f"(from {order_amount} to {real_amount}) from Trades")
return real_amount
def update_open_order(self, trade, action_order: dict = None):
def update_trade_state(self, trade, action_order: dict = None):
"""
Checks trades with open orders and updates the amount if necessary
"""

View File

@ -1288,14 +1288,6 @@ def test_process_maybe_execute_sell(mocker, default_conf, limit_buy_order, caplo
# test amount modified by fee-logic
assert not freqtrade.process_maybe_execute_sell(trade)
trade.is_open = True
trade.open_order_id = None
# Assert we call handle_trade() if trade is feasible for execution
freqtrade.update_open_order(trade)
regexp = re.compile('Found open order for.*')
assert filter(regexp.match, caplog.record_tuples)
def test_process_maybe_execute_sell_exception(mocker, default_conf,
limit_buy_order, caplog) -> None:
@ -1308,14 +1300,14 @@ def test_process_maybe_execute_sell_exception(mocker, default_conf,
# Test raise of DependencyException exception
mocker.patch(
'freqtrade.freqtradebot.FreqtradeBot.update_open_order',
'freqtrade.freqtradebot.FreqtradeBot.update_trade_state',
side_effect=DependencyException()
)
freqtrade.process_maybe_execute_sell(trade)
assert log_has('Unable to sell trade: ', caplog.record_tuples)
def test_update_open_order(mocker, default_conf, limit_buy_order, caplog) -> None:
def test_update_trade_state(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))
@ -1329,7 +1321,7 @@ def test_update_open_order(mocker, default_conf, limit_buy_order, caplog) -> Non
Trade.session = MagicMock()
trade.open_order_id = '123'
trade.open_fee = 0.001
freqtrade.update_open_order(trade)
freqtrade.update_trade_state(trade)
# Test amount not modified by fee-logic
assert not log_has_re(r'Applying fee to .*', caplog.record_tuples)
assert trade.open_order_id is None
@ -1339,20 +1331,20 @@ def test_update_open_order(mocker, default_conf, limit_buy_order, caplog) -> Non
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', return_value=90.81)
assert trade.amount != 90.81
# test amount modified by fee-logic
freqtrade.update_open_order(trade)
freqtrade.update_trade_state(trade)
assert trade.amount == 90.81
assert trade.open_order_id is None
trade.is_open = True
trade.open_order_id = None
# Assert we call handle_trade() if trade is feasible for execution
freqtrade.update_open_order(trade)
freqtrade.update_trade_state(trade)
regexp = re.compile('Found open order for.*')
assert filter(regexp.match, caplog.record_tuples)
def test_update_open_order_withorderdict(default_conf, trades_for_order, limit_buy_order, mocker):
def test_update_trade_state_withorderdict(default_conf, trades_for_order, limit_buy_order, mocker):
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
# get_order should not be called!!
mocker.patch('freqtrade.exchange.Exchange.get_order', MagicMock(side_effect=ValueError))
@ -1367,13 +1359,13 @@ def test_update_open_order_withorderdict(default_conf, trades_for_order, limit_b
open_rate=0.245441,
open_order_id="123456"
)
freqtrade.update_open_order(trade, limit_buy_order)
freqtrade.update_trade_state(trade, limit_buy_order)
assert trade.amount != amount
assert trade.amount == limit_buy_order['amount']
def test_update_open_order_exception(mocker, default_conf,
limit_buy_order, caplog) -> None:
def test_update_trade_state_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)
@ -1386,7 +1378,7 @@ def test_update_open_order_exception(mocker, default_conf,
'freqtrade.freqtradebot.FreqtradeBot.get_real_amount',
side_effect=OperationalException()
)
freqtrade.update_open_order(trade)
freqtrade.update_trade_state(trade)
assert log_has('Could not update trade amount: ', caplog.record_tuples)