Skip to content

Commit 190edb2

Browse files
authored
Prefer delayed IBKR quote snapshots (#67)
1 parent 6f71766 commit 190edb2

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/quant_platform_kit/ibkr/market_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ def fetch_quote_snapshots(
253253
attempts_per_data_type = max(int(attempts_per_data_type or 1), 1)
254254

255255
setter = getattr(ib, "reqMarketDataType", None)
256-
market_data_types = (1, 2, 4) if callable(setter) else (1,)
256+
# Prefer delayed data before live data so accounts without live subscriptions do
257+
# not emit noisy IBKR 10089 permission errors before falling back.
258+
market_data_types = (3, 4, 1, 2) if callable(setter) else (1,)
257259

258260
try:
259261
for market_data_type in market_data_types:

tests/test_ibkr_market_data.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def reqMktData(self, contract, *_args):
237237
key = (self.market_data_type, contract.symbol)
238238
attempt = self.market_data_attempts.get(key, 0)
239239
self.market_data_attempts[key] = attempt + 1
240-
if self.market_data_type == 1 and attempt == 0:
240+
if self.market_data_type == 3 and attempt == 0:
241241
return FakeTicker(-1.0, close=float("nan"), bid=None, ask=None)
242242
return FakeTicker(101.8, close=101.8, bid=101.7, ask=101.9)
243243

@@ -252,7 +252,8 @@ def reqMktData(self, contract, *_args):
252252
)
253253

254254
self.assertEqual(snapshots["SPY"].last_price, 101.8)
255-
self.assertEqual(ib.market_data_attempts[(1, "SPY")], 2)
255+
self.assertEqual(ib.market_data_attempts[(3, "SPY")], 2)
256+
self.assertEqual(ib.market_data_type_calls, [3, 1])
256257
self.assertNotIn(2, ib.market_data_type_calls)
257258
self.assertNotIn(4, ib.market_data_type_calls)
258259

@@ -269,9 +270,9 @@ def reqMarketDataType(self, market_data_type):
269270

270271
def reqMktData(self, contract, *_args):
271272
self.last_market_data_contract = contract
272-
if self.market_data_type == 1:
273+
if self.market_data_type == 3:
273274
return FakeTicker(-1.0, close=float("nan"), bid=None, ask=None)
274-
if self.market_data_type == 2:
275+
if self.market_data_type == 4:
275276
return FakeTicker(-1.0, close=float("nan"), bid=None, ask=None)
276277
return FakeTicker(-1.0, close=101.8, bid=None, ask=None)
277278

@@ -284,7 +285,7 @@ def reqMktData(self, contract, *_args):
284285
)
285286

286287
self.assertEqual(snapshots["SPY"].last_price, 101.8)
287-
self.assertEqual(ib.market_data_type_calls, [1, 2, 4, 1])
288+
self.assertEqual(ib.market_data_type_calls, [3, 4, 1, 1])
288289

289290

290291
if __name__ == "__main__":

0 commit comments

Comments
 (0)