Deleting must delete orders first
This commit is contained in:
parent
b7662722ba
commit
a78d61150c
@ -1118,8 +1118,7 @@ class FreqtradeBot:
|
|||||||
if isclose(filled_amount, 0.0, abs_tol=constants.MATH_CLOSE_PREC):
|
if isclose(filled_amount, 0.0, abs_tol=constants.MATH_CLOSE_PREC):
|
||||||
logger.info('Buy order fully cancelled. Removing %s from database.', trade)
|
logger.info('Buy order fully cancelled. Removing %s from database.', trade)
|
||||||
# if trade is not partially completed, just delete the trade
|
# if trade is not partially completed, just delete the trade
|
||||||
Trade.session.delete(trade)
|
trade.delete()
|
||||||
Trade.session.flush()
|
|
||||||
was_trade_fully_canceled = True
|
was_trade_fully_canceled = True
|
||||||
else:
|
else:
|
||||||
# if trade is partially complete, edit the stake details for the trade
|
# if trade is partially complete, edit the stake details for the trade
|
||||||
|
@ -446,6 +446,14 @@ class Trade(_DECL_BASE):
|
|||||||
def update_order(self, order: Dict) -> None:
|
def update_order(self, order: Dict) -> None:
|
||||||
Order.update_orders(self.orders, order)
|
Order.update_orders(self.orders, order)
|
||||||
|
|
||||||
|
def delete(self) -> None:
|
||||||
|
|
||||||
|
for order in self.orders:
|
||||||
|
Order.session.delete(order)
|
||||||
|
|
||||||
|
Trade.session.delete(self)
|
||||||
|
Trade.session.flush()
|
||||||
|
|
||||||
def _calc_open_trade_price(self) -> float:
|
def _calc_open_trade_price(self) -> float:
|
||||||
"""
|
"""
|
||||||
Calculate the open_rate including open_fee.
|
Calculate the open_rate including open_fee.
|
||||||
|
@ -567,8 +567,7 @@ class RPC:
|
|||||||
except (ExchangeError):
|
except (ExchangeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
Trade.session.delete(trade)
|
trade.delete()
|
||||||
Trade.session.flush()
|
|
||||||
self._freqtrade.wallets.update()
|
self._freqtrade.wallets.update()
|
||||||
return {
|
return {
|
||||||
'result': 'success',
|
'result': 'success',
|
||||||
|
@ -313,7 +313,6 @@ def test_rpc_delete_trade(mocker, default_conf, fee, markets, caplog):
|
|||||||
with pytest.raises(RPCException, match='invalid argument'):
|
with pytest.raises(RPCException, match='invalid argument'):
|
||||||
rpc._rpc_delete('200')
|
rpc._rpc_delete('200')
|
||||||
|
|
||||||
create_mock_trades(fee)
|
|
||||||
trades = Trade.query.all()
|
trades = Trade.query.all()
|
||||||
trades[1].stoploss_order_id = '1234'
|
trades[1].stoploss_order_id = '1234'
|
||||||
trades[2].stoploss_order_id = '1234'
|
trades[2].stoploss_order_id = '1234'
|
||||||
|
@ -1074,6 +1074,3 @@ def test_update_order_from_ccxt():
|
|||||||
assert o.remaining == 0.0
|
assert o.remaining == 0.0
|
||||||
assert not o.ft_is_open
|
assert not o.ft_is_open
|
||||||
assert o.order_filled_date is not None
|
assert o.order_filled_date is not None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user