BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

Separating realizedPNL from settlement #493

Open patrickdugan opened 1 year ago

patrickdugan commented 1 year ago

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...

patrickdugan commented 1 year ago

Needs some work where commented.

https://github.com/BlockPo/BlockPo-to-Tradelayer/commit/3cc0d10dd85bb973000aff44fab7274c00c3ee50

patrickdugan commented 1 year ago

https://github.com/BlockPo/BlockPo-to-Tradelayer/pull/496

Ok there's a branch ready to test with this and all merge issues resolved.