Skip to content

[IBKR] updateAccountValue ignores currency — same-key values overwrite, wrong account figures for multi-currency accounts #295

@rudyll

Description

@rudyll

Summary

updateAccountValue() stores account values keyed only by the tag name, ignoring the currency argument. IBKR sends many account-value tags (TotalCashValue, NetLiquidation, BuyingPower, …) once per currency plus a consolidated BASE line. Because the handler does values.set(key, val) without the currency, each currency's value for a given key overwrites the previous one — only the last-received currency survives. For multi-currency accounts this stores a non-base value for keys consumed as base-currency totals → incorrect account figures.

Location

services/uta/src/domain/trading/brokers/ibkr/request-bridge.ts:

override updateAccountValue(key: string, val: string, _currency: string, _accountName: string): void {
  this.accountCachePending_?.values.set(key, val)   // currency ignored → same-key overwrite
}

(accountSummary() likewise leaves _currency unused.) Then IbkrBroker.getAccount() reads values.get('TotalCashValue') / get('NetLiquidation') etc. as if they were base-currency totals.

Impact

  • Accounts holding more than one currency (e.g. USD + HKD for HK equities) get an incorrect totalCashValue and a derived netLiquidation that depends on IBKR's per-currency send order.
  • USD-only accounts are unaffected (USD == BASE), so the bug stays hidden until a non-base currency appears.

Suggested fix

  • Key account values by (key, currency), or capture the BASE line specifically for consolidated totals (keep per-currency where needed).
  • getAccount() should read the BASE value for account-level totals.

Note

Found while debugging account balances on a USD-only IBKR paper account; not reproduced there by design (USD == BASE). Flagging the code path as currency-unsafe — it will bite any account that holds a non-base currency (e.g. HKD for HK stocks).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions