fix: align OHLCV fetch window with limit so chart seeds past 30 bars
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from hub_kline_store import (
|
||||
HUB_KLINE_REMOTE_FETCH_CAP,
|
||||
_since_ms_for_span,
|
||||
clear_series_bars,
|
||||
init_db,
|
||||
load_bars_before,
|
||||
@@ -391,6 +393,55 @@ class TestHubKlineStore(unittest.TestCase):
|
||||
self.assertGreater(int(out.get("fetched") or 0), 0)
|
||||
self.assertGreaterEqual(len(out.get("candles") or []), 19)
|
||||
|
||||
def test_since_span_matches_fetch_limit_not_need(self):
|
||||
period = TIMEFRAME_MS["15m"]
|
||||
now_ms = 1_800_000_000_000
|
||||
fetch_limit = HUB_KLINE_REMOTE_FETCH_CAP
|
||||
since = _since_ms_for_span(
|
||||
now_ms=now_ms,
|
||||
period_ms=period,
|
||||
span_bars=fetch_limit,
|
||||
cutoff_ms=0,
|
||||
)
|
||||
self.assertEqual(since, now_ms - period * fetch_limit)
|
||||
wrong_since = now_ms - period * chart_initial_limit("15m")
|
||||
self.assertGreater(since, wrong_since)
|
||||
|
||||
def test_thin_series_tail_refresh_fetches_full_window(self):
|
||||
init_db(self.db)
|
||||
period = TIMEFRAME_MS["15m"]
|
||||
now = int(time.time() * 1000)
|
||||
last_closed = last_closed_bar_open_ms("15m", now)
|
||||
bars = [
|
||||
{
|
||||
"open_time_ms": last_closed - period * (150 - i),
|
||||
"open": 100000,
|
||||
"high": 100100,
|
||||
"low": 99900,
|
||||
"close": 100050,
|
||||
"volume": 1,
|
||||
}
|
||||
for i in range(150)
|
||||
]
|
||||
fetch_calls: list[dict] = []
|
||||
|
||||
def remote_fetch(**kwargs):
|
||||
fetch_calls.append(dict(kwargs))
|
||||
return {"ok": True, "bars": bars, "price_tick": 0.01}
|
||||
|
||||
out = resolve_chart_bars(
|
||||
"binance",
|
||||
"BTC/USDT",
|
||||
"15m",
|
||||
remote_fetch,
|
||||
db_path=self.db,
|
||||
tail_refresh=True,
|
||||
)
|
||||
self.assertTrue(out.get("ok"))
|
||||
self.assertGreaterEqual(len(out.get("candles") or []), 100)
|
||||
self.assertGreater(int(out.get("fetched") or 0), 0)
|
||||
self.assertTrue(any(int(c.get("limit") or 0) > 30 for c in fetch_calls))
|
||||
|
||||
def test_resolve_before_ms_exhausted(self):
|
||||
init_db(self.db)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user