diff --git a/nautilus_trader/adapters/interactive_brokers/client/common.py b/nautilus_trader/adapters/interactive_brokers/client/common.py index caa22d39f3eb..7b6235fdd514 100644 --- a/nautilus_trader/adapters/interactive_brokers/client/common.py +++ b/nautilus_trader/adapters/interactive_brokers/client/common.py @@ -14,6 +14,7 @@ # ------------------------------------------------------------------------------------------------- import asyncio +import functools from abc import ABC from abc import abstractmethod from collections.abc import Callable @@ -70,7 +71,7 @@ class Subscription(msgspec.Struct, frozen=True): req_id: Annotated[int, msgspec.Meta(gt=0)] name: str | tuple - handle: Callable + handle: functools.partial | Callable cancel: Callable last: Any diff --git a/nautilus_trader/adapters/interactive_brokers/client/market_data.py b/nautilus_trader/adapters/interactive_brokers/client/market_data.py index c27e47d5e2ec..a3ecdb4cbd78 100644 --- a/nautilus_trader/adapters/interactive_brokers/client/market_data.py +++ b/nautilus_trader/adapters/interactive_brokers/client/market_data.py @@ -78,7 +78,7 @@ async def set_market_data_type(self, market_data_type: MarketDataTypeEnum) -> No async def _subscribe( self, name: str | tuple, - subscription_method: Callable, + subscription_method: Callable | functools.partial, cancellation_method: Callable, *args: Any, **kwargs: Any, @@ -274,10 +274,10 @@ async def subscribe_historical_bars( name, self.subscribe_historical_bars, self._eclient.cancelHistoricalData, - bar_type, - contract, - use_rth, - handle_revised_bars, + bar_type=bar_type, + contract=contract, + use_rth=use_rth, + handle_revised_bars=handle_revised_bars, ) if not subscription: return @@ -815,10 +815,12 @@ def historicalDataUpdate(self, req_id: int, bar: BarData) -> None: self.logAnswer(current_fn_name(), vars()) if not (subscription := self._subscriptions.get(req_id=req_id)): return + if not isinstance(subscription.handle, functools.partial): + raise TypeError(f"Expecting partial type subscription method. {subscription=}") if bar := self._process_bar_data( bar_type_str=str(subscription.name), bar=bar, - handle_revised_bars=subscription.handle().keywords.get("handle_revised_bars", False), + handle_revised_bars=subscription.handle.keywords.get("handle_revised_bars", False), ): if bar.is_single_price() and bar.open.as_double() == 0: self._log.debug(f"Ignoring Zero priced {bar=}")