Skip to content

[codex] Add CIB debit and IBKR providers#223

Open
Triple-Z wants to merge 9 commits into
masterfrom
codex/cib-ibkr-providers
Open

[codex] Add CIB debit and IBKR providers#223
Triple-Z wants to merge 9 commits into
masterfrom
codex/cib-ibkr-providers

Conversation

@Triple-Z

@Triple-Z Triple-Z commented May 11, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds two provider workflows, refreshes related provider documentation, and includes the shared compiler support needed by the new workflows:

  • Adds a cib_debit provider/analyser with multi-file CNY/HKD/USD statement support.
  • Adds an ibkr provider/analyser for Interactive Brokers Flex XML exports.
  • Adds a shared CurrencyExchange IR order type and Beancount/Ledger rendering for paired FX transactions.
  • Allows providers that implement MultiFileInterface to translate multiple input files in one command.
  • Adds example fixtures and e2e coverage for cib_debit.
  • Adds XML example fixtures and Beancount/Ledger e2e coverage for ibkr.
  • Adds Chinese and English provider documentation for cib_debit, ibkr, and the existing boc provider.

CIB Debit

The new CIB debit provider parses XLSX exports and supports combining multiple currency statement files in one translation run. The converter detects paired purchase-of-foreign-currency activity and emits one currency-exchange transaction instead of disconnected cash-flow rows.

The analyser supports matching rules over peer, item, type, peer bank, peer account, currency, and timestamps, then maps output to method/target accounts using the existing configuration style.

Included examples cover CNY, HKD, and USD input files plus expected Beancount and Ledger output.

Documentation added:

  • docs/docs/providers/banks/cib_debit.md
  • docs/docs/en/providers/banks/cib_debit.md

IBKR

The new IBKR provider parses Flex XML using streaming XML decoding and converts:

  • stock/ETF/ADR Trade rows into securities trade IR orders,
  • cash Trade rows such as USD.HKD into currency exchange IR orders,
  • CashTransaction rows such as deposits, dividends, withholding tax, interest, and fees into normal cash-flow orders.

IBKR metadata such as account id, trade id, transaction id, exchange, ISIN, security id, report date, and settle date is preserved in generated output where present.

The included example/ibkr/config.yaml demonstrates default IBKR cash/position/fee/PnL accounts and uses bookingMethod: FIFO so generated Beancount can resolve repeated-lot securities sells. This PR also adds example/ibkr/example-ibkr-records.xml plus expected Beancount and Ledger outputs, and registers ibkr in the e2e provider matrix.

Documentation added:

  • docs/docs/providers/securities/ibkr.md
  • docs/docs/en/providers/securities/ibkr.md

BOC Documentation

This PR also documents the existing boc provider for Bank of China debit and credit card statements. The new pages describe the provider key, supported matching fields, the existing debit-card peer behavior that combines counterparty name and account/card number, and a basic double-entry-generator translate --provider boc command.

Documentation added:

  • docs/docs/providers/banks/boc.md
  • docs/docs/en/providers/banks/boc.md

The README provider lists, provider index pages, and Chinese/English MkDocs navigation now include Bank of China.

Compiler And CLI Changes

This PR adds OrderTypeCurrencyExchange to the IR and compiler templates for both Beancount and Ledger. The Beancount securities renderer now uses the order currency when present, which is required for non-default-currency broker records.

The translate command now accepts multiple input files when a provider implements MultiFileInterface; providers without that interface still fail explicitly for multi-file input.

A new optional global config field, bookingMethod, writes Beancount's option "booking_method" header when configured.

Documentation Navigation

The provider index and MkDocs navigation now include:

  • CIB Debit under Banks
  • Bank of China under Banks
  • IBKR under Securities Trading

Both Chinese and English navigation trees were updated.

Validation

Ran the following checks locally:

GOCACHE=/private/tmp/double-entry-generator-go-build go test ./...
GOCACHE=/private/tmp/double-entry-generator-go-build make test-provider PROVIDER=cib_debit TARGET=beancount
GOCACHE=/private/tmp/double-entry-generator-go-build make test-provider PROVIDER=cib_debit TARGET=ledger
GOCACHE=/private/tmp/double-entry-generator-go-build make test-provider PROVIDER=ibkr TARGET=beancount
GOCACHE=/private/tmp/double-entry-generator-go-build make test-provider PROVIDER=ibkr TARGET=ledger
GOCACHE=/private/tmp/double-entry-generator-go-build make test-providers
make -C docs build

Results:

  • Go test passed.
  • CIB Beancount and Ledger e2e tests passed.
  • IBKR Beancount and Ledger e2e tests passed.
  • Full provider e2e suite passed with 38/38 passed.
  • Documentation build passed.

I also tested the newly added BOC config/docs path locally with the existing BOC debit example fixture:

double-entry-generator translate \
  --config ./config/double-entry-generator/boc.yaml \
  --provider boc \
  --target beancount \
  --output /private/tmp/my-bookkeeping-boc-example.beancount \
  /Users/triplez/Code/double-entry-generator/example/boc/debit/example-boc-records.csv

The command completed successfully and produced Beancount output using the existing boc provider.

I attempted to rerun the original real IBKR XML conversion, but /Users/triplez/Downloads/last_365_days.xml was no longer present in the local environment. The IBKR parser behavior is covered by the new unit test and by the new XML e2e fixture.

@Triple-Z Triple-Z requested review from a team and gaocegege as code owners May 11, 2026 17:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60d2f98caa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/cmd/translate.go
Comment thread pkg/provider/cib_debit/parse.go Outdated
Comment thread pkg/provider/ibkr/ibkr.go Outdated
@Triple-Z Triple-Z marked this pull request as draft May 11, 2026 18:12
@Triple-Z Triple-Z marked this pull request as ready for review May 12, 2026 10:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a424e8247d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/provider/ibkr/ibkr.go
@Triple-Z Triple-Z requested a review from fatsheep2 May 20, 2026 15:12
@fatsheep2

Copy link
Copy Markdown
Contributor

感觉没毛病,但是这个pr好像没办法用新provider抽象,我后面看看怎么加比较好一些

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants