2024-01-10 18:53:06 +00:00
|
|
|
|
2024-02-12 19:14:37 +00:00
|
|
|
from freqtrade.persistence.custom_data import CustomDataWrapper
|
2024-01-10 18:53:06 +00:00
|
|
|
from freqtrade.persistence.pairlock_middleware import PairLocks
|
|
|
|
from freqtrade.persistence.trade_model import Trade
|
|
|
|
|
|
|
|
|
|
|
|
def disable_database_use(timeframe: str) -> None:
|
|
|
|
"""
|
|
|
|
Disable database usage for PairLocks and Trade models.
|
|
|
|
Used for backtesting, and some other utility commands.
|
|
|
|
"""
|
|
|
|
PairLocks.use_db = False
|
|
|
|
PairLocks.timeframe = timeframe
|
|
|
|
Trade.use_db = False
|
2024-02-12 17:25:02 +00:00
|
|
|
CustomDataWrapper.use_db = False
|
2024-01-10 18:53:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def enable_database_use() -> None:
|
|
|
|
"""
|
|
|
|
Cleanup function to restore database usage.
|
|
|
|
"""
|
|
|
|
PairLocks.use_db = True
|
|
|
|
PairLocks.timeframe = ''
|
|
|
|
Trade.use_db = True
|
2024-02-07 06:13:41 +00:00
|
|
|
CustomDataWrapper.use_db = True
|
2024-01-10 19:01:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FtNoDBContext:
|
|
|
|
def __init__(self, timeframe: str = ''):
|
|
|
|
self.timeframe = timeframe
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
disable_database_use(self.timeframe)
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
|
|
enable_database_use()
|