Skip to content

Latest commit

 

History

History
139 lines (94 loc) · 13.4 KB

0012-POSR-position_resolution.md

File metadata and controls

139 lines (94 loc) · 13.4 KB

Position resolution

Acceptance Criteria

  • All orders of "distressed traders" in cross-margin mode are cancelled (0012-POSR-001)

  • Open positions of distressed traders are closed immediately (0012-POSR-002)

  • Mark Price is never updated during position resolution (0012-POSR-004)

  • Non-distressed traders who trade with the network because their open orders are hit during the networks' trade have their positions settled correctly. (0012-POSR-005)

  • When a distressed party has a staking account with the same currency as the settlement currency of the market where it's distressed the staking account is NOT used in margin search and liquidation. (0012-POSR-006)

  • When a party is distressed and gets closed out the network's position gets modified to reflect that it's now the network party that holds that volume. (0012-POSR-009)

  • When the network party holds a non-zero position and there are not enough funds in market's insurance pool to meet the mark-to-market payment the network's position is unaffected and loss socialisation is applied. (0012-POSR-010)

  • When the network party holds a non-zero position and the market's insurance pool balance is below the network party's maintenance margin for that market the network's position in that market remains unaffected. (0012-POSR-011)

  • The liquidation strategy can be updated using the market update transaction (0012-POSR-012)

  • When the market is configured to use:

    • disposal time step = 10s,
    • disposal fraction = 0.5,
    • full disposal size = 50,
    • max fraction of book side within liquidity bounds consumed = 0.01

    and the volume on the buy side of the book within the liquidity bounds is always 10,000 (as volume on the book gets filled new orders get placed) then liquidating a distressed party with an open volume of 280 results in 4 network trades in total spaced 10s apart with volumes of: 100, 90, 45, 45. (0012-POSR-013)

  • It is possible to check the network party's open volume and margin level in any market via the API. (0012-POSR-014)

  • It is possible to check the time of the next liquidation trade attempt in any market via the API. (0012-POSR-015)

Network position disposal

  • When calculating the available volume, the full remaining size of iceberg orders should be considered. (0012-POSR-019)
  • When calculating the available volume, volume outside price monitoring bounds should be considered. (0012-POSR-020)
  • When calculating the available volume, volume outside the disposal price range should not be considered. (0012-POSR-033)
  • Given a highly liquid market, if the network’s position is greater than full disposal size. The network must attempt to dispose position * disposal fraction at the next disposal step. (0012-POSR-022)
  • Given a highly liquid market, if the network’s position is less than or equal to full disposal size. The network must attempt to dispose of its full position at the next disposal step. (0012-POSR-023)
  • Given a highly liquid market, if the network’s disposal fraction<1 and full disposal size=0, the network must still eventually dispose of its full position. (0012-POSR-024)
  • The network must never dispose more than available volume * max fraction of book side within liquidity bounds consumed in a single order. (0012-POSR-025)
  • A network disposal order which generates trades must not affect the mark price. (0012-POSR-026)
  • A network disposal order can not cross with orders outside the disposal price range. (0012-POSR-031)
  • A network disposal order will not cross with orders outside price monitoring bounds (internally has to behave like an IOC at one tick inside the price monitoring bound). Hence a network disposal cannot trade at a price outside the tightest price monitoring and it won't ever trigger a price monitoring auction. (0012-POSR-030)
  • A network disposal order which crosses multiple orders should generate multiple atomic trades. (0012-POSR-029)
  • A network disposal order which crosses with volume implied by an vAMM should trade with the vAMM volume. (0012-POSR-032)

Network Profit and Loss

  • Given the network starts with no position and does not dispose any of it's position during the scenario: (0012-POSR-016)

    • The mark price moves to 100, the network liquidates a distressed party with a long position of 1. The network should report a position of 1 and a realised and unrealised pnl of 0 and 0 respectively.
    • The mark price moves to 120, the network liquidates a distressed party with a short position of -1. The network should report a position of -1 and a realised and unrealised pnl of 20 and 0 respectively.
    • The mark price moves to 60. The network should report a position of -1 and a realised and unrealised pnl of 20 and 60 respectively.
  • Given the network starts with no position and does not dispose any of it's position during the scenario: (0012-POSR-017)

    • The mark price moves to 100, the network liquidates a distressed party with a long position of 1. The network should report a position of 1 and a realised and unrealised pnl of 0 and 0 respectively.
    • The mark price moves to 90, the network liquidates a distressed party with a long position of 1 (average entry price now equals 95). The network should report a position of 2 and a realised and unrealised pnl of 0 and -10 respectively.
    • The mark price moves to 60. The network should report a position of 2 and a realised and unrealised pnl of 0 and -70 respectively.
  • Given an empty insurance pool and the liquidation strategy disposal time step = 5, disposal fraction = 0.5, full disposal size=0 and max fraction of book side within liquidity bounds consumed = 0.01 during the below scenario: (0012-POSR-018)

    • The mark price moves to 100, the network liquidates a distressed party with a long position of 2. The network should report a position of 2 and a realised and unrealised pnl of 0 and 0 respectively.
    • Given the order book:
      side price size
      buy 90 1000
      sell 110 1000
    • The time updates to the next disposal time, the network reduces its position by 1. The network should report a position of 1 and a realised and unrealised pnl of -10 and 0 respectively.
    • The time updates to the next disposal time, the network reduces its position by 1. The network should report a position of 1 and a realised and unrealised pnl of -20 and 0 respectively.
    • Loss socialisation should be applied and the accumulated balance for all accounts should be unchanged.

Summary

Position resolution is the mechanism which deals with closing out distressed positions on a given market. It is instigated when one or more participant's margin account balance falls below their latest maintenance margin level.

Guide-level explanation

Reference-level explanation

Any trader that has insufficient collateral to cover their margin liability is referred to as a "distressed trader".

Position resolution algorithm

Liquidating distressed party's position in a market

  • Position resolution evaluation gets carried out each time the mark price is updated, strictly after the margin levels margin level update and mark-to-market settlement.

  • During position resolution evaluation party's margin account balance is compared to it's latest maintenance margin level. If the account balance is below the margin level then the party gets marked as distressed.

  • If a party marked as "distressed" has the cross-margin mode selected for the market being considered:

    • all their open orders on that market get cancelled without releasing any collateral from the margin account,
    • their margin level then gets recalculated to account only for the open volume they hold in a market
    • if party's margin account balance is now above or equal to their latest maintenance margin level then such party is no longer marked as "distressed".
  • If party's is marked as "distressed" at this stage then:

    • their open volume gets added to network's open volume for that market,
    • party's open volume in that market gets set to 0,
    • the full amount of party's margin account balance gets transferred to market's insurance pool.

This concludes the position resolution from party's perspective.

Managing network's position

Whilst network has a non-zero position in a given market it's treated as any other party with market's insurance in that market acting as its margin account and with and exception that margin search, margin release or liquidation are never attempted on a network party.

Whenever the network party has a non-zero position it attempts to unload it using an immediate or cancel limit order. If the the network has a long position it will submit a sell order. If it has a short position it will submit a buy order. The size of that order is chosen according to the liquidation strategy which forms a part of the market's configuration. The strategy can be updated at any point whilst market is active with a market change governance vote.

Currently only one liquidation strategy is supported and its defined by the following parameters:

  • disposal time step (min: 1s, max: 1h): network attempts to unload its position in a given market every time it goes out of auction and then every disposal time step seconds as long as market is not in auction mode and while the network's position is not equal to 0,
  • disposal fraction (min: 0.01, max: 1): fraction of network's current open volume that it will try to reduce in a single disposal attempt,
  • full disposal size (min: 0, max: max int): once net absolute value of network's open volume is at or below that value, the network will attempt to dispose the remaining amount in one go,
  • disposal slippage range (decimal >0 with default of 0.1 which is interpreted as 10%, existing markets to default to their current SLA range). Just like SLA range these are taken from mid_price during continuous trading or indicative uncrossing price during auctions so the lower bound becomes max(0,price x (1-range) and upper bound price x (1+range).
  • max fraction of book side within bounds consumed (min: 0, max: 1): once the network chooses the size of its order (s_candidate) the effective size will be calculated as s_effective=min(m*N, s_candidate), where N is the sum of volume (on the side of the book with which the network's order will be matching) that falls within the range implied by the disposal slippage range and m is the max fraction of book side within liquidity bounds consumed. When vAMMs are implemented and provide liquidity then volume implied by vAMMs that lies within the relevant range must be included in the calculation.

Assume the price range implied by the disposal slippage range is [a, b]. Assume the the tightest price monitoring bound has lower bound plus one tick of c and upper bound minus one tick of d. Once the network has worked out a size of its immediate or cancel limit order it sets its price to max(a,c) if it's a sell order or min(b,d) if it's a buy order, and it submits the order.

Note that setting:

  • disposal time step = 0s,
  • disposal fraction = 1,
  • full disposal size = max int,
  • disposal slippage range = 10,
  • max fraction of book side within liquidity bounds consumed = 1

is closest to reproducing the legacy setup where party would get liquidated immediately (with a difference that closeout now happens immediately even if there's not enough volume on the book to fully absorb it) hence the above values should be used when migrating existing markets to a new version. For all new markets these values should be specified explicitly.

Different liquidation strategies with different parameters might be proposed in the future, hence implementation should allow for easy substitution of strategies.

API requirements:

  • create an endpoint to easily identify network's position in any given market,
  • create an endpoint to easily identify network's margin levels in any given market,
  • create an endpoint to easily check time of next liquidation trade attempt.