Repository: nautechsystems/nautilus_trader
File: nautilus_trader/adapters/interactive_brokers/client/market_data.py (Python)

Code before:
                instrument_id=instrument_id,
                bid_price=instrument.make_price(converted_bid_price),
                ask_price=instrument.make_price(converted_ask_price),
                bid_size=instrument.make_qty(bid_size),
                ask_size=instrument.make_qty(ask_size),
                ts_event=ts_event,
                ts_init=ts_event,
            )

            await self._handle_data(quote_tick)

    async def _try_create_index_price_tick_from_market_data(
        self,
        subscription: Subscription,
        req_id: int,
    ) -> None:
        if req_id not in self._subscription_tick_data:
            return

        tick_data = self._subscription_tick_data[req_id]

        price = tick_data.get(4)  # IB tick type 4 = LAST_PRICE for index market data

        if price is not None:
            instrument_id = InstrumentId.from_str(subscription.name[0])
            instrument = self._cache.instrument(instrument_id)
            ts_event = self._clock.timestamp_ns()
            price_magnifier = (
                self._instrument_provider.get_price_magnifier(instrument_id)
                if self._instrument_provider
                else 1
            )
            converted_price = ib_price_to_nautilus_price(price, price_magnifier)

            index_price_update = IndexPriceUpdate(
                instrument_id=instrument_id,
                value=instrument.make_price(converted_price),
                ts_event=ts_event,
                ts_init=ts_event,
            )

            await self._handle_data(index_price_update)

    async def process_realtime_bar(
        self,
        *,
        req_id: int,
        time: int,
        open_: float,
        high: float,
        low: float,

Review comment (suggestion):
We should check for `None` here, log an error and return (common pattern in other adapters). This is clearer than an attribute error on a `NoneType` later.

Code after:
                instrument_id=instrument_id,
                bid_price=instrument.make_price(converted_bid_price),
                ask_price=instrument.make_price(converted_ask_price),
                bid_size=instrument.make_qty(bid_size),
                ask_size=instrument.make_qty(ask_size),
                ts_event=ts_event,
                ts_init=ts_event,
            )

            await self._handle_data(quote_tick)

    async def _try_create_index_price_tick_from_market_data(
        self,
        subscription: Subscription,
        req_id: int,
    ) -> None:
        if req_id not in self._subscription_tick_data:
            return

        tick_data = self._subscription_tick_data[req_id]

        price = tick_data.get(TickTypeEnum.LAST)

        if price is not None:
            instrument_id = InstrumentId.from_str(subscription.name[0])
            instrument = self._cache.instrument(instrument_id)
            if instrument is None:
                self._log.error(f"Cannot find instrument for {instrument_id}")
                return

            ts_event = self._clock.timestamp_ns()
            price_magnifier = (
                self._instrument_provider.get_price_magnifier(instrument_id)
                if self._instrument_provider
                else 1
            )
            converted_price = ib_price_to_nautilus_price(price, price_magnifier)

            index_price_update = IndexPriceUpdate(
                instrument_id=instrument_id,
                value=instrument.make_price(converted_price),
                ts_event=ts_event,
                ts_init=ts_event,
            )

            await self._handle_data(index_price_update)

    async def process_realtime_bar(
        self,
        *,
        req_id: int,