ibkr: use IBKR account number as the canonical Account.id
Bug: provider passed the WF UUID as Account.id. ensure_account looks up existing accounts by (provider, providerAccountId=Account.id), so the WF-UUID-as-providerAccountId would never match the manually-created account (which has providerAccountId=U13279690), causing the pipeline to create a duplicate WF account on every cron run. Fix: Account.id is now the IBKR account number (U13279690) throughout. The pipeline's _ensure_accounts() resolves it to the WF UUID via the canonical (provider, providerAccountId) lookup; activities are remapped before import. CLI no longer takes the WF UUID — derives it post-import via a cheap idempotent ensure_account call for the reconciliation step. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
30af5fe2c9
commit
ceb652b623
3 changed files with 17 additions and 11 deletions
|
|
@ -179,12 +179,14 @@ class IBKRProvider:
|
|||
*,
|
||||
token: str,
|
||||
query_id: str,
|
||||
wf_account_id: str,
|
||||
upstream_account_id: str,
|
||||
) -> None:
|
||||
self._token = token
|
||||
self._query_id = query_id
|
||||
self._wf_account_id = wf_account_id
|
||||
# Single source of truth — the IBKR account number (e.g. U13279690).
|
||||
# The pipeline's _ensure_accounts() resolves this to a Wealthfolio
|
||||
# UUID via (provider="ibkr", providerAccountId=upstream_account_id);
|
||||
# activities are remapped to the WF UUID before import.
|
||||
self._upstream_account_id = upstream_account_id
|
||||
# Stashed for the reconciliation step after fetch() drains.
|
||||
self._last_response: Any = None
|
||||
|
|
@ -192,7 +194,7 @@ class IBKRProvider:
|
|||
def accounts(self) -> list[Account]:
|
||||
return [
|
||||
Account(
|
||||
id=self._wf_account_id,
|
||||
id=self._upstream_account_id,
|
||||
name="Interactive Brokers (UK)",
|
||||
account_type=AccountType.GIA,
|
||||
currency="GBP", # FX-aware per-trade; account ccy is GBP
|
||||
|
|
@ -232,10 +234,10 @@ class IBKRProvider:
|
|||
)
|
||||
|
||||
for trade in stmt.Trades or []:
|
||||
yield _map_trade_to_activity(trade, account_id=self._wf_account_id)
|
||||
yield _map_trade_to_activity(trade, account_id=self._upstream_account_id)
|
||||
|
||||
for cash in stmt.CashTransactions or []:
|
||||
activity = _map_cash_to_activity(cash, account_id=self._wf_account_id)
|
||||
activity = _map_cash_to_activity(cash, account_id=self._upstream_account_id)
|
||||
if activity is not None:
|
||||
yield activity
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue