Skip to content

Commit

Permalink
feat: isolated margin (#1850)
Browse files Browse the repository at this point in the history
* feat: Isolated margin
  • Loading branch information
TomMcL authored Nov 1, 2023
1 parent 99b8306 commit dcf39b9
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 43 deletions.
3 changes: 2 additions & 1 deletion protocol/0010-MARG-margin_orchestration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ This specification outlines:

### **Background - how margin levels are calculated**

The [margin calculator](./0019-MCAL-margin_calculator.md) will calculate the margin levels when instructed to do so. It will return four margin levels for each trader:
The [margin calculator](./0019-MCAL-margin_calculator.md) will calculate the margin levels when instructed to do so. It will return five margin levels for each trader:

1. maintenance margin
1. order margin
1. collateral search level
1. initial margin
1. collateral release level
Expand Down
2 changes: 1 addition & 1 deletion protocol/0012-POSR-position_resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Any trader that has insufficient collateral to cover their margin liability is r

See [Whitepaper](https://vega.xyz/papers/vega-protocol-whitepaper.pdf), Section 5.3 , steps 1 - 3

1. A "distressed trader" has all their open orders on that market cancelled. Note, the network must then recalculate their margin requirement on their remaining open position and if they now have sufficient collateral (i.e. aren't in the close out zone) they are no longer considered a distressed trader and not subject to position resolution. The market may at any point in time have multiple distressed traders that require position resolution. They are 'resolved' together in a batch.
1. A "distressed trader" in cross-margining mode has all their open orders on that market cancelled. Note, the network must then recalculate their margin requirement on their remaining open position, perform one final margin search and if they now have sufficient collateral (i.e. aren't in the close out zone) they are no longer considered a distressed trader and not subject to position resolution. The market may at any point in time have multiple distressed traders that require position resolution. They are 'resolved' together in a batch.
1. The batch of distressed open positions that require position resolution may be comprised of a collection of long and short positions. The network calculates the overall net long or short position. This tells the network how much volume (either long or short) needs to be sourced from the order book. For example, if there are 3 distressed traders with +5, -4 and +2 positions respectively. Then the net outstanding liability is +3. If this is a non-zero number, do Step 3.
1. This net outstanding liability is sourced from the market's order book via a single market order (in above example, that would be a market order to sell 3 on the order book) executed by the network as a counterpart. This internal entity is the counterpart of all trades that result from this single market order and now has a position which is comprised of a set of trades that transacted with the non-distressed traders on the order book. Note, the network's order should not incur a margin liability. Also, these new positions (including that incurred by the network) will need to be "MTM settled". This should happen after Step 5 to ensure we don't bankrupt the market's insurance pool before collecting the distressed trader's collateral. This has been included as Step 6.
1. The network then generates a set of trades with all the distressed traders all at the volume weighted average price of the network's (new) open position. These trades should be readily distinguished from the trades executed by the network counterpart in Step 3 (suggest by a flag on the trades)
Expand Down
Loading

0 comments on commit dcf39b9

Please sign in to comment.