Coverage for src/finbot/strategy/strategies.py: 100%
20 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 17:12 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 17:12 +0000
1import random
3from finbot.market.models import Bar
4from finbot.strategy.base import Strategy
5from finbot.strategy.signal import Signal, SignalDirection
8class RandomStrategy(Strategy):
9 def on_bar(self, bar: Bar) -> Signal | None:
10 n = random.randint(1, 100)
11 if n == 42:
12 return Signal(symbol=bar.symbol, direction=SignalDirection.LONG)
13 if n == 69:
14 return Signal(symbol=bar.symbol, direction=SignalDirection.SHORT)
16 return None
19class BuyOnceStrategy(Strategy):
20 def __init__(self) -> None:
21 self._signaled_symbols: set[str] = set()
23 def on_bar(self, bar: Bar) -> Signal | None:
24 if bar.symbol in self._signaled_symbols:
25 return None
27 self._signaled_symbols.add(bar.symbol)
29 return Signal(symbol=bar.symbol, direction=SignalDirection.LONG)