Since I needed a tool to tell me if trade is actually making money, I started working on one. What I've made so far is something that takes these transactions:
And returns this output:
Which are correct*.
If I delete the database and re-run it, it initializes correctly.
If I then run it with only the first two transactions, it returns correct values (0 on market, -0.02 profits).
If I then run it with the next two transactions, it returns correct values as you see above.
These don't quite add up to it definitely working correctly, but they are encouraging signs. I'll plan to give it a real test run soon(tm).
*It took longer than I would have liked to be sure about this.