Skip to content

fix: query live orders per account#44

Merged
NitayRabi merged 1 commit into
code-rabi:masterfrom
infinitnet:fix/live-orders-account-scoped
May 12, 2026
Merged

fix: query live orders per account#44
NitayRabi merged 1 commit into
code-rabi:masterfrom
infinitnet:fix/live-orders-account-scoped

Conversation

@infinitnet
Copy link
Copy Markdown
Contributor

Fixes get_live_orders({}) so the advertised “all accounts” behavior is actually account-scoped under the hood.

Today the tool calls /iserver/account/orders without accountId when no account is passed. In live Client Portal Gateway sessions this can return an empty orders list even when account-scoped requests such as /iserver/account/orders?accountId=<account> return working/recent orders. That makes the MCP tool unreliable for validating fills, brackets, stops, and other live order state.

This PR changes the no-accountId path to:

  • discover trading accounts via /iserver/accounts
  • fall back to /portfolio/accounts if needed
  • query /iserver/account/orders?accountId=<id> for each discovered account
  • aggregate the order lists into orders
  • include per-account raw responses in accountResults for debugging/auditing
  • retain the existing unscoped request as a last-resort fallback if account discovery returns no IDs

The explicit getOrders(accountId) path is unchanged and still returns the raw single-account response.

Why

IBKR’s Web API documentation describes /iserver/account/orders as retrieving orders in a given account, and live testing showed that omitting accountId can produce a false-empty response. The MCP tool description says {} should get all live/open orders, so the implementation should enumerate accounts rather than depend on an unscoped Client Portal response.

Test Plan

  • npm test
  • npm run build

New/updated unit coverage verifies:

  • no-accountId calls discover accounts with /iserver/accounts and then query orders per account
  • /portfolio/accounts is used as a fallback account source
  • legacy unscoped /iserver/account/orders remains a fallback when no accounts can be discovered
  • explicit single-account order requests still pass accountId directly

@NitayRabi NitayRabi merged commit f02fff9 into code-rabi:master May 12, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 1.21.10 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants