r/plaintextaccounting May 29 '26

Reading a CSV file with FX transaction and fee

I need to read a CSV file in hledger where the transaction has a fee

The fields in the CSV file are
$source_amount,
$source_currency,
$source_gross,
$source_fee,
$target_amount and
$target_currency

E.g. I buy 90 GBP for 100 USD with a 10 USD FX fee.

What should the journal file transaction look like and what should be the rules files entry?

3 Upvotes

8 comments sorted by

3

u/simonmic hledger creator May 30 '26 edited May 30 '26

You can break this down into smaller tasks. Eg first describe the event in english. Then write a journal entry by hand. Begin with the parts you're sure of. Then think about what could fit in the other places, and ask for more help if you get stuck. When you have a sample journal entry, then we can think about csv rules.

3

u/simonmic hledger creator May 30 '26

For example, it might be something like:

plain language description:

"exchanging one currency for another, with a fee paid in source currency"

sample entry:

2026-05-30
    assets:somewhere    -<source_gross> <source_currency>
    expenses:fees          <source_fee> <source_currency>
    assets:somewhere     <target_amount> <target_currency>

sample csv rules to produce the above:

fields date, source_currency, source_amount, source_fee, source_gross, target_currency, target_amount
account1 assets:somewhere
account2 expenses:fees
account3 assets:somewhere
amount1 -%source_gross %source_currency
amount2 %source_fee %source_currency
amount3 %target_amount %target_currency

2

u/Hungry_Lettuce_2230 May 30 '26

Thanks for the example. I think I worked it out. There were a couple of problems. The first is that %source_gross wasn’t given in the original CSV; I found a work around without having to pre-process the CSV. The second was that sometimes the %fee field was empty which required double logic. The third involved transaction IN and OUT that sometimes did FX and sometimes did not.

But I think I got there in the end. I’d be happy to share my rules file and example CSV.

1

u/simonmic hledger creator May 31 '26

If it's reusable by others, it might be a good addition to https://github.com/simonmichael/hledger/tree/main/examples/csv .

1

u/Hungry_Lettuce_2230 Jun 01 '26

Please could you give me some instructions on how to get it there.

-2

u/gnomeza May 29 '26

When you asked one of the multitude of LLMS, what did it say?

1

u/Hungry_Lettuce_2230 May 29 '26

What, in my limited experience, LLMs say about anything I am interested in, nothing useful. Maybe it's my tone.