Is there a way to automatically transfer lots from one account to another 
using FIFO and keeping the prices paid?

E.g.:

I bought `0.13833333 BTC` for `2500 EUR` and `0.125 BTC` for `2500 EUR` on 
Coinbase. I transferred `0.2 BTC` to Binance. I sold all `0.2 BTC` for 
`3500 EUR` on Binance.

*(Which will actually become a swap to another coin. But for taxes I need 
to account an assumed BTC-EUR sell and an assumed X-Token buy. But since I 
got that lot issue the final step is omitted.)*

option "booking_method" "FIFO"
option "operating_currency" "EUR"
option "inferred_tolerance_default" "EUR:0.001"
option "inferred_tolerance_default" "BTC:0.00000001"
2020-12-01 open Equity:Opening-Account
2020-12-01 open Assets:Cash:Coinbase-Pro
2020-12-01 open Assets:Cash:Binance
2020-12-01 open Assets:Crypto:BTC:Coinbase-Pro
2020-12-01 open Assets:Crypto:BTC:Binance
2020-12-01 open Expenses:Commission:Coinbase-Pro:EUR
2020-12-01 open Income:Day-trading:EUR
2020-12-17 * "Coinbase" "Opening"
Assets:Cash:Coinbase-Pro 5000 EUR
Equity:Opening-Account -5000 EUR

2020-12-17 * "Coinbase" "Trade EUR => BTC"
Assets:Cash:Coinbase-Pro -2500 EUR
Assets:Crypto:BTC:Coinbase-Pro 0.13833333 BTC {18,000 EUR} @ 18,000 EUR
Expenses:Commission:Coinbase-Pro:EUR 10 EUR
2020-12-18 * "Coinbase" "Trade EUR => BTC"
Assets:Cash:Coinbase-Pro -2500 EUR
Assets:Crypto:BTC:Coinbase-Pro 0.125 BTC {20,000 EUR} @ 20,000 EUR
Expenses:Commission:Coinbase-Pro:EUR 0 EUR

2020-12-19 * "Binance" "Transfer BTC Coinbase-Pro => Binance"
Assets:Crypto:BTC:Binance 0.2 BTC
Assets:Crypto:BTC:Coinbase-Pro -0.2 BTC

2020-12-20 * "Binance" "Trade BTC => USDT"
Assets:Crypto:BTC:Binance -0.2 BTC {} @ 17,500 EUR
Assets:Cash:Binance 3,500 EUR
Income:Day-trading:EUR

The error I'm getting is:

>$ bean-check Krypto.bean 
> 
>Krypto.bean:38: No position matches 
"Posting(account='Assets:Crypto:BTC:Binance', units=-0.2 BTC, 
cost=CostSpec(number_per=<class 'beancount.core.number.MISSING'>, 
number_total=None, currency='EUR', date=None, label=None, merge=False), 
price=17500 EUR, flag=None, meta={'filename': 'Krypto.bean', 'lineno': 
39})" against balance (0.2 BTC)
>
> 2020-12-20 * "Binance" "Trade BTC => USDT"
> Assets:Crypto:BTC:Binance -0.2 BTC {} @ 17500 EUR
> Assets:Cash:Binance 3500 EUR 
> Income:Day-trading:EUR 

That's probably because the lot information isn't passed in the 2020-12-19 
transfer post.

`--------------------`

According to the manual keeping the lot information could be achieved 
writing the transfer post like this:

2020-12-16 * "Binance" "Transfer BTC Coinbase-Pro => Binance"
Assets:Crypto:BTC:Binance 0.13833333 BTC {18,000 EUR} ; creates a lot 
manually. Not FIFO safe
Assets:Crypto:BTC:Coinbase-Pro -0.13833333 BTC {} ; selects the lot 
automatically. Therefore, Assets:Crypto:BTC:Coinbase-Pro is FIFO safe

But using this means I'm creating a lot in the second account 
`Assets:Crypto:BTC:Binance` manually. So, I'd need to look up which is/are 
the lot(s) that get transferred. Is there a syntax to solve automatically? 
Doing this manually would be cumbersome and error-prone. Dealing with 
cryptos many transfers between exchanges and privately owned wallets are a 
common thing. To keep track of them is crucial for any tax declaration.

I think this is related to:
* https://groups.google.com/g/beancount/c/gecmdDlrxWc/m/qRTJniqQAQAJ
* https://groups.google.com/g/beancount/c/Qvbcq-Sk5NY
* https://github.com/beancount/beancount/issues/168

`--------------------`

In order to do the FIFO manually I need to look up/query my lots, but I'm 
unable to do this. `bean-report FILE holdings` seemed appropriate, but the 
lot date is missing and the units are trimmed/rounded to two digits:

>$ bean-report Krypto.bean holdings
>
>Account Units Currency Cost Currency Average Cost Price Book Value Market 
Value
>------------------------------ ----- -------- ------------- ------------ 
----- ---------- ------------
>Assets:Crypto:BTC:Binance 0.20 BTC BTC 0.20 0.20
Assets:Crypto:BTC:Coinbase-Pro 0.14 BTC EUR 18,000.00 2,490.00 
Assets:Crypto:BTC:Coinbase-Pro 0.12 BTC EUR 20,000.00 2,500.00 
Assets:Crypto:BTC:Coinbase-Pro -0.20 BTC BTC -0.20 -0.20
>------------------------------ ----- -------- ------------- ------------ 
----- ---------- ------------
I also tried `bean-query`. I could add the date, but the unit size is 
rounded as well:

>$ bean-query Krypto.bean 'SELECT account, date, position WHERE 
currency="BTC" ORDER BY account'
>
> account date position 
>------------------------------ ---------- --------------------
>Assets:Crypto:BTC:Binance 2020-12-19 0.2 BTC 
>Assets:Crypto:BTC:Coinbase-Pro 2020-12-17 0.1 BTC {18000 EUR}
>Assets:Crypto:BTC:Coinbase-Pro 2020-12-18 0.1 BTC {20000 EUR}
>Assets:Crypto:BTC:Coinbase-Pro 2020-12-19 -0.2 BTC 

I'd like to have an output with the colums:

account, lot_date, lot_units (using 8 decimal digits), lot_cost (using 8 
decimal digits)
Lots which has been transferred/sold should be omitted, of course. (How) Is 
this possible?

Regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/bb0c459a-dfc7-496f-bb84-2c284cda0a33n%40googlegroups.com.

Reply via email to