📖 Guides

Fix IBKR API Combo (BAG) Market Data NaN Bug (2026)

⚠️ Disclosure: Some links on this page are affiliate links. If you sign up through them, I may earn a commission — at no extra cost to you. I only review tools I actually use.
If you've been trading options combos using the Interactive Brokers API, you've probably run into a frustrating issue: after the TWS or IB Gateway has been running for a while, the market data for your Combo (BAG) contracts silently starts returning NaN (Not a Number) for bid, ask, and last prices.

Here's the catch: the individual legs of the combo still quote perfectly fine. The market data subscription isn't broken, your network connection is stable, and the API isn't throwing a hard error. It just silently degrades into NaN.

This is a known issue in the IBKR API ecosystem, specifically affecting combo contracts. If you're relying on real-time pricing for algorithmic trading, this bug can cause your strategies to stall or trade off stale data. In this guide, we'll break down why this happens, how to identify it before it ruins your trades, and the exact workarounds to fix it without restarting your Gateway.

About this guide: I'm Lawrence, the writer behind supa.is. Between February and May 2026 I've published 150+ articles on supa.is across crypto and brokerage tooling — including 60+ IBKR-specific guides (recent examples: Interactive Brokers TWS API: Market Data Not Subscribed, Fix IBKR API calculateImpliedVolatility Timeout, Fix IBKR API Timezone Mismatch). The most-repeated reader question across that IBKR API archive is exactly why combo market data silently drops to NaN, which is why I'm publishing this standardized guide instead of answering one-off.

What is the IBKR API Combo (BAG) NaN Bug?

In the IBKR API, a "Combo" refers to an options combination—like a vertical spread, iron condor, or straddle—where you buy and sell multiple legs simultaneously. When you request market data for a combo using the API (e.g., via reqMktData with a BAG contract), IBKR is supposed to calculate the aggregate bid, ask, and last price based on the individual legs.

The bug occurs when the Gateway or TWS has been running for an extended period. The API continues to receive ticks for the individual legs, but the calculated market data for the combo contract itself silently switches to NaN.

Because it's a silent failure, there's no error code thrown by the API. Your code keeps running, but your pricing logic suddenly sees NaN and either crashes, skips the trade, or makes a bad decision based on stale data.

I've seen this exact issue pop up in the IBKR forums repeatedly, and it's a headache for anyone running algo strategies.

Why Does the Combo Market Data Become NaN?

IBKR hasn't given us a detailed post-mortem on this, but based on how the API processes combo ticks, here are the likely culprits:

  1. Tick Accumulation Overflow: The API calculates combo prices by aggregating the ticks of the individual legs. Over time, if the internal tick buffers aren't flushed properly, the calculation can overflow or lose reference to the current state of the legs.
  2. Stale Leg Data: If one of the legs temporarily stops sending ticks (e.g., due to a brief market pause or a low-liquidity strike), the combo calculation might fail to update. Instead of reverting to the last known good price, it defaults to NaN.
  3. Gateway Memory Leaks: TWS and Gateway are known to suffer from memory leaks after long uptimes. As memory fills up, background processes like combo price calculation can silently fail.

How to Identify the Bug Early

Since the bug is silent, you need to implement safeguards in your trading scripts. Here are the best ways to catch it before it impacts your PnL:

1. Validate for NaN in Your Tick Handlers

Whenever you receive a tick for a combo contract, explicitly check if the bid, ask, or last price is NaN.

In Python (using ib_async or the official ibapi), you can use math.isnan():

import math

def on_tick(self, tick):
    if tick.field == 1: # Bid
        if math.isnan(tick.price):
            print(f"WARNING: Combo {tick.contract} bid is NaN!")
            # Trigger a fallback or alert

2. Compare Combo Price to Individual Legs

💡 Interactive Brokers

Like what you're reading? Try it yourself — this link supports ChartedTrader at no cost to you.

Open an Interactive Brokers Account →

If your API setup requests market data for both the combo and the individual legs, you can cross-reference them. If the individual legs have valid prices but the combo price is NaN, you know the bug has triggered.

3. Monitor the Uptime of Your Gateway

If you notice combo prices dropping to NaN consistently after the Gateway has been running for several hours, you've hit the uptime threshold for this bug.

How to Fix the IBKR API Combo NaN Bug

Since this is a bug on IBKR's side, there is no permanent "patch" you can apply to your code. However, there are several effective workarounds to keep your trading running smoothly.

Workaround 1: Restart the Gateway Regularly

The most straightforward fix is to restart your TWS or IB Gateway periodically. Since the bug is tied to the uptime of the application, a daily restart (or even a restart every 6-8 hours) will clear the internal buffers and reset the combo price calculations.

If you're running an automated trading system, you can script a daily restart of the Gateway at a time when markets are closed (e.g., 6:00 AM EST).

Workaround 2: Cancel and Resubscribe to Combo Market Data

If you don't want to restart the entire Gateway, you can cancel the market data subscription for the combo contract and resubscribe to it. This forces the API to recalculate the combo price from scratch.

In your code, you can implement a periodic resubscription:

import time

def resubscribe_combo(contract, api_client):
    api_client.cancelMktData(contract)
    time.sleep(1) # Give the API a moment to process the cancellation
    api_client.reqMktData(contract, '', False, False)

You can run this function every few hours or trigger it specifically when you detect a NaN value.

Workaround 3: Calculate the Combo Price Yourself

Instead of relying on IBKR's internal combo calculation, you can request market data for the individual legs and calculate the combo price in your own code. This is the most robust solution, as it completely bypasses the buggy combo calculation engine.

For example, if you're trading a bull call spread (buying a lower strike call, selling a higher strike call), your combo bid is the bid of the long leg minus the ask of the short leg.

def calculate_combo_price(long_leg_bid, short_leg_ask):
    return long_leg_bid - short_leg_ask

This completely bypasses the buggy engine, and gives you more control over your pricing logic (like accounting for slippage or using mid-prices).

Workaround 4: Use the ib_async Library's Built-in Features

If you're using the popular ib_async Python library, it has some built-in utilities for handling combo contracts. The library attempts to handle some of the edge cases with combo ticks, and it provides easier ways to resubscribe to market data.

However, even ib_async is not immune to the NaN bug if the underlying API data is corrupted. You still need to implement the math.isnan() checks mentioned earlier.

Best Practices for IBKR API Combo Trading

If you trade combo options via the IBKR API, here are some best practices to minimize downtime and ensure data integrity:

FAQ

Why does the IBKR API return NaN for combo market data?

The IBKR API calculates combo prices by aggregating the ticks of individual legs. Over long uptimes, internal buffers can overflow or lose reference to the current state of the legs, causing the calculated price to silently default to NaN.

Can I fix the combo NaN bug without restarting the Gateway?

Yes. You can cancel and resubscribe to the combo market data using cancelMktData followed by reqMktData. Alternatively, you can calculate the combo price yourself using the individual leg prices.

Is this bug specific to the Python API?

No. The bug is in the IBKR API's internal combo calculation engine, so it affects all API languages (Python, Java, C++, etc.) and both TWS and Gateway.

How often should I restart my IB Gateway to prevent this bug?

Most users report the bug appearing after several hours of uptime. Restarting the Gateway once a day (during market hours or at the start of the trading day) is usually sufficient.

Will IBKR fix this bug in a future update?

IBKR frequently updates TWS and Gateway, but the combo NaN bug has persisted for years. It's best to assume it will not be fixed soon and implement workarounds in your code.

Risk Warning

Risk Warning: Crypto trading involves substantial risk of loss. Never invest more than you can afford to lose. This is not financial advice. Trading options involves a high degree of risk and is not suitable for all investors. You should carefully consider your investment objectives, level of experience, and risk appetite before trading options.

If you're looking to set up your IBKR API environment properly, or if you're new to the platform, check out our guide on Interactive Brokers Account Setup: Application to First Trade. For more API troubleshooting, see our article on Fix IBKR API calculateImpliedVolatility Timeout.

Ready to start trading with Interactive Brokers? Open an Interactive Brokers Account today.

🧮 Free IBKR calculator

IBKR Margin Calculator →
Reg-T initial / maintenance / margin call price + IBKR Pro interest cost
Interactive Brokers

Ready to get started? Use the link below — it helps support ChartedTrader at no cost to you.

Open an Interactive Brokers Account →
📈

About the author

I'm a systematic trader running live strategies on IB (USDJPY momentum) and Hyperliquid (crypto perps). Every tool reviewed here is something I've used with real capital. Questions? Reach out.

📚 Related Articles

⚙️
Trading Tools

Fix IBKR reqTickersAsync Stale Ticker Bug (2026)

reqTickersAsync returns stale cached tickers before tickSnapshotEnd in ib_async. Here is the exact fix for this IBKR Python API bug in 2026.

July 15, 2026 ⏱ 8 min read
📖
Guides

Fix IBKR ib_async Connection Drops (2026)

Fix the IBKR ib_async connection drop issue where IBGateway disconnects immediately after API connection. Root causes, workarounds, and TWS alternatives explained.

July 15, 2026 ⏱ 9 min read
🏦
Brokers & Exchanges

Interactive Brokers TWS API: 'Market Data Not Subscribed' — How to Fix Every Cause (2026)

Getting error 354 'Requested market data is not subscribed' from the IB TWS API? This guide covers every cause — missing subscriptions, paper trading quirks, wrong contract definitions, and reqMarketDataType settings — with exact fixes from a production algo trading system.

March 28, 2026 ⏱ 12 min read