Add Trade.commit method for easy use
This commit is contained in:
parent
6fb32c3594
commit
a01d05997e
@ -187,7 +187,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
if self.get_free_open_trades():
|
||||
self.enter_positions()
|
||||
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
def process_stopped(self) -> None:
|
||||
"""
|
||||
@ -620,7 +620,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
self.update_trade_state(trade, order_id, order)
|
||||
|
||||
Trade.query.session.add(trade)
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
# Updating wallets
|
||||
self.wallets.update()
|
||||
@ -706,7 +706,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
if (self.strategy.order_types.get('stoploss_on_exchange') and
|
||||
self.handle_stoploss_on_exchange(trade)):
|
||||
trades_closed += 1
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
continue
|
||||
# Check if we can sell our current pair
|
||||
if trade.open_order_id is None and trade.is_open and self.handle_trade(trade):
|
||||
@ -1037,7 +1037,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
|
||||
elif order['side'] == 'sell':
|
||||
self.handle_cancel_sell(trade, order, constants.CANCEL_REASON['ALL_CANCELLED'])
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
def handle_cancel_buy(self, trade: Trade, order: Dict, reason: str) -> bool:
|
||||
"""
|
||||
@ -1235,7 +1235,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
# In case of market sell orders the order can be closed immediately
|
||||
if order.get('status', 'unknown') == 'closed':
|
||||
self.update_trade_state(trade, trade.open_order_id, order)
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
# Lock pair for one candle to prevent immediate re-buys
|
||||
self.strategy.lock_pair(trade.pair, datetime.now(timezone.utc),
|
||||
@ -1376,7 +1376,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
# Handling of this will happen in check_handle_timeout.
|
||||
return True
|
||||
trade.update(order)
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
# Updating wallets when order is closed
|
||||
if not trade.is_open:
|
||||
|
@ -74,7 +74,7 @@ def cleanup_db() -> None:
|
||||
Flushes all pending operations to disk.
|
||||
:return: None
|
||||
"""
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
|
||||
def clean_dry_run_db() -> None:
|
||||
@ -86,7 +86,7 @@ def clean_dry_run_db() -> None:
|
||||
# Check we are updating only a dry_run order not a prod one
|
||||
if 'dry_run' in trade.open_order_id:
|
||||
trade.open_order_id = None
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
|
||||
class Order(_DECL_BASE):
|
||||
@ -711,6 +711,10 @@ class Trade(_DECL_BASE, LocalTrade):
|
||||
Order.query.session.delete(order)
|
||||
|
||||
Trade.query.session.delete(self)
|
||||
Trade.commit()
|
||||
|
||||
@staticmethod
|
||||
def commit():
|
||||
Trade.query.session.commit()
|
||||
|
||||
@staticmethod
|
||||
|
@ -569,7 +569,7 @@ class RPC:
|
||||
# Execute sell for all open orders
|
||||
for trade in Trade.get_open_trades():
|
||||
_exec_forcesell(trade)
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
self._freqtrade.wallets.update()
|
||||
return {'result': 'Created sell orders for all open trades.'}
|
||||
|
||||
@ -582,7 +582,7 @@ class RPC:
|
||||
raise RPCException('invalid argument')
|
||||
|
||||
_exec_forcesell(trade)
|
||||
Trade.query.session.commit()
|
||||
Trade.commit()
|
||||
self._freqtrade.wallets.update()
|
||||
return {'result': f'Created sell order for trade {trade_id}.'}
|
||||
|
||||
|
@ -1291,6 +1291,7 @@ def test_Trade_object_idem():
|
||||
excludes = (
|
||||
'delete',
|
||||
'session',
|
||||
'commit',
|
||||
'query',
|
||||
'open_date',
|
||||
'get_best_pair',
|
||||
|
Loading…
Reference in New Issue
Block a user