07.4.4.1.5 — Runtime Window Cleanup & Symbol Lifecycle Isolation
This commit is contained in:
@@ -26,4 +26,8 @@ class BaseStrategy(Protocol):
|
||||
|
||||
# выполнить анализ и вернуть торговый сигнал
|
||||
def analyze(self, context: StrategyContext) -> SignalResult:
|
||||
...
|
||||
|
||||
# сбросить runtime-память стратегии
|
||||
def reset_runtime(self, symbol: str | None = None) -> None:
|
||||
...
|
||||
@@ -20,4 +20,7 @@ class HoldStrategy:
|
||||
"status": context.status,
|
||||
"strategy": self.name,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
def reset_runtime(self, symbol: str | None = None) -> None:
|
||||
return
|
||||
@@ -17,6 +17,27 @@ class StrategyRegistry:
|
||||
"SCALP": ScalpStrategy(),
|
||||
}
|
||||
|
||||
# сбросить runtime-память одной стратегии
|
||||
@classmethod
|
||||
def reset_runtime(
|
||||
cls,
|
||||
name: str | None = None,
|
||||
*,
|
||||
symbol: str | None = None,
|
||||
) -> None:
|
||||
if name:
|
||||
strategy = cls.get(name)
|
||||
strategy.reset_runtime(symbol)
|
||||
return
|
||||
|
||||
for strategy in cls._strategies.values():
|
||||
strategy.reset_runtime(symbol)
|
||||
|
||||
# сбросить runtime-память всех стратегий
|
||||
@classmethod
|
||||
def reset_all_runtime(cls) -> None:
|
||||
cls.reset_runtime()
|
||||
|
||||
# получить стратегию по имени
|
||||
@classmethod
|
||||
def get(cls, name: str | None) -> BaseStrategy:
|
||||
|
||||
@@ -21,6 +21,20 @@ class ScalpStrategy:
|
||||
# для scalp допускаем чуть больше шума
|
||||
_min_direction_ratio = 0.55
|
||||
|
||||
def reset_runtime(self, symbol: str | None = None) -> None:
|
||||
if symbol is None:
|
||||
self._price_window.clear()
|
||||
return
|
||||
|
||||
normalized_symbol = symbol.upper()
|
||||
keys_to_delete = [
|
||||
key for key in self._price_window.keys()
|
||||
if key.upper() == normalized_symbol
|
||||
]
|
||||
|
||||
for key in keys_to_delete:
|
||||
self._price_window.pop(key, None)
|
||||
|
||||
def analyze(self, context: StrategyContext) -> SignalResult:
|
||||
try:
|
||||
ticker = ExchangeService().get_price(context.symbol)
|
||||
|
||||
@@ -22,6 +22,20 @@ class TrendStrategy:
|
||||
# основной таймфрейм анализа рынка
|
||||
_market_interval = "5m"
|
||||
|
||||
def reset_runtime(self, symbol: str | None = None) -> None:
|
||||
if symbol is None:
|
||||
self._price_window.clear()
|
||||
return
|
||||
|
||||
normalized_symbol = symbol.upper()
|
||||
keys_to_delete = [
|
||||
key for key in self._price_window.keys()
|
||||
if key.upper() == normalized_symbol
|
||||
]
|
||||
|
||||
for key in keys_to_delete:
|
||||
self._price_window.pop(key, None)
|
||||
|
||||
def analyze(self, context: StrategyContext) -> SignalResult:
|
||||
market = MarketAnalysisService().analyze(
|
||||
context.symbol,
|
||||
|
||||
Reference in New Issue
Block a user