Balancing "equity:conversion" split across postings.

35 views
Skip to first unread message

Wasif Hasan Baig

unread,
Feb 15, 2024, 12:29:12 AMFeb 15
to hledger
Hi folks,

Can anyone help me with balancing a split equity conversion posting. My base currency is CAD. I bought 0.5 ETH for 100 USD. The two postings below are coming from separate CSV files.

2018-05-03 Buy ETH
    assets:crypto:ETH      0.5 ETH
    equity:conversion      ; date:2022-05-04

2018-05-04 Visa debit purchase 100 USD @ 1.300000
    assets:bank:checking                -130.00 CAD
    equity:conversion         100 USD @@ 130.00 CAD


Any help balancing these postings would be greatly appreciated.

Thanks,
Wasif

Simon Michael

unread,
Feb 15, 2024, 2:43:28 AMFeb 15
to hle...@googlegroups.com
How about this ?

2018-05-03 Buy ETH
    assets:crypto:ETH      0.5 ETH @ 200 USD
    assets:crypto:USD     -100 USD

2018-05-04 Visa debit purchase 100 USD @ 1.300000
    assets:crypto:USD      100 USD @ 1.30 CAD
    assets:bank:checking  -130.00 CAD

I left the conversion equity implicit; it can be added with --infer-equity if you want it.
--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.

Wasif Hasan Baig

unread,
Feb 15, 2024, 12:38:44 PMFeb 15
to hledger
Hi Simon,

Thanks for your response. Is it possible to infer the amount of an account in a posting. I'm asking this because these postings are generated from CSV imports and the "Buy ETH" posting does not have the cost in the USD amount. Building on your proposed entries, is it legal to do this in Hledger:

2018-05-03 Buy ETH
    assets:crypto:ETH         0.5 ETH @ 200 USD
    assets:crypto:USD:ForETH  ; <--- I want to avoid manual entry of the amount here

2018-05-04 Visa debit purchase 100 USD @ 1.300000
    assets:crypto:USD:ForETH  100 USD @ 1.30 CAD
    assets:bank:checking      -130.00 CAD

Thanks,
Wasif

Simon Michael

unread,
Feb 15, 2024, 1:18:20 PMFeb 15
to hle...@googlegroups.com
Yes, -200 USD will be inferred there.

Wasif Hasan Baig

unread,
Feb 16, 2024, 3:01:13 PMFeb 16
to hledger
I have removed "@ 200 USD" after 0.5 ETH because my crypto ledger CSV don't have this information. Can HLedger infer "100 USD @ 1.30 CAD" in the scenario below because that is the balance of this account:

2018-05-03 Buy ETH
    assets:crypto:ETH         0.5 ETH
    assets:crypto:USD:ForETH  ; <--- I want to avoid manual entry of the amount here

2018-05-04 Visa debit purchase 100 USD @ 1.300000
    assets:crypto:USD:ForETH  100 USD @ 1.30 CAD
    assets:bank:checking     -130.00 CAD

Thanks,
Wasif

Simon Michael

unread,
Feb 16, 2024, 3:24:12 PMFeb 16
to Wasif Hasan Baig, hle...@googlegroups.com
Hi Wasif, 

did you include the right paste with this message ? It seems the same as the previous one which I answered.

Wasif Hasan Baig

unread,
Feb 16, 2024, 3:54:25 PMFeb 16
to hledger
Hi Simon,

Yes I did. I only removed the  "@ 200 USD" from line 2 and I want HLedger to infer "100 USD @ 1.30 CAD" (the total balance in assets:crypto:USD:ForETH account) on line 3. I'm not sure if this is even possible and wanted to confirm with someone more knowledgeable.

Thanks,
Wasif

Simon Michael

unread,
Feb 16, 2024, 4:07:50 PMFeb 16
to hle...@googlegroups.com
Sorry, I'm not getting it...

Wasif Hasan Baig

unread,
Feb 22, 2024, 3:42:56 PMFeb 22
to hledger
Sorry for being ambiguous and unclear. I am going to add more context to my previous post and state what I'm trying to achieve.

My HLedger setup is based on https://github.com/adept/full-fledged-hledger which promotes minimizing manual work/entries as much as possible.

Below are the two CSVs that my journal entries are automatically extracted from.

CSV1 (My crypto account transaction history):
Operation Date ,Currency Ticker ,Operation Type ,Operation Amount ,Operation Fees
2018-05-03 ,ETH             ,IN             ,       0.5 ,    0          

CSV2 (My checking account transaction history):
Date       ,Account             ,Description                           ,Withdrawals ($) ,Deposits ($) ,Balance ($) ,Foreign Currency ,Exchange Amount ,Exchange Rate
04-05-2018 ,assets:bank:checking,Visa debit purchase 100 USD @ 1.300000 ,130.00          ,             ,870.00  ,USD              ,         100.00 ,     1.300000

2018-05-03 Buy ETH     ; <--- posting from CSV1

    assets:crypto:ETH          0.5 ETH
    assets:crypto:USD:ForETH   ; <--- I want to avoid manual entry of the amount here

2018-05-04 Visa debit purchase 100 USD @ 1.300000  ; <--- posting from CSV2
    assets:crypto:USD:ForETH   100.00 USD @@ 130.00 CAD
    assets:bank:checking      -130.00 CAD

As you can see, these two transactions are linked but CSV1 lacks information about the cost of the transaction.

My main question is, given these entries/postings, can HLedger infer the actual cost of buying 0.5 ETH i.e. 100 USD @@ 130 CAD (or @ 1.30 CAD)?

I hope this added some clarity to my previous post/question.

Thanks,
Wasif




Simon Michael

unread,
Feb 23, 2024, 8:26:34 AMFeb 23
to hle...@googlegroups.com
Hi Wasif,

The short answer: no, hledger by itself can't do that. It generates at most one transaction per CSV record.

If it was me, I would think twice about jumping from CAD to ETH in a single transaction - that feels like a synthetic transaction, whereas it seems more accurate to record two events, a purchase of USD and then a purchase of ETH with USD. You may have good reason and may be able to avoid causing problems down the road.. or not.

Simon Michael

unread,
Feb 23, 2024, 8:31:38 AMFeb 23
to hle...@googlegroups.com
Well, I can see the reason - you'd like to see costs and gains/losses in your native CAD. You could report it in USD then use --value to convert that to CAD, but it's less direct. Perhaps the single CAD -> ETH transaction will work fine for you, but you'll have to do some scripting or manual edits to generate it.

Wasif Hasan Baig

unread,
Mar 10, 2024, 5:55:12 PMMar 10
to hledger
Thanks Simon! I figured I'll have to deal with this manually or using a script. I thought it's better to consult with more knowledgeable people before embarking on it myself.

Regards,
Wasif

Dmytro Astapov

unread,
Mar 11, 2024, 8:26:09 AMMar 11
to hle...@googlegroups.com
Yeah, it looks like the biggest problem you have is that there are no inputs (csv or otherwise) that say that you bought 0.5eth for exalt 130usd (and not, say, 100usd or 500usd). 

If you always drain USD:ForETH fully with each pechar and they're are no concurrent purchases in flight at any time, you can try generating a balance assertion of "USD:ForETH = 0 USD" on your ETH transaction... It would not be ideal, but maybe it would be better than the current state of affairs? 

Reply all
Reply to author
Forward
0 new messages