BlockPo / BlockPo-to-Tradelayer

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

Stop Loss Order #412

Open patrickdugan opened 3 years ago

patrickdugan commented 3 years ago

Problem: managing risk with leverage in a Dex environment is hard. You might not be able to get a Trade Channel counterparty to book you a close on your risky position when the market is moving 10-20% in <15 min. Bart risk. Bart risk is then, systemic risk. How can we improve this?

By adding an optional Stop Price parameter to every Instant Contract trade or on-chain contractTrade tx. The xTrade function will look at the mark price, look at the stack of extant Stop Orders, and match them based on chronological-seniority to any on-chain limit orders. Then, after Stop Orders are exhausted, general orders will be able to match.

When a stop parameter is entered into a confirmed trade, a List structure gets the order added to it. Orders are treated logically in the same way that reduce-only orders are treated on centralized exchanges. If an Order's associated address is found to not have a contract position, the order would be canceled, removed from the list. If a position in the same contract is on the address, and it's <= to the size of the stop, then it goes in for matching. If it's a smaller sized remaining position than the order, then the contract would flatten. If the position > the stop, then some position would be left over.

Putting this on Native so we can beeline towards decent live functionality, try to launch that, and improve risk management with this a bit later.

patrickdugan commented 2 years ago

We should still do this. Doesn't have to be a launch feature but should be added with the Insurance Fund v2 in an early upgrade before we go fully hands off.