Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend_api_python/app/data_sources/us_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ def get_kline(


klines = self._fetch_yahoo_chart(symbol, interval, start_date, end_date, effective_limit)
if klines and merge_factor > 1:
klines = self._merge_every_n_sorted_bars(klines, merge_factor)
if not klines:
if timeframe in ('1m', '3m', '5m', '15m', '30m', '1H', '4H'):
# Nasdaq's intraday chart is a latest-session feed, not a
Expand Down
44 changes: 44 additions & 0 deletions backend_api_python/tests/test_us_stock_intraday_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,47 @@ def history(self, **kwargs):

assert captured["start"] == start
assert captured["end"] == end


class _MinuteChartResponse:
def __init__(self, start_ts, count):
self._timestamps = [start_ts + 60 * i for i in range(count)]

def raise_for_status(self):
return None

def json(self):
n = len(self._timestamps)
return {"chart": {"result": [{
"timestamp": self._timestamps,
"indicators": {"quote": [{
"open": [100.0 + i for i in range(n)],
"high": [101.0 + i for i in range(n)],
"low": [99.0 + i for i in range(n)],
"close": [100.5 + i for i in range(n)],
"volume": [10] * n,
}]},
}]}}


def test_three_minute_klines_from_yahoo_chart_are_merged(monkeypatch):
session_open = int(datetime(2026, 9, 14, 13, 30).timestamp())
captured = {}

def fake_get(_url, **kwargs):
captured.update(kwargs["params"])
return _MinuteChartResponse(session_open, 6)

monkeypatch.setattr(us_stock.requests, "get", fake_get)
source = USStockDataSource.__new__(USStockDataSource)

bars = source.get_kline("NVDA", "3m", 2, before_time=session_open + 3600)

assert captured["interval"] == "1m"
assert [bar["time"] for bar in bars] == [session_open, session_open + 180]
assert bars[0]["open"] == 100.0
assert bars[0]["high"] == 103.0
assert bars[0]["low"] == 99.0
assert bars[0]["close"] == 102.5
assert bars[0]["volume"] == 30
assert bars[1]["close"] == 105.5