Use closed candles for trend signals

This commit is contained in:
Codex
2026-06-21 23:45:56 +03:00
parent 6b9bddeb0a
commit 85fecbfc36
2 changed files with 55 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
from __future__ import annotations
from crypto_spot_bot.market_data import _closed_candles, _is_closed_kline_row
from crypto_spot_bot.models import Candle
def test_closed_candles_excludes_current_open_interval() -> None:
candles = [
Candle(0, 100, 101, 99, 100, 10),
Candle(3_600_000, 101, 102, 100, 101, 10),
Candle(7_200_000, 102, 103, 101, 102, 10),
]
closed = _closed_candles(candles, "60", now_ms=7_200_000 + 1_000)
assert [candle.timestamp for candle in closed] == [0, 3_600_000]
def test_websocket_kline_requires_confirmed_candle() -> None:
assert _is_closed_kline_row({"start": 7_200_000, "confirm": False}, "60") is False
assert _is_closed_kline_row({"start": 7_200_000, "confirm": True}, "60") is True