Your assertion entry fails to balance because it has just one regular posting. An unbalanced posting would work (parenthesise the account name).
I'm not sure exactly what's going on in your example, but here's an attempt at modeling a similar, complete scenario, with maximum correctness a la #1177.
2019-07-01 opening balances, add $10000 cash
assets:cash $10000 = $10000
equity:opening/closing balances
2019-07-01 purchase 1000 shares of BKT1 for $9900
assets:bucket1 1000 "BKT1" = 1000 "BKT1" ; quotes because of the digit
assets:cash -$9900 = $100
; all shares cashed out from bucket1 to buy shares in bucket2:
2019-12-31 sell all BKT1 for $10000, and realize capital gains
assets:bucket1 -1000 "BKT1" = 0 "BKT1"
equity:exchange 1000 "BKT1"
equity:exchange -$10000
assets:cash $10000 = $10100
revenues:tax-deferred:gains $-100 ; gain for lot: 1000 BKT1 acquired 2019-07-01
assets:cash $100 = $10200
2019-12-31 buy BKT2 with the proceeds
assets:bucket2 995 "BKT2" = 995 "BKT2"
equity:exchange -995 "BKT2"
equity:exchange $10000
assets:cash -$10000 = $200
I'm not sure I have it right though. It gives these reports:
cash transactions:
$ hledger reg -w 90,30 cash
2019-07-01 opening balances, add $10000.. assets:cash $10000 $10000
2019-07-01 purchase 1000 shares of BKT1.. assets:cash $-9900 $100
2019-12-31 sell all BKT1 for $10000, an.. assets:cash $10000 $10100
assets:cash $100 $10200
2019-12-31 buy BKT2 with the proceeds assets:cash $-10000 $200
bucket1 transactions:
$ hledger reg -w 90,30 bucket1
2019-07-01 purchase 1000 shares of BKT1.. ..1 1000 "BKT1" 1000 "BKT1"
2019-12-31 sell all BKT1 for $10000, an.. ..1 -1000 "BKT1" 0
bucket2 transactions:
$ hledger reg -w 90,30 bucket2
2019-12-31 buy BKT2 with the proceeds assets:bucket2 995 "BKT2" 995 "BKT2"
all ending balances:
$ hledger bal --flat -E
0 assets:bucket1
995 "BKT2" assets:bucket2
$200 assets:cash
1000 "BKT1"
-995 "BKT2" equity:exchange
$-10000 equity:opening balances
$-100 revenues:tax-deferred:gains
--------------------
$-9900
1000 "BKT1"
balance sheet:
$ hledger bs --flat -E
Balance Sheet 2019-12-31
|| 2019-12-31
================++==================
Assets ||
----------------++------------------
assets:bucket1 || 0
assets:bucket2 || 995 "BKT2"
assets:cash || $200
----------------++------------------
|| $200, 995 "BKT2"
================++==================
Liabilities ||
----------------++------------------
----------------++------------------
||
================++==================
Net: || $200, 995 "BKT2"
balance sheet including (some) equity:
$ hledger bse --flat -E not:'opening balances'
Balance Sheet With Equity 2019-12-31
|| 2019-12-31
=================++==========================
Assets ||
-----------------++--------------------------
assets:bucket1 || 0
assets:bucket2 || 995 "BKT2"
assets:cash || $200
-----------------++--------------------------
|| $200, 995 "BKT2"
=================++==========================
Liabilities ||
-----------------++--------------------------
-----------------++--------------------------
||
=================++==========================
Equity ||
-----------------++--------------------------
equity:exchange || -1000 "BKT1", 995 "BKT2"
-----------------++--------------------------
|| -1000 "BKT1", 995 "BKT2"
=================++==========================
Net: || $200, 1000 "BKT1"
income statement:
$ hledger is --flat
Income Statement 2019-07-01-2019-12-31
|| 2019-07-01-2019-12-31
=============================++=======================
Revenues ||
-----------------------------++-----------------------
revenues:tax-deferred:gains || $100
-----------------------------++-----------------------
|| $100
=============================++=======================
Expenses ||
-----------------------------++-----------------------
-----------------------------++-----------------------
||
=============================++=======================
Net: || $100