mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add Rollback function to Trade
simplifies Session work
This commit is contained in:
parent
45d68222a1
commit
5250189f77
|
@ -196,7 +196,7 @@ class Order(_DECL_BASE):
|
|||
if filtered_orders:
|
||||
oobj = filtered_orders[0]
|
||||
oobj.update_from_ccxt_object(order)
|
||||
Order.query.session.commit()
|
||||
Trade.commit()
|
||||
else:
|
||||
logger.warning(f"Did not find order for {order}.")
|
||||
|
||||
|
@ -1148,6 +1148,10 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||
def commit():
|
||||
Trade.query.session.commit()
|
||||
|
||||
@staticmethod
|
||||
def rollback():
|
||||
Trade.query.session.rollback()
|
||||
|
||||
@staticmethod
|
||||
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
||||
open_date: datetime = None, close_date: datetime = None,
|
||||
|
|
|
@ -18,9 +18,9 @@ def get_rpc_optional() -> Optional[RPC]:
|
|||
def get_rpc() -> Optional[Iterator[RPC]]:
|
||||
_rpc = get_rpc_optional()
|
||||
if _rpc:
|
||||
Trade.query.session.rollback()
|
||||
Trade.rollback()
|
||||
yield _rpc
|
||||
Trade.query.session.rollback()
|
||||
Trade.rollback()
|
||||
else:
|
||||
raise RPCException('Bot is not in the correct state')
|
||||
|
||||
|
|
|
@ -876,7 +876,7 @@ class RPC:
|
|||
lock.active = False
|
||||
lock.lock_end_time = datetime.now(timezone.utc)
|
||||
|
||||
PairLock.query.session.commit()
|
||||
Trade.commit()
|
||||
|
||||
return self._rpc_locks()
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ def authorized_only(command_handler: Callable[..., None]) -> Callable[..., Any]:
|
|||
)
|
||||
return wrapper
|
||||
# Rollback session to avoid getting data stored in a transaction.
|
||||
Trade.query.session.rollback()
|
||||
Trade.rollback()
|
||||
logger.debug(
|
||||
'Executing handler: %s for chat_id: %s',
|
||||
command_handler.__name__,
|
||||
|
|
|
@ -2375,6 +2375,7 @@ def test_Trade_object_idem():
|
|||
'delete',
|
||||
'session',
|
||||
'commit',
|
||||
'rollback',
|
||||
'query',
|
||||
'open_date',
|
||||
'get_best_pair',
|
||||
|
|
Loading…
Reference in New Issue
Block a user