Open patrickdugan opened 1 year ago
Needs some work where commented.
https://github.com/BlockPo/BlockPo-to-Tradelayer/commit/3cc0d10dd85bb973000aff44fab7274c00c3ee50
https://github.com/BlockPo/BlockPo-to-Tradelayer/pull/496
Ok there's a branch ready to test with this and all merge issues resolved.
Current version is settling everything at mark price even positions that were closed that block, so you're not really getting out at the trade price.
To fix this we realize the PNL from closing positions in the flow of the decrease_entry function that is called in mdex:
https://github.com/BlockPo/BlockPo-to-Tradelayer/blob/settlement-vs.-realizedPNL/src/tradelayer/register.cpp
Creating new functions to call during that flow, or that write to the register about exit trades in a block, and then later in the flow before calling settlement we realize the PNLs from all the position-reducing trades. Since the position size is lower for the mark-price settlement that follows, these two functions probably don't step on each others toes...