Dr-Nuke/drnuke-bean

Closed lot matching fails

Closed this issue · 0 comments

Actually, a closed lot is matched on trade date and symbol on sell.
However, this is wrong if there are multiple sell transactions with the same date. In this case the first sell transaction will be matched with all closed lots.

Example:
2020-05-26 * "SKT" "BUY 300 SKT @ 6.625 USD"
Assets:Invest:IB:SKT 300 SKT {6.625 USD, 2020-05-26}
Assets:Invest:IB:USD -1987.50 USD
Assets:Invest:IB:USD -1.50 USD
Expenses:Invest:IB:Fees:USD 1.50 USD

2020-06-10 * "SKT" "SELL -100 SKT @ 8.23 USD"
Assets:Invest:IB:USD 823.00 USD
Assets:Invest:IB:SKT -100 SKT {6.63 USD, 2020-05-26} @ 8.23 USD
Assets:Invest:IB:SKT -100 SKT {6.63 USD, 2020-05-26} @ 8.23 USD
Assets:Invest:IB:SKT -100 SKT {6.63 USD, 2020-05-26} @ 8.23 USD
Income:Invest:IB:SKT:GuV
Assets:Invest:IB:USD -1.03 USD
Expenses:Invest:IB:Fees:USD 1.03 USD

2020-06-10 * "SKT" "SELL -100 SKT @ 8.22 USD"
Assets:Invest:IB:USD 822.00 USD
Income:Invest:IB:SKT:GuV
Assets:Invest:IB:USD -0.03 USD
Expenses:Invest:IB:Fees:USD 0.03 USD

2020-06-10 * "SKT" "SELL -100 SKT @ 8.23 USD"
Assets:Invest:IB:USD 823.00 USD
Income:Invest:IB:SKT:GuV
Assets:Invest:IB:USD -0.53 USD
Expenses:Invest:IB:Fees:USD 0.53 USD