Convert ISO 20022 to the ledger-cli plain text accounting format or optionally to plain old csv.
Obviously this goes without saying: This software is provided “as is” without warranty of any kind. If your ledger statements are incorrect and you believe you found a bug in the converter please file an issue or even better a pull request.
You can use the tool in two ways: You can either directly run it via
clojure
or you can compile it to a jar file first and then run it
via java.
clojure -m iso-to-ledger iso_20022.xml > plain_text.ledger
If you’d rather just have a csv file and import that with one of the many ledger import tools you can convert the iso 20022 file to a csv as follows:
clojure -m iso-to-csv iso_20022.xml > transactions.csv
This will generate a csv along the lines of
amount | amount-in | type | booking-date | currency | reference | balance | amount-out | info | value-date |
---|---|---|---|---|---|---|---|---|---|
8.00 | :debit | 2020-01-02 | CHF | 12345 | 100.00 | 8.00 | txn info | 2019-01-02 | |
10.00 | 10.00 | :credit | 2020-01-03 | CHF | 67890 | 102.00 | txn info | 2019-01-03 |
See below how this csv can be imported.
You can create a jar file as follows:
clojure -X:uberjar :jar iso-20022-to-ledger.jar
After that you can run the tool as follows:
java -jar iso-20022-to-ledger.jar iso_20022.xml > transactions.csv
This will give you a csv file that you can import.
You can import the generated csv using hledger and the following rules file
hledger -f 2020.journal import transactions.csv
account1 Assets:Postcheck fields _, amount-in, _, date, _, reference, balance, amount-out, comment, date2 skip 1 currency CHF
You will need clj
to run this code. Install as described in
Getting Started.
- [ ] Add some machine learning to classify the transactions, i.e. assign the right account and payee to a transaction.
- banks2ledger can infer account names via simple Bayesian inference
based on an existing ledger file. Generally it seems well thought
out and maintained. So maybe we should
- join forces, i.e. reduce this package to just iso to csv
- use their classifier code
- the classifier needs to parse existing ledger files. For that it has a simple hand-crafted parser. It might be interesting to look into a parser that is based on instaparse such as ledger.parser
If you have any suggestions or problems let me know. Issues and Pull Requests are very welcome.
The conversion is mostly based on classic reverse engineering of sample xml data. When in doubt also some official implementation guidelines were consulted.
GPLv3+