Skip to content

IB Flex import: FX trades (assetCategory=CASH) mapped to wrong cash accounts when Flex report contains multiple accounts (multiple FlexStatements) #5473

@miert56

Description

@miert56

Describe the bug
When importing an IBKR Flex report that contains multiple FlexStatement nodes (multiple IBKR accounts) in one XML, Portfolio Performance imports FX trades (Trades/Trade with assetCategory="CASH" and symbols like EUR.HUF, USD.HUF, also EUR.USD, EUR.ZAR, USD.ZAR) as cash transfers, but the source/target cash accounts are resolved incorrectly across accounts. FX legs end up booked between cash accounts belonging to different IBKR accountIds, creating artificial inter-account transfers and impossible negative cash balances.

To Reproduce

  1. Create a PP file with two IBKR portfolios/cash accounts, e.g.:
    AccountId U158xxxxx (main), base HUF + EUR/USD/GBP cash accounts
    AccountId U173xxxxx (alias TBSZ-2025), base HUF + EUR/USD/GBP/ZAR cash accounts

  2. Export a single IBKR FlexQuery XML containing both accounts (two FlexStatement blocks).

  3. Import the XML via “Import → Interactive Brokers Flex Statements”.

  4. "Import transactions from PDF files" screen appears, which may override accountIds.

Actual behavior
FX trade legs are mapped to cash accounts not belonging to the statement’s accountId.

Example:
Trade in U173xxxxx: transactionID=3607649210, symbol=EUR.HUF, quantity=1108, proceeds=-452067.324 (HUF)
Imported as cash transfer from IBKR (U158xxxxx) (HUF) to IBKR TBSZ-2025 (U173xxxxx) EUR.
Trade in U158xxxxx: transactionID=3579620213, symbol=EUR.HUF, quantity=1, proceeds=-407.735 (HUF)
Imported as cash transfer from IBKR (U158xxxxx) (HUF) to IBKR TBSZ-2025 (U173xxxxx) EUR (wrong target account).
This causes huge negative cash in the main account and inflated cash in the TBSZ account.

Expected behavior
For each FX trade, both legs must be posted within cash accounts belonging to the same statement accountId (same IBKR account). Account resolution should be keyed by (accountId, currency) (and also handle base-currency cash account naming without a currency suffix).

Possible root cause
Cash account lookup for FX trades appears to be done by currency only (global), not scoped to the statement/accountId context, so the first matching cash account of a currency is chosen even if it belongs to another IBKR account.

Alternatively, the "Import transactions from PDF files" screen may override accounts. This screen is misleading, as some trades can involve Fx within U158xxxxx (buy USD from HUF) and others within IBKR TBSZ-2025 (U173xxxxx) (e.g. buy USD from HUF)

Image

Suggested fix
During FX trade import, resolve both cash accounts using the FlexStatement context:
quote currency cash account: (statementAccountId, quoteCurrency)
base currency cash account: (statementAccountId, baseCurrency)
"Import transactions from PDF files" screen could be imitted
Never mix cash accounts across different statement accountIds.

Desktop (please complete the following information):

  • OS: Win10
  • Version 0.81.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions