Skip to content

Commit

Permalink
Fix InteractiveBrokers historical bar data bug (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsingleton authored Feb 14, 2024
1 parent 78d0d49 commit bf32484
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# -------------------------------------------------------------------------------------------------

import asyncio
import functools
from abc import ABC
from abc import abstractmethod
from collections.abc import Callable
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=}")
Expand Down

0 comments on commit bf32484

Please sign in to comment.