Remove .query from pairlock
This commit is contained in:
parent
aa54b77702
commit
8865af9104
@ -1,8 +1,8 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, ClassVar, Dict, Optional
|
from typing import Any, ClassVar, Dict, Optional
|
||||||
|
|
||||||
from sqlalchemy import String, or_
|
from sqlalchemy import ScalarResult, String, or_, select
|
||||||
from sqlalchemy.orm import Mapped, Query, QueryPropertyDescriptor, mapped_column
|
from sqlalchemy.orm import Mapped, QueryPropertyDescriptor, mapped_column
|
||||||
|
|
||||||
from freqtrade.constants import DATETIME_PRINT_FORMAT
|
from freqtrade.constants import DATETIME_PRINT_FORMAT
|
||||||
from freqtrade.persistence.base import ModelBase, SessionType
|
from freqtrade.persistence.base import ModelBase, SessionType
|
||||||
@ -37,7 +37,7 @@ 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 = '*') -> Query:
|
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
|
||||||
@ -53,9 +53,7 @@ class PairLock(ModelBase):
|
|||||||
else:
|
else:
|
||||||
filters.append(PairLock.side == '*')
|
filters.append(PairLock.side == '*')
|
||||||
|
|
||||||
return PairLock.query.filter(
|
return PairLock.session.scalars(select(PairLock).filter(*filters))
|
||||||
*filters
|
|
||||||
)
|
|
||||||
|
|
||||||
def to_json(self) -> Dict[str, Any]:
|
def to_json(self) -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
|
@ -2,6 +2,8 @@ import logging
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
from freqtrade.exchange import timeframe_to_next_date
|
from freqtrade.exchange import timeframe_to_next_date
|
||||||
from freqtrade.persistence.models import PairLock
|
from freqtrade.persistence.models import PairLock
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ class PairLocks():
|
|||||||
PairLock.active.is_(True),
|
PairLock.active.is_(True),
|
||||||
PairLock.reason == reason
|
PairLock.reason == reason
|
||||||
]
|
]
|
||||||
locks = PairLock.query.filter(*filters)
|
locks = PairLock.session.scalars(select(PairLock).filter(*filters)).all()
|
||||||
for lock in locks:
|
for lock in locks:
|
||||||
logger.info(f"Releasing lock for {lock.pair} with reason '{reason}'.")
|
logger.info(f"Releasing lock for {lock.pair} with reason '{reason}'.")
|
||||||
lock.active = False
|
lock.active = False
|
||||||
@ -170,6 +172,6 @@ class PairLocks():
|
|||||||
Return all locks, also locks with expired end date
|
Return all locks, also locks with expired end date
|
||||||
"""
|
"""
|
||||||
if PairLocks.use_db:
|
if PairLocks.use_db:
|
||||||
return PairLock.query.all()
|
return PairLock.session.scalars(select(PairLock)).all()
|
||||||
else:
|
else:
|
||||||
return PairLocks.locks
|
return PairLocks.locks
|
||||||
|
@ -959,7 +959,7 @@ class RPC:
|
|||||||
if pair:
|
if pair:
|
||||||
locks = PairLocks.get_pair_locks(pair)
|
locks = PairLocks.get_pair_locks(pair)
|
||||||
if lockid:
|
if lockid:
|
||||||
locks = PairLock.query.filter(PairLock.id == lockid).all()
|
locks = PairLock.session.scalar(select(PairLock).filter(PairLock.id == lockid)).all()
|
||||||
|
|
||||||
for lock in locks:
|
for lock in locks:
|
||||||
lock.active = False
|
lock.active = False
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
from freqtrade.constants import Config
|
from freqtrade.constants import Config
|
||||||
from freqtrade.enums.tradingmode import TradingMode
|
from freqtrade.enums.tradingmode import TradingMode
|
||||||
@ -44,7 +45,7 @@ def _migrate_binance_futures_db(config: Config):
|
|||||||
# Should symbol be migrated too?
|
# Should symbol be migrated too?
|
||||||
# order.symbol = new_pair
|
# order.symbol = new_pair
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
pls = PairLock.query.filter(PairLock.pair.notlike('%:%'))
|
pls = PairLock.session.scalars(select(PairLock).filter(PairLock.pair.notlike('%:%'))).all()
|
||||||
for pl in pls:
|
for pl in pls:
|
||||||
pl.pair = f"{pl.pair}:{config['stake_currency']}"
|
pl.pair = f"{pl.pair}:{config['stake_currency']}"
|
||||||
# print(pls)
|
# print(pls)
|
||||||
|
Loading…
Reference in New Issue
Block a user