Dealing with Commodities Swaps/Transactions in Beancount

130 views
Skip to first unread message

Bruno Serrão

unread,
Mar 20, 2021, 1:20:32 PM3/20/21
to Beancount
Hello,

I'm trying to keep track of some of my crypto in beancount without success... I'm already using it for "normal" bank transactions without problem.  (Sorry for the long post)

2020-10-06 open Assets:Crypto-com:App:Wallet:CRO CRO
2020-10-06 open Assets:Crypto-com:App:Wallet:ETH ETH

2020-10-06 * "Buy CRO"
    Assets:Crypto-com:App:Wallet:CRO                10000 CRO {0.12546 EUR}
    Assets:Skrill:Wallet                    -1254.57 EUR

2020-10-06 * "Stake CRO"
    Assets:Crypto-com:App:Wallet:Stake          10000 CRO {}
    Assets:Crypto-com:App:Wallet:CRO         -10000 CRO {EUR}

2020-10-13 * "CRO Stake Rewards"
    Income:Crypto-com:App                     -26.2295082 CRO
    Assets:Crypto-com:App:Wallet:CRO

2020-11-01 * "Buy CRO"
    Assets:Crypto-com:App:Wallet:CRO                 7540 CRO {0.07306 EUR}
    Assets:NB:Checking                       -550.84 EUR

Suppose i have something like this and now i want to trade some of CRO for ETH, i've tried this: (Also tried cost {{ or price @@ at first leg)

2020-11-02 * "Buy ETH"
    Assets:Crypto-com:App:Wallet:ETH            0.5 ETH {{2341.49925 CRO}}
    Assets:Crypto-com:App:Wallet:CRO        -2341.49925 CRO

And get the error "No position matches "Postings.... ", so i've tried adding {EUR} in the Wallet:CRO leg, like this:

2020-11-02 * "Buy ETH"
    Assets:Crypto-com:App:Wallet:ETH            0.5 ETH {{2341.49925 CRO}}
    Assets:Crypto-com:App:Wallet:CRO        -2341.49925 CRO {EUR}

And this throws a "Transaction does not balance: (-171.0699... EUR, 2341.49925 CRO)

The only way i can get this to work is by passing cost in EUR on the first leg, like this:

2020-11-02 * "Buy ETH"
    Assets:Crypto-com:App:Wallet:ETH            0.5 ETH {170.55 EUR} @ 170.55 EUR
    Assets:Crypto-com:App:Wallet:CRO        -2341.49925 CRO {EUR}

With this i have a small transaction does no balance of 52 cents (I think this is because of price difference in my crypo prices entries, no problem with that)
The problem with this approach for me, is that now i see the cost of these 0.5 ETH as EUR, when all i used was CRO. How can i make this appear as CRO? The conversion to EUR should only occurs when i make a transaction/swap to an account that deals with EUR. Or am i wrong? I'm sorry because i'm a noob in all this finance areas :)
Of course this matter is also valid for all the subsequent transactions like (ETH -> DOT, DOT->CRO, ...) 

Already searched a lot and couldn't find and answer, could you please point me in the right direction?
Thanks a lot for your work!

Cheers,

david e

unread,
Mar 23, 2021, 10:31:08 AM3/23/21
to Beancount
hello, I am also new to beancount and started to track my crypto trades with it as well. I have opened a reddit thread where I am trying to solve similar problems. --> link

there you can find one approach to swap one coin for another. in the beginning I thought that I have to subdivide such action into two entries (sell eth for usd, then buy altcoin) but it is very doable to book this in one entry. you have to consider the swap against the cost basis and also calculate the profit you made with this entry.

without going too much into detail with your example, I think it is important to understand the cost basis {price} and price notation correctly. the dollar notation @price is ignored at all and simply for visual clarity. if you add a cost basis to an sell-entry, beancount will look for this specific listing (and returns an error when no such listing exists). without a cost basis, beancount will grab the oldest one available. to make sure this is the case, you can add the following line to the top of your file: option "booking_method" "FIFO" 

hope this helps

Bruno Serrão

unread,
Mar 26, 2021, 3:08:22 PM3/26/21
to Beancount
Yeah, it helps :) thanks.
For me, i think the main problem is to find a good way to separate the entries that are going to be used as coins (where it doesn't matter the cost, like with USD and EUR) from those that refer to trades and want to keep track of PnL.
Reply all
Reply to author
Forward
0 new messages