Descentralized Exchange with Margin Trading

in #ethereum5 years ago (edited)

photo_2019-11-09_22-34-34.jpghttps://bit.ly/2qGRWer

DMEX is the first of its kind Decentralized P2P Margin Trading Platform. On DMEX users can trade a select list of crypto assets with up to 100X leverage without ever committing their funds into the custody of a third party.
DMEX is comprised of three smart contracts running on the Ethereum blockchain, a web interface (the dmex.app website) and a backend server. We will discuss the function of each element in Part 2 of these series.
On DMEX, users trade futures contracts. A futures contract is a virtual agreement comprising of the following parameters:
Asset — the underlying asset being traded (eg. Bitcoin, Ethereum etc)
Expiration — the time when the futures contract expires and has to be settled
Floor Price — the lower limit of the price that can be traded on the contract (if the limit is reached, the contract is settled prematurely)
Cap Price — the upper limit for the price that can be traded on the contract (if limit reached, the contract is settled prematurely)
Funding Rate — the funding rate that will be deducted per block for the duration of the position.
Multiplier — the exchange rate of the base token to the traded pair (eg. if the asset pair is BTC/USD, and the collateral currency is ETH, then the multiplier = 1/(ETHUSD price)). This is needed to transform USD profit/loss into the base token.
The Asset comprises of the following information:
Asset Name — the name of the asset, i.e. Bitcoin, Litecoin, etc
Base Token — the collateral currency (ETH, USDT, etc)
Price Url — the URL where the price will be taken by the Oracle on the expiration date or when the upper or lower limit is breached. This is an API endpoint on an external exchange that returns a JSON string containing the latest price on the said exchange (eg. https://www.bitstamp.net/api/v2/ticker/btcusd/)
Price Path — the parameter in the JSON response that denotes the latest price. In the Bitstamp example, it is “last”.
Every Asset has a unique hash. That unique hash is used in the “Asset” parameter when creating a new Futures Contract.
The Futures Contract has a unique hash as well derived from its parameters. When a user places an order, the order is placed to trade a specific futures contract and the futures contract hash is embedded in the user’s signature.
Depending on the parameters of the order (margin level, expiration date) the appropriate futures contract hash is generated by the DMEX Web Application and sent for matching to the DMEX server.
The matching is performed as is usually done on an exchange, buy orders and sell orders are matched against one another and if the price condition matches, a new trade is created. The trade is then sent to the Smart Contract and a position is opened.
A position contains the following information:
Size — the number of futures contracts bought, denoted in terms of the underlying asset (eg. 0.5 Bitcoin).
Entry Price — the price at which the position was opened, this will be adjusted if the position is increased to signify the Average Entry Price.
Side — True if the position is Long, False if the position is short
Entry Block — the Ethereum block at which the position was opened, this will be adjusted if the position is increased to signify the Average Entry Block (used for funding cost calculation).
In DMEX the margin level is calculated from the Floor and Cap price of the futures contract. If you open a Long position for 1 Bitcoin at price 10,000 USD on a futures contract with Floor Price = 8,000 USD, you need to provide 2,000 USD as collateral (the maximum possible loss 10,000–8,000). This means that you are buying 10,000 worth of bitcoin by having only 2000 as collateral, creating a 5x margin. Similarly, if you go Short for 1 Bitcoin at price 10000 and Cap Price 12,000 USD you need to provide only 2000 USD as collateral, providing for the same 5x margin level.

https://bit.ly/2qGRWer

Sort:  

@concorde You have received a 100% upvote from @botreporter because this post did not use any bidbots and you have not used bidbots in the last 30 days!

Upvoting this comment will help keep this service running.