Add Rollback function to Trade

simplifies Session work
This commit is contained in:
Matthias 2022-08-06 15:08:13 +02:00
parent 45d68222a1
commit 5250189f77
5 changed files with 10 additions and 5 deletions

View File

@ -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,

View File

@ -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')

View File

@ -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()

View File

@ -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__,

View File

@ -2375,6 +2375,7 @@ def test_Trade_object_idem():
'delete',
'session',
'commit',
'rollback',
'query',
'open_date',
'get_best_pair',