Basically each purchase is split it into 2 records, the fiat currency deducted and the cryptocurrency purchased and they share the same transaction id.
Is it possible for hledger to automatically detect the 2 csv rows with identical IDs and create a single transaction from it?
PS: less important, but I have a similar situation with currency conversion transactions on credit-card statement. When I purchase something with a different currency, a 2nd transaction shows up with the same description as the main one plus a special string, something like ` CCY CONVERSION`.
As a matter of fact I came across the data cleaning command yesterday and that’s what led me to ask this question. For the currency conversion fee I have been dealing with it with a custom python script that scans all transactions and finds the conversion transactions and adds identifying info to it so that the csv rules file can auto-categorize it. In short, a lot of python magic which I would like to get rid of or at least simplify.
Even with data cleaning, there is no way to do this out-of-the-box right? I’d have to write a script that gets called by the data-cleaning command, if I understand it correctly.
Still, I appreciate the data-cleaning step now baked into the CSV rules. It eliminates a big preprocessing step for me.
I’ll try your method of using a temporary account to hold the transfer/conversion.
I just realized that I won’t be able to use the @@ format for these purchases if I split them into separate transactions. So I won’t be able to use P directives to track the performance or PNL.
I think writing a script which can combine 2 transactions into 1 based on the value of a csv column might be a better solution for me.
No way with hledger to build a single entry based on two CSV records, no; you’d have to preprocess and merge all the required info into one record first.
Here’s the rules I came up with. (The if block is just to order the postings in a sequence that I like.)
Yes I think you're right that with separate entries like these, you can't record the costs, you can't --infer-costs, you can't --infer-market-prices, you can't show a bal --gain report.
Trying not to be too pedantic, but it might be better to say, “Is it possible to combine 2 csv postings into one transaction using hledger?
I believe this would be a nice feature for hledger (and all PDA programs). Also, rather than combining two lines, it would be nice to combine n lines with a unique transaction_id field.
Transactions is a generic term, and usually what the exporting app calls them. I usually say "csv records".
There's a question of how much complexity is too much for csv rules, which are supposed to be simple and approachable for non-programmers. They could easily grow into yet another never finished programming language.
Ie at some point a person with advanced custom needs should just write a conversion script with a real programming language.
But hledger csv rules also have some smarts that make them better at doing this robustly. I feel the sweet spot is to use them as much as possible; and when necessary, assist them by preprocessing (or generating) the csv with an external script.