diff --git a/nautilus_trader/adapters/interactive_brokers/client/client.py b/nautilus_trader/adapters/interactive_brokers/client/client.py index 2f5780d09ed8..7c00587c7a13 100644 --- a/nautilus_trader/adapters/interactive_brokers/client/client.py +++ b/nautilus_trader/adapters/interactive_brokers/client/client.py @@ -1107,7 +1107,7 @@ async def get_historical_bars( endDateTime=end_date_time, durationStr=duration, barSizeSetting=bar_size_setting, - whatToShow=what_to_show[bar_type.spec.price_type], + whatToShow=what_to_show(bar_type), useRTH=use_rth, formatDate=2, keepUpToDate=False, @@ -1192,7 +1192,7 @@ async def subscribe_historical_bars( endDateTime="", durationStr=timedelta_to_duration_str(duration), barSizeSetting=bar_size_setting, - whatToShow=what_to_show[bar_type.spec.price_type], + whatToShow=what_to_show(bar_type), useRTH=use_rth, formatDate=2, keepUpToDate=True, @@ -1395,7 +1395,7 @@ async def subscribe_realtime_bars( reqId=req_id, contract=contract, barSize=bar_type.spec.step, - whatToShow=what_to_show[bar_type.spec.price_type], + whatToShow=what_to_show(bar_type), useRTH=use_rth, realTimeBarsOptions=[], ), diff --git a/nautilus_trader/adapters/interactive_brokers/historic/bar_data.py b/nautilus_trader/adapters/interactive_brokers/historic/bar_data.py index ec920980f4ed..a3d095bfb25a 100644 --- a/nautilus_trader/adapters/interactive_brokers/historic/bar_data.py +++ b/nautilus_trader/adapters/interactive_brokers/historic/bar_data.py @@ -39,6 +39,7 @@ class BarDataDownloaderConfig(ActorConfig): bar_types: list[str] handler: Callable freq: str = "1W" + request_timeout: int = 30 class BarDataDownloader(AsyncActor): @@ -67,7 +68,7 @@ async def _on_start(self): instrument_ids = {bar_type.instrument_id for bar_type in self.bar_types} for instrument_id in instrument_ids: request_id = self.request_instrument(instrument_id) - await self.await_request(request_id) + await self.await_request(request_id, timeout=self.config.request_timeout) request_dates = list(pd.date_range(self.start_time, self.end_time, freq=self.freq)) @@ -78,7 +79,7 @@ async def _on_start(self): start=request_date, end=request_date + pd.Timedelta(self.freq), ) - await self.await_request(request_id) + await self.await_request(request_id, timeout=self.config.request_timeout) self.stop() diff --git a/nautilus_trader/adapters/interactive_brokers/parsing/data.py b/nautilus_trader/adapters/interactive_brokers/parsing/data.py index 8c19803da786..3b9f5fcdb99b 100644 --- a/nautilus_trader/adapters/interactive_brokers/parsing/data.py +++ b/nautilus_trader/adapters/interactive_brokers/parsing/data.py @@ -20,6 +20,7 @@ from nautilus_trader.core.datetime import nanos_to_secs from nautilus_trader.model.data import BarAggregation from nautilus_trader.model.data import BarSpecification +from nautilus_trader.model.data import BarType from nautilus_trader.model.enums import BookAction from nautilus_trader.model.enums import OrderSide from nautilus_trader.model.enums import PriceType @@ -44,12 +45,18 @@ 4: "MidPoint", } -what_to_show = { - PriceType.ASK: "ASK", - PriceType.BID: "BID", - PriceType.LAST: "TRADES", - PriceType.MID: "MIDPOINT", -} + +def what_to_show(bar_type: BarType) -> str: + mapping = { + PriceType.ASK: "ASK", + PriceType.BID: "BID", + PriceType.LAST: "TRADES", + PriceType.MID: "MIDPOINT", + } + if str(bar_type.instrument_id.venue) == "PAXOS" and bar_type.spec.price_type == PriceType.LAST: + return "AGGTRADES" + else: + return mapping[bar_type.spec.price_type] def generate_trade_id(ts_event: int, price: float, size: Decimal) -> TradeId: diff --git a/pyproject.toml b/pyproject.toml index 23b343611701..8376d56cd747 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,13 +68,14 @@ uvloop = {version = "^0.19.0", markers = "sys_platform != 'win32'"} hiredis = {version = "^2.2.3", optional = true} redis = {version = "^5.0.1", optional = true} docker = {version = "^6.1.3", optional = true} +async-timeout = "^4.0.3" nautilus_ibapi = {version = "==1019.1", optional = true} # Pinned for stability betfair_parser = {version = "==0.7.1", optional = true} # Pinned for stability [tool.poetry.extras] betfair = ["betfair_parser"] docker = ["docker"] -ib = ["nautilus_ibapi"] +ib = ["nautilus_ibapi", "async-timeout"] redis = ["hiredis", "redis"] [tool.poetry.group.dev]