Update more .query usages
This commit is contained in:
parent
8865af9104
commit
ae361e1d5d
@ -37,7 +37,8 @@ class PairLock(ModelBase):
|
|||||||
f'lock_end_time={lock_end_time}, reason={self.reason}, active={self.active})')
|
f'lock_end_time={lock_end_time}, reason={self.reason}, active={self.active})')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def query_pair_locks(pair: Optional[str], now: datetime, side: str = '*') -> ScalarResult['PairLock']:
|
def query_pair_locks(
|
||||||
|
pair: Optional[str], now: datetime, side: str = '*') -> ScalarResult['PairLock']:
|
||||||
"""
|
"""
|
||||||
Get all currently active locks for this pair
|
Get all currently active locks for this pair
|
||||||
:param pair: Pair to check for. Returns all current locks if pair is empty
|
:param pair: Pair to check for. Returns all current locks if pair is empty
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Sequence
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ class PairLocks():
|
|||||||
return lock
|
return lock
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_pair_locks(
|
def get_pair_locks(pair: Optional[str], now: Optional[datetime] = None,
|
||||||
pair: Optional[str], now: Optional[datetime] = None, side: str = '*') -> List[PairLock]:
|
side: str = '*') -> Sequence[PairLock]:
|
||||||
"""
|
"""
|
||||||
Get all currently active locks for this pair
|
Get all currently active locks for this pair
|
||||||
:param pair: Pair to check for. Returns all current locks if pair is empty
|
:param pair: Pair to check for. Returns all current locks if pair is empty
|
||||||
@ -167,7 +167,7 @@ class PairLocks():
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_locks() -> List[PairLock]:
|
def get_all_locks() -> Sequence[PairLock]:
|
||||||
"""
|
"""
|
||||||
Return all locks, also locks with expired end date
|
Return all locks, also locks with expired end date
|
||||||
"""
|
"""
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from math import isclose
|
from math import isclose
|
||||||
from typing import Any, ClassVar, Dict, List, Optional, cast
|
from typing import Any, ClassVar, Dict, List, Optional, Sequence, cast
|
||||||
|
|
||||||
from sqlalchemy import (Enum, Float, ForeignKey, Integer, ScalarResult, Select, String,
|
from sqlalchemy import (Enum, Float, ForeignKey, Integer, ScalarResult, Select, String,
|
||||||
UniqueConstraint, desc, func, select)
|
UniqueConstraint, desc, func, select)
|
||||||
@ -263,12 +263,12 @@ class Order(ModelBase):
|
|||||||
return o
|
return o
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_open_orders() -> List['Order']:
|
def get_open_orders() -> Sequence['Order']:
|
||||||
"""
|
"""
|
||||||
Retrieve open orders from the database
|
Retrieve open orders from the database
|
||||||
:return: List of open orders
|
:return: List of open orders
|
||||||
"""
|
"""
|
||||||
return Order.query.filter(Order.ft_is_open.is_(True)).all()
|
return Order.session.scalars(select(Order).filter(Order.ft_is_open.is_(True))).all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def order_by_id(order_id: str) -> Optional['Order']:
|
def order_by_id(order_id: str) -> Optional['Order']:
|
||||||
@ -276,7 +276,7 @@ class Order(ModelBase):
|
|||||||
Retrieve order based on order_id
|
Retrieve order based on order_id
|
||||||
:return: Order or None
|
:return: Order or None
|
||||||
"""
|
"""
|
||||||
return Order.query.filter(Order.order_id == order_id).first()
|
return Order.session.scalars(select(Order).filter(Order.order_id == order_id)).first()
|
||||||
|
|
||||||
|
|
||||||
class LocalTrade():
|
class LocalTrade():
|
||||||
|
@ -954,12 +954,12 @@ class RPC:
|
|||||||
def _rpc_delete_lock(self, lockid: Optional[int] = None,
|
def _rpc_delete_lock(self, lockid: Optional[int] = None,
|
||||||
pair: Optional[str] = None) -> Dict[str, Any]:
|
pair: Optional[str] = None) -> Dict[str, Any]:
|
||||||
""" Delete specific lock(s) """
|
""" Delete specific lock(s) """
|
||||||
locks = []
|
locks: Sequence[PairLock] = []
|
||||||
|
|
||||||
if pair:
|
if pair:
|
||||||
locks = PairLocks.get_pair_locks(pair)
|
locks = PairLocks.get_pair_locks(pair)
|
||||||
if lockid:
|
if lockid:
|
||||||
locks = PairLock.session.scalar(select(PairLock).filter(PairLock.id == lockid)).all()
|
locks = PairLock.session.scalars(select(PairLock).filter(PairLock.id == lockid)).all()
|
||||||
|
|
||||||
for lock in locks:
|
for lock in locks:
|
||||||
lock.active = False
|
lock.active = False
|
||||||
|
Loading…
Reference in New Issue
Block a user