44from datetime import date
55import unittest
66
7- from quant_platform_kit .ibkr .market_data import fetch_historical_price_series , fetch_quote_snapshots
7+ from quant_platform_kit .ibkr .market_data import (
8+ fetch_historical_price_candles ,
9+ fetch_historical_price_series ,
10+ fetch_quote_snapshots ,
11+ )
812
913
1014@dataclass
@@ -18,6 +22,10 @@ class FakeContract:
1822class FakeBar :
1923 date : date
2024 close : float
25+ open : float = 0.0
26+ high : float = 0.0
27+ low : float = 0.0
28+ volume : float = 0.0
2129
2230
2331class FakeTicker :
@@ -52,8 +60,8 @@ def reqHistoricalData(self, contract, **kwargs):
5260 self .last_history_contract = contract
5361 self .last_history_kwargs = kwargs
5462 return [
55- FakeBar (date = date (2026 , 3 , 27 ), close = 100.5 ),
56- FakeBar (date = date (2026 , 3 , 28 ), close = 101.0 ),
63+ FakeBar (date = date (2026 , 3 , 27 ), open = 100.0 , high = 101.0 , low = 99.5 , close = 100.5 , volume = 1000.0 ),
64+ FakeBar (date = date (2026 , 3 , 28 ), open = 100.5 , high = 101.5 , low = 100.0 , close = 101.0 , volume = 1200 .0 ),
5765 ]
5866
5967 def reqMktData (self , contract , * _args ):
@@ -78,6 +86,20 @@ def test_fetch_historical_price_series_builds_price_points(self) -> None:
7886 self .assertEqual (ib .last_history_contract .symbol , "SPY" )
7987 self .assertEqual (ib .last_history_kwargs ["durationStr" ], "2 Y" )
8088
89+ def test_fetch_historical_price_candles_exposes_ohlc_fields (self ) -> None :
90+ ib = FakeIB ()
91+ candles = fetch_historical_price_candles (
92+ ib ,
93+ "QQQ" ,
94+ stock_factory = FakeContract ,
95+ )
96+
97+ self .assertEqual (candles [- 1 ]["close" ], 101.0 )
98+ self .assertEqual (candles [- 1 ]["open" ], 100.5 )
99+ self .assertEqual (candles [- 1 ]["high" ], 101.5 )
100+ self .assertEqual (candles [- 1 ]["low" ], 100.0 )
101+ self .assertEqual (candles [- 1 ]["volume" ], 1200.0 )
102+
81103 def test_fetch_quote_snapshots_returns_last_price (self ) -> None :
82104 ib = FakeIB ()
83105 snapshots = fetch_quote_snapshots (
0 commit comments