§ · Configuration

Tuning & diagnostics.

The defaults are good. StreamXLS runs correctly out of the box, and most users never set a single option. This page is for the times you want to tune behavior — a faster position refresh, delayed-only quotes, verbose logs — or diagnose something that is misbehaving. Everything here is optional. The Reference defines the topic families and field names these settings affect.

§ · Environment variables

Every setting

The engine reads its configuration from TWS_RTD_* environment variables the moment Excel first loads it. An invalid value is never fatal: it logs a warning, surfaces on the CONFIGWARNINGS status field, and the setting falls back to its default.

Set variables before you start Excel. Excel inherits the environment that was in effect when it launched, and the engine reads it once at load. Set a user-level environment variable (Windows Settings → Edit environment variables for your account) and restart Excel, or launch Excel from a shell that has the variable set. Changing a variable while Excel is open has no effect until you reopen it. The StreamXLS Control Panel can also write these settings to a per-user config file, so you can tune the engine without touching Windows environment variables — an environment variable, when present, takes precedence over the file.
Logging
Variable Default Purpose
TWS_RTD_LOG_FILE (none) Path to the log file, e.g. %TEMP%\streamxls.log. Unset means logging is off. Supports environment-variable expansion in the path.
TWS_RTD_LOG_LEVEL INFO Verbosity threshold: ERROR, WARN, INFO, DEBUG, TRACE, VERBOSE (or NONE to silence).Use DEBUG when reporting an issue.
TWS_RTD_LOG_RETENTION_DAYS 5 Days to keep rotated logs; older files are deleted at startup.Range: -1 to 365 (-1 = never delete)
Market data
Variable Default Purpose
TWS_RTD_MARKET_DATA_TYPE 4 Which market-data type to request — see Market-data type below. Default 4 (DELAYED_FROZEN) gives real-time data when subscribed and delayed otherwise.Range: 1–4
TWS_RTD_ERROR_DISPLAY MESSAGE How a TWS error shows in a cell: MESSAGE displays the error text; NA shows #N/A.
TWS_RTD_ACCOUNT_VALUES_NA_ON_DISCONNECT false When true, all account-value topics flip to #N/A while disconnected from TWS instead of preserving their last-known values. The P&L trio (DailyPnL/UnrealizedPnL/RealizedPnL) always resets to #N/A on disconnect regardless of this setting.
Connection
Variable Default Purpose
TWS_RTD_CLIENT_ID (auto) Fixed TWS API client ID. Leave unset — the engine auto-picks a per-process ID to avoid collisions between Excel instances. Set only when you need a predictable ID.
TWS_RTD_HOST 127.0.0.1 Default host dialed when a formula does not name one. Any hostname or IP. Per-formula connection tokens override it — see Connections.
TWS_RTD_PORT 7496 Default socket port when a formula does not name one (7496 = live TWS). Per-formula tokens override it.Range: 1–65535
Positions & orders
Variable Default Purpose
TWS_RTD_THROTTLE_MS 500 Minimum interval between position-refresh requests. Lower for faster updates (100–250 ms); raise to reduce CPU (1000–2000 ms).Range: 0–10000 ms
TWS_RTD_POSITION_REQUEST_TIMEOUT_MS 8000 Positions watchdog: re-issue reqPositions() if a snapshot makes no progress within this window.Range: 0–120000 ms (0 = disable)
TWS_RTD_POSITION_REQUEST_MAX_RETRIES -1 Max watchdog re-requests per stuck episode; -1 = unlimited.Range: -1 to 20
TWS_RTD_POSITION_STALE_TIMEOUT_MS 30000 After this long with no position data during a stuck snapshot, flip individual/aggregate position values to #N/A ("fail loud"). The list topics (SymbolsCsv/ConIdCsv/PositionsChangedUtc) are preserved.Range: 0–600000 ms (0 = disable)
TWS_RTD_POSITION_RECONNECT_AFTER_RETRIES 4 After this many futile watchdog re-requests in one episode, force a full reconnect — the recovery for a silently-dead ("zombie") socket that keeps reporting connected.Range: 0–100 (0 = disable)
TWS_RTD_ORDER_REFRESH_SECONDS 15 Order-polling interval. StreamXLS polls with reqAllOpenOrders() because the push API (reqAutoOpenOrders) works only with client ID 0, which the engine avoids to prevent collisions — so orders placed elsewhere are picked up on this cadence.Range: 5–300 seconds
Heartbeat & update notifier
Variable Default Purpose
TWS_RTD_HEARTBEAT_INTERVAL_MS (Excel default) Overrides Excel's RTD heartbeat interval. Raising it lowers overhead but delays detection of stuck updates.Must be ≥ 15000 ms, or -1 to disable
TWS_RTD_HEARTBEAT_NOTIFY_ASYNC true Whether the heartbeat schedules UpdateNotify asynchronously (avoids reentrancy and UI blocking). Leave on outside of deterministic testing.
TWS_RTD_UPDATE_NOTIFY_MIN_MS 0 Minimum interval between UpdateNotify attempts (rate limit). 0 = no throttle.Range: 0–60000 ms
TWS_RTD_UPDATE_NOTIFY_PENDING_STALE_MS 1000 Window after which pending topics are considered stale and the notify cycle is re-armed if no RefreshData arrived.Range: 100–60000 ms
TWS_RTD_NOTIFY_EXPECT_REFRESH_MS 0 Watchdog that warns if Excel does not call RefreshData within this window after a notify. 0 = disabled.Range: 0–60000 ms
Diagnostics (advanced)
Variable Default Purpose
TWS_RTD_MAX_PARALLEL_HANDSHAKES 8 Max concurrent connection-handshake attempts.Range: 1–100
TWS_RTD_HANDSHAKE_SUCCESS_COOLDOWN_MS 50 Cooldown after a successful handshake.Range: 0–60000 ms
TWS_RTD_HANDSHAKE_FAILURE_COOLDOWN_MS 1000 Cooldown after a failed handshake.Range: 0–60000 ms
TWS_RTD_HANDSHAKE_MIN_INTERVAL_MS 0 Minimum interval between any handshake attempts.Range: 0–60000 ms
TWS_RTD_HANDSHAKE_DIAGNOSTICS (none) Log-file path; when set, records detailed handshake diagnostics.
TWS_RTD_FORCE_CALLER_STACK false Force capture of the caller stack in diagnostics (performance cost). Support use only.
TWS_RTD_DIAG_PARSE_CONNECTION false Emit diagnostic output for connection-string parsing.
§ · Market-data type

Delayed vs. real-time

TWS serves four market-data types, selected with TWS_RTD_MARKET_DATA_TYPE. The type governs which quotes TWS is willing to send for a contract.

Type Value Subscription needed Data
REALTIME1YesLive streaming quotes.
FROZEN2YesLast available real-time values, frozen (e.g. after the close).
DELAYED3No15–20 minute delayed quotes.
DELAYED_FROZEN4NoDelayed quotes, frozen when the market is closed.

The default is 4 (DELAYED_FROZEN), chosen so StreamXLS works without any market-data subscription. Under type 4, TWS returns real-time data when you do hold a live subscription for the contract, falls back to delayed data when you don't, and serves frozen values when the market is closed. This avoids the "API data requires subscription" error for users without an API market-data subscription.

Set TWS_RTD_MARKET_DATA_TYPE=1 to enforce strict real-time only — TWS then returns an error instead of falling back to delayed data when a subscription is missing. See the Reference market-data fields for the tick names these quotes populate.

§ · Logging

Logs & support reports

Logging is off by default. To capture a log, set TWS_RTD_LOG_FILE to a writable path and restart Excel — for example %TEMP%\streamxls.log. Raise detail with TWS_RTD_LOG_LEVEL=DEBUG (or TRACE). Logs cover connection handshakes, subscribe/unsubscribe/refresh activity, and the data-feed lifecycle. Rotated files are pruned after TWS_RTD_LOG_RETENTION_DAYS (default 5; set -1 to keep them indefinitely).

Reporting an issue? Email [email protected] and include:
  • Your StreamXLS version — read =RTD("Tws.Rtd", , "VERSION") in a cell, or read it off the StreamXLS Control Panel.
  • Your TWS or IB Gateway version and your TWS API version (these are different — the TWS API is the separately-installed package the engine binds to).
  • Your Excel bitness (32-bit or 64-bit).
  • A log file captured with TWS_RTD_LOG_LEVEL=DEBUG covering the problem.

Even with logging off, a configuration mistake is visible in Excel: read =RTD("Tws.Rtd", , "status", "CONFIGWARNINGS") to see any warnings the engine raised while loading its settings. The status fields are the fastest first-line diagnostic.

§ · Version floor

The TWS API version floor

This is the single most common reason for "everything works except quotes," so it gets a permanent home here. If your positions, orders, account values, and P&L all populate but market-data cells stay empty, your installed TWS API is almost certainly too old.

Interactive Brokers moved market data onto a newer wire protocol that a modern TWS or IB Gateway will only speak once the connection negotiates ServerVersion ≥ 206. An older TWS API can neither request nor decode that protocol, so a modern TWS sends it zero market-data ticks — no error, no quotes — while orders, positions, account values, and P&L keep flowing over their still-supported legacy paths. The human equivalent of that floor is TWS API ≥ 10.38.01. Keep to the latest Stable TWS API release.

Because serving a silently blank quote would violate the "fail loud" principle, StreamXLS does the opposite: when a connection negotiates below ServerVersion 206, it withholds the market-data topics with an actionable error rather than showing blanks. This is per-connection — each socket negotiates its own protocol level — and it never withholds a non-market-data topic.

Diagnose it from three per-connection status fields:

  • =RTD("Tws.Rtd", , "status", "ServerVersion") — this connection's negotiated ServerVersion (an integer, or Not Connected).
  • =RTD("Tws.Rtd", , "status", "MarketDataState")Ok (≥ 206, quotes can stream), TooOld (1–205, market data withheld on version grounds), or Unknown (not yet handshaked).
  • =RTD("Tws.Rtd", , "status", "MarketDataMessage") — the actionable "update your TWS API" message when the state is TooOld; empty otherwise.

The fix: update your TWS API install to the latest Stable release and reconnect (reopen Excel, or force it with the VBA below). This is a separate package from the TWS or IB Gateway application — updating the desktop app does not update the API. Confirm the binding at any time with the TWSAPI_VERSION and TWSAPI_STATE metadata topics.

§ · Connections

Multiple connections & reconnection

A single workbook can talk to several TWS or IB Gateway instances at once. Each unique host:port:clientid combination is a separate connection, opened on demand from the connection tokens in your formulas. Full token grammar and the port aliases (paper, gw, gwpaper) are on the Reference; the default host and port for formulas that name neither come from TWS_RTD_HOST / TWS_RTD_PORT above.

=RTD("Tws.Rtd", , "port=7496", "AAPL", "Bid")  — live TWS
=RTD("Tws.Rtd", , "port=7497", "AAPL", "Bid")  — paper TWS
=RTD("Tws.Rtd", , "port=4001", "AAPL", "Bid")  — IB Gateway live

Because connections are per host:port:clientid, watch which one you are diagnosing: the status fields scope per-connection, so pass the same connection token (paper, host=, port=…) to read that connection's state, or omit it to piggyback the single connection.

Reconnection

When TWS drops mid-session, StreamXLS reconnects automatically and re-establishes the subscriptions that were active — you don't touch your formulas, and non-volatile values are preserved across the gap. What StreamXLS cannot control is exactly when Excel gives it a chance to try, because reconnection is driven by Excel's heartbeat. Per Microsoft:

"The Excel calculation cycle determines when the Heartbeat method is called. In most scenarios with default settings, it is less than 1 second. However, depending on configuration, it could be as long as 2 minutes."

So if Excel is very busy, an automatic reconnect can lag. To force it immediately, reopen Excel or run the VBA call Application.RTD.RefreshData. Watch =RTD("Tws.Rtd", , "status", "IsConnected") to see the link return.