Simplify pairlock querying

This commit is contained in:
Matthias 2023-03-16 06:48:12 +01:00
parent ae361e1d5d
commit e579ff9532
4 changed files with 13 additions and 8 deletions

View File

@ -36,7 +36,7 @@ def start_convert_db(args: Dict[str, Any]) -> None:
session_target.commit()
for pairlock in PairLock.query:
for pairlock in PairLock.get_all_locks():
pairlock_count += 1
make_transient(pairlock)
session_target.add(pairlock)

View File

@ -56,6 +56,10 @@ class PairLock(ModelBase):
return PairLock.session.scalars(select(PairLock).filter(*filters))
@staticmethod
def get_all_locks() -> ScalarResult['PairLock']:
return PairLock.session.scalars(select(PairLock))
def to_json(self) -> Dict[str, Any]:
return {
'id': self.id,

View File

@ -172,6 +172,6 @@ class PairLocks():
Return all locks, also locks with expired end date
"""
if PairLocks.use_db:
return PairLock.session.scalars(select(PairLock)).all()
return PairLock.get_all_locks().all()
else:
return PairLocks.locks

View File

@ -1607,12 +1607,13 @@ class Trade(ModelBase, LocalTrade):
NOTE: Not supported in Backtesting.
:returns: Tuple containing (pair, profit_sum)
"""
trading_volume = Order.query.with_entities(
func.sum(Order.cost).label('volume')
).filter(
Order.order_filled_date >= start_date,
Order.status == 'closed'
).scalar()
trading_volume = Trade.session.execute(
select(
func.sum(Order.cost).label('volume')
).filter(
Order.order_filled_date >= start_date,
Order.status == 'closed'
)).scalar_one()
return trading_volume
@staticmethod