(Apologies for the long response, you've triggered an interesting corner
case which may require a fix.)

The error you made here (deducting 1.0 BTC from the account with existing
positions without specifying the cost basis) brings up an interesting
corner case.


The following is sufficient to trigger the error:


2013-11-27 open Assets:AU:Coinjar:BTC  BTC
2013-11-27 open Assets:AU:Coinjar:Cash AUD
2013-11-27 open Assets:AU:ColdStorage:BTC BTC

2014-01-05 * "Deposit Cold storage"
  Assets:AU:ColdStorage:BTC                     1.0 BTC
  Assets:AU:Coinjar:BTC                        -1.0 BTC

2014-01-28 * "Buy BTC"
  Assets:AU:Coinjar:BTC                         0.162288 BTC
{924.2827565808932268559597752 AUD}
  Assets:AU:Coinjar:Cash                     -150.00 AUD


What's happening is that after the first transaction the Coinjar:BTC
account contains a negative number of units of BTC:

bean-doctor context smile1.beancount 6
Hash:f7a2fba6639dd0ec5d52abce3788f32d
Location: /home/blais/r/q/beancount-data/user/smile/smile1.beancount:5

------------ Balances before transaction

  Assets:AU:ColdStorage:BTC

  Assets:AU:Coinjar:BTC


------------ Transaction

2014-01-05 * "Deposit Cold storage"
  Assets:AU:ColdStorage:BTC   1.0 BTC
  Assets:AU:Coinjar:BTC      -1.0 BTC


Tolerances: BTC=0.05

------------ Balances after transaction

* Assets:AU:ColdStorage:BTC                                            1.0
BTC

* Assets:AU:Coinjar:BTC                                               -1.0
BTC


"Adding" BTC to this negative inventory essentially means a "reduction" of
the negative number of BTC (you're reducing the short position).
Since the second transaction is providing a cost basis and it has only a
single lot with no cost basis, it cannot find a lot that matches, so you
get an error.
This is WAI.
(But it does beg the question regarding whether lots without a cost basis
should be treated distinctly; so far I'm not convinced that they should, I
don't have a great use case for that, so they're not.)



If I leave all the previous transactions, one gets into a slightly
different case:

bean-doctor context smile1.beancount 27
Hash:f7a2fba6639dd0ec5d52abce3788f32d
Location: /home/blais/r/q/beancount-data/user/smile/smile1.beancount:26

------------ Balances before transaction

  Assets:AU:ColdStorage:BTC

  Assets:AU:Coinjar:BTC      0.14161 BTC {1059.247228303085940258456324
AUD, 2013-11-27}
  Assets:AU:Coinjar:BTC      0.118776 BTC {1262.881390179834309961608406
AUD, 2013-11-29}
  Assets:AU:Coinjar:BTC      0.149156 BTC {1005.658505189197886776261096
AUD, 2013-12-10}
  Assets:AU:Coinjar:BTC      0.673358 BTC {742.5470552068884605217432629
AUD, 2013-12-17}
  Assets:AU:Coinjar:BTC      0.230398 BTC {651.0473181190808947994340229
AUD, 2013-12-19}


------------ Transaction

2014-01-05 * "Deposit Cold storage"
  Assets:AU:ColdStorage:BTC   1.000000 BTC
  Assets:AU:Coinjar:BTC      -1.000000 BTC


Tolerances: BTC=0.05

------------ Balances after transaction

* Assets:AU:ColdStorage:BTC                                            1.0
BTC

  Assets:AU:Coinjar:BTC      0.14161 BTC {1059.247228303085940258456324
AUD, 2013-11-27}
  Assets:AU:Coinjar:BTC      0.118776 BTC {1262.881390179834309961608406
AUD, 2013-11-29}
  Assets:AU:Coinjar:BTC      0.149156 BTC {1005.658505189197886776261096
AUD, 2013-12-10}
  Assets:AU:Coinjar:BTC      0.673358 BTC {742.5470552068884605217432629
AUD, 2013-12-17}
  Assets:AU:Coinjar:BTC      0.230398 BTC {651.0473181190808947994340229
AUD, 2013-12-19}
* Assets:AU:Coinjar:BTC                                               -1.0
BTC


Here, in theory (excluding the last transaction), there are enough BTC to
cover the -1.0 reduction and keep the balance positive:

bean-query smile1.beancount "select account, sum(units(position)) group by
1"
         account          sum_units_positi
------------------------- ----------------
Assets:AU:Coinjar:BTC         0.313298 BTC
Assets:AU:Coinjar:Cash    -1100.00     AUD
Assets:AU:ColdStorage:BTC     1.0      BTC


The real problem is that the transaction removing -1.0 BTC from the
Coinjar:BTC should have failed and raised an error message. It's a bug that
it did not (I'll have to address that; I'm quite surprised this wasn't
covered by my unit tests - thanks for bringing up that question).

Ticket:
https://bitbucket.org/blais/beancount/issues/167/reductions-without-a-cost-basis-should

Now, with the default booking method (STRICT) If you reduce an existing
position, you should have to provide the cost basis you want to book
against. Given the frequency with which those transactions appear to occur,
explicitly selecting each of the lots to reduce in order to move your 1.0
BTC to cold storage would be a pain in the butt. I think you'll want
something easier.

Normally, you can set that account's booking algorithm to something else,
e.g. "FIFO", which would select the lots for you:

2013-11-27 open Assets:AU:Coinjar:BTC  BTC  "FIFO"
...
2014-01-05 * "Deposit Cold storage"
  Assets:AU:ColdStorage:BTC                     1.0 BTC
  Assets:AU:Coinjar:BTC                        -1.0 BTC {}


But this appears to trigger another bug!
Congratulations, you've found two at once (finding one is reasonably rare
these days).

Tickets:
https://bitbucket.org/blais/beancount/issues/168/fifo-without-a-cost-currency-appears-to


I'm going to fix those, but in any case, you shouldn't be able to reduce an
inventory with lots with -1.0 BTC.
Either you'll have to select the lots explicltly, or let one of the
automatic booking methods do it for you.
In any case, you should probably never mix operations at cost (with {...})
with those not at cost (without {...}) on a single account.

In the meantime, you can disable the booking algorithm by setting the
method to "NONE":

2013-11-27 open Assets:AU:Coinjar:BTC  BTC  "NONE"
...
2014-01-05 * "Deposit Cold storage"
  Assets:AU:ColdStorage:BTC                     1.0 BTC
  Assets:AU:Coinjar:BTC                        -1.0 BTC

This effectively replicates the Ledger model. The resulting inventory will
have all the transactions in it, and you can sum up the resulting number of
UNITS() or COST() and these numbers will be correct. However, the detailed
contents of the inventory will appear messy. But it works.

I think the way forward is for me to fix the two bugs and for you to use
the FIFO method thereafter.

Or... it's also possible that you're not attempting to track cost basis.
If that's the case you can just use price conversions (with @ ...).
If you used price conversions, there are no lots (well, just a single lot
with no cost basis).

I hope this helps,





On Mon, Jun 12, 2017 at 12:48 AM, <[email protected]> wrote:

> Hi there,
>
> I'm new to beancount and I'm trying to use it to bring sanity to some old
> Bitcoin transactions.
>
> I start off making the odd purchase of BTC in Australian dollars using the
> Coinjar service with one beancount account for BTC and one for AUD.
>
> However, once I move 1.0 BTC out of my Coinjar BTC account into a paper
> wallet, subsequent purchases throw an error in bean-check:
>
> No position matches "Posting(account='Assets:AU:Coinjar:BTC',
> units=0.162288 BTC, 
> cost=CostSpec(number_per=Decimal('924.2827565808932268559597752'),
> number_total=None, currency='AUD', date=None, label=None, merge=False),
> price=None, flag=None, meta={'lineno': 24, 'filename':
> '/home/dave/fin/accounts/bitcoin-test.beancount'})" against balance (-1.0
> BTC, 0.230398 BTC {651.0473181190808947994340229 AUD, 2013-12-19}, 0.673358
> BTC {742.5470552068884605217432629 AUD, 2013-12-17}, 0.149156 BTC
> {1005.658505189197886776261096 AUD, 2013-12-10}, 0.14161 BTC
> {1059.247228303085940258456324 AUD, 2013-11-27}, 0.118776 BTC
> {1262.881390179834309961608406 AUD, 2013-11-29})
>
> But of course no existing position matches; this is a new lot I'm
> purchasing. Here's a simple sample file to reproduce. Could someone perhaps
> clarify where I've gone wrong? Thanks for your time; I've read the
> documentation on booking trades several times but I'm afraid I can't make
> sense of this error.
>
>
> 2013-11-27 open Assets:AU:Coinjar:BTC  BTC
> 2013-11-27 open Assets:AU:Coinjar:Cash AUD
> 2013-11-27 open Assets:AU:ColdStorage:BTC BTC
>
>
> 2013-11-27 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.14161 BTC
> {1059.247228303085940258456324 AUD}
>   Assets:AU:Coinjar:Cash                     -150.00 AUD
> 2013-11-29 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.118776 BTC
> {1262.881390179834309961608406 AUD}
>   Assets:AU:Coinjar:Cash                     -150.00 AUD
> 2013-12-10 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.149156 BTC
> {1005.658505189197886776261096 AUD}
>   Assets:AU:Coinjar:Cash                     -150.00 AUD
> 2013-12-17 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.673358 BTC
> {742.5470552068884605217432629 AUD}
>   Assets:AU:Coinjar:Cash                     -500.00 AUD
> 2013-12-19 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.230398 BTC
> {651.0473181190808947994340229 AUD}
>   Assets:AU:Coinjar:Cash                     -150.00 AUD
> 2014-01-05 * "Deposit Cold storage"
>   Assets:AU:ColdStorage:BTC                     1.0 BTC
>   Assets:AU:Coinjar:BTC                        -1.0 BTC
> ; The following tx now throws an error though it is syntactically
> identical to the
> ; purchases above. Why?
> 2014-01-28 * "Buy BTC"
>   Assets:AU:Coinjar:BTC                         0.162288 BTC
> {924.2827565808932268559597752 AUD}
>   Assets:AU:Coinjar:Cash                     -150.00 AUD
>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/beancount/2beb84b0-8f10-4c40-b6d5-abfa2b77cda5%40googlegroups.com
> <https://groups.google.com/d/msgid/beancount/2beb84b0-8f10-4c40-b6d5-abfa2b77cda5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAK21%2BhOs5fu8-1DZcar-e95aoFJyVti196BFLb%3D6S0yKLOnZEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to