summaryrefslogtreecommitdiff
path: root/services/strategy-engine/tests/test_vwap_strategy.py
diff options
context:
space:
mode:
Diffstat (limited to 'services/strategy-engine/tests/test_vwap_strategy.py')
-rw-r--r--services/strategy-engine/tests/test_vwap_strategy.py50
1 files changed, 48 insertions, 2 deletions
diff --git a/services/strategy-engine/tests/test_vwap_strategy.py b/services/strategy-engine/tests/test_vwap_strategy.py
index 5d76b04..2cc4766 100644
--- a/services/strategy-engine/tests/test_vwap_strategy.py
+++ b/services/strategy-engine/tests/test_vwap_strategy.py
@@ -1,6 +1,6 @@
"""Tests for the VWAP strategy."""
-from datetime import datetime, timezone
+from datetime import datetime, timezone, timedelta
from decimal import Decimal
@@ -13,15 +13,18 @@ def make_candle(
high: float | None = None,
low: float | None = None,
volume: float = 1.0,
+ open_time: datetime | None = None,
) -> Candle:
if high is None:
high = close
if low is None:
low = close
+ if open_time is None:
+ open_time = datetime(2024, 1, 1, tzinfo=timezone.utc)
return Candle(
symbol="BTC/USDT",
timeframe="1m",
- open_time=datetime(2024, 1, 1, tzinfo=timezone.utc),
+ open_time=open_time,
open=Decimal(str(close)),
high=Decimal(str(high)),
low=Decimal(str(low)),
@@ -99,3 +102,46 @@ def test_vwap_reset_clears_state():
assert strategy._candle_count == 0
assert strategy._was_below_vwap is False
assert strategy._was_above_vwap is False
+ assert strategy._current_date is None
+ assert len(strategy._tp_values) == 0
+ assert len(strategy._vwap_values) == 0
+
+
+def test_vwap_daily_reset():
+ """Candles from two different dates cause VWAP to reset."""
+ strategy = _configured_strategy()
+
+ day1 = datetime(2024, 1, 1, tzinfo=timezone.utc)
+ day2 = datetime(2024, 1, 2, tzinfo=timezone.utc)
+
+ # Feed 35 candles on day 1 to build VWAP state
+ for i in range(35):
+ strategy.on_candle(make_candle(100.0, high=101.0, low=99.0, open_time=day1))
+
+ # Verify state is built up
+ assert strategy._candle_count == 35
+ assert strategy._cumulative_vol > 0
+ assert strategy._current_date == "2024-01-01"
+
+ # Feed first candle of day 2 — should reset
+ strategy.on_candle(make_candle(100.0, high=101.0, low=99.0, open_time=day2))
+
+ # After reset, candle_count should be 1 (the new candle)
+ assert strategy._candle_count == 1
+ assert strategy._current_date == "2024-01-02"
+
+
+def test_vwap_reset_clears_date():
+ """Verify reset() clears _current_date and deviation band state."""
+ strategy = _configured_strategy()
+
+ for _ in range(35):
+ strategy.on_candle(make_candle(100.0))
+
+ assert strategy._current_date is not None
+
+ strategy.reset()
+
+ assert strategy._current_date is None
+ assert len(strategy._tp_values) == 0
+ assert len(strategy._vwap_values) == 0