Use commit instead of .flush()
This commit is contained in:
parent
eaa47ff335
commit
6fb32c3594
@ -187,7 +187,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
if self.get_free_open_trades():
|
||||
self.enter_positions()
|
||||
|
||||
Trade.query.session.flush()
|
||||
Trade.query.session.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.flush()
|
||||
Trade.query.session.commit()
|
||||
|
||||
# Updating wallets
|
||||
self.wallets.update()
|
||||
@ -706,6 +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()
|
||||
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):
|
||||
@ -1036,6 +1037,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
|
||||
elif order['side'] == 'sell':
|
||||
self.handle_cancel_sell(trade, order, constants.CANCEL_REASON['ALL_CANCELLED'])
|
||||
Trade.query.session.commit()
|
||||
|
||||
def handle_cancel_buy(self, trade: Trade, order: Dict, reason: str) -> bool:
|
||||
"""
|
||||
@ -1233,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.flush()
|
||||
Trade.query.session.commit()
|
||||
|
||||
# Lock pair for one candle to prevent immediate re-buys
|
||||
self.strategy.lock_pair(trade.pair, datetime.now(timezone.utc),
|
||||
@ -1374,6 +1376,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
# Handling of this will happen in check_handle_timeout.
|
||||
return True
|
||||
trade.update(order)
|
||||
Trade.query.session.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.flush()
|
||||
Trade.query.session.commit()
|
||||
|
||||
|
||||
def clean_dry_run_db() -> None:
|
||||
@ -86,6 +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()
|
||||
|
||||
|
||||
class Order(_DECL_BASE):
|
||||
@ -174,6 +175,7 @@ class Order(_DECL_BASE):
|
||||
if filtered_orders:
|
||||
oobj = filtered_orders[0]
|
||||
oobj.update_from_ccxt_object(order)
|
||||
Order.query.session.commit()
|
||||
else:
|
||||
logger.warning(f"Did not find order for {order}.")
|
||||
|
||||
@ -709,7 +711,7 @@ class Trade(_DECL_BASE, LocalTrade):
|
||||
Order.query.session.delete(order)
|
||||
|
||||
Trade.query.session.delete(self)
|
||||
Trade.query.session.flush()
|
||||
Trade.query.session.commit()
|
||||
|
||||
@staticmethod
|
||||
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
||||
|
@ -49,7 +49,7 @@ class PairLocks():
|
||||
)
|
||||
if PairLocks.use_db:
|
||||
PairLock.query.session.add(lock)
|
||||
PairLock.query.session.flush()
|
||||
PairLock.query.session.commit()
|
||||
else:
|
||||
PairLocks.locks.append(lock)
|
||||
|
||||
@ -99,7 +99,7 @@ class PairLocks():
|
||||
for lock in locks:
|
||||
lock.active = False
|
||||
if PairLocks.use_db:
|
||||
PairLock.query.session.flush()
|
||||
PairLock.query.session.commit()
|
||||
|
||||
@staticmethod
|
||||
def is_global_lock(now: Optional[datetime] = None) -> bool:
|
||||
|
@ -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.flush()
|
||||
Trade.query.session.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.flush()
|
||||
Trade.query.session.commit()
|
||||
self._freqtrade.wallets.update()
|
||||
return {'result': f'Created sell order for trade {trade_id}.'}
|
||||
|
||||
@ -705,8 +705,7 @@ class RPC:
|
||||
lock.active = False
|
||||
lock.lock_end_time = datetime.now(timezone.utc)
|
||||
|
||||
# session is always the same
|
||||
PairLock.query.session.flush()
|
||||
PairLock.query.session.commit()
|
||||
|
||||
return self._rpc_locks()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user