DeFi 101. Part 2— Margin Trading

A 3-part series on decentralized lending, margin trading, and spot trading

Missed part 1? Check it out!

In part 1, we discussed how decentralized lending and borrowing works. To quickly summarize: decentralized loans are secured through the use of collateral, deposited by the borrower. As long as a loan is over-collateralized (the collateral is worth more than the borrowed assets), the loan stays open. If the loan becomes under-collateralized, the collateral can be liquidated (sold to payback the loan) by the lending platform.

As of now, the primary use for borrowing crypto assets is Margin Trading. Decentralized Margin Trading cannot happen without the ability to take loans trustlessly!

Building on part 1, in this article we will dive into how Margin Trading leverages loans to create positions: amplifying gains/losses and creating the ability to “short” markets.

Disclaimer: this series of articles is designed to be educational and informative. It is NOT investment advice. It is not an attempt to sway you into Margin Trading, nor do I assume any liability for your trades :) All trading, especially on margin, is inherently risky: please be careful and do your own research and due diligence!

Part 2 — Decentralized Margin Trading

What is Margin Trading?

The term Margin refers to borrowed assets. Margin Trading is thus the process of trading borrowed assets.

When you trade on margin, you are “taking a position” on a given market.

Why do people trade on Margin?

Margin trading amplifies your gains or losses. By borrowing funds and then trading them, you can leverage a position on a market: a 2x leverage would double my gains or losses, 3x would triple them, etc. The ability to margin trade allows traders to actualize greater returns without investing additional money into a particular asset.

Margin Trading also opens up an entirely new type of trading that is not possible with spot trading: the ability to bet on the decline of an asset’s price (called a “short”).

In the decentralized world, this can all be done trustlessly through the clever use of smart contracts, collateral management, and liquidations.

What are positions?

Your margin position is what you believe is going to happen in a given market: either LONG or SHORT. If I am LONG on ETH-DAI, I believe that the price of ETH is going to rise with respect to the price of DAI. If I’m SHORT on ETH-DAI, I believe that the price of ETH is going to decrease with respect to the price of DAI.

Long means I think the price is going to go up

Short means I think the price is going to go down

An Example: Understanding Margin Trading

Let’s go through our glorious Bob example once more.

Bob believes that the price of ETH is going to rise with respect to the price of DAI. Currently ETH is priced at 260 DAI. Bob only has 2 ETH though, and decides that he wants to leverage his position to make more gains!

So Bob deposits his 2 ETH as collateral, and takes out a 260 DAI loan at 10% APR. Bob then takes this 260 DAI loan to his favorite Decentralized Exchange and buys 1 ETH with it. Now Bob has 3 ETH (with a 260 DAI loan) — his position is now a 1.5x Leveraged Long on ETH-DAI.

Bob borrowed 260 DAI, then traded it for 1 ETH

A couple months later, ETH’s price shoots up to 300 DAI and Bob decides he wants to close his position. To do this, Bob needs to repay his 260 DAI loan, plus ~5 DAI of interest. So Bob sells 265 DAI worth of ETH (~0.883 ETH) and repays his loan, closing out his position. Bob now has 2.117 ETH, valued at 635 DAI!

Bob started with 2 ETH, and ended up with 2.117 ETH. Not only did the value of ETH rise, by going LONG on ETH-DAI he gained 115 DAI of value instead of only 80. He increased his gains by ~44%!

To start, Bob had 2 ETH valued at 520 DAI

At the end, Bob had 2.117 ETH valued at 635 DAI → a 115 DAI gain

Without his position, he would have 2 ETH valued at 600 DAI → a 80 DAI gain

Bob gained an extra 35 DAI, or ~44%, value from his 1.5x long!

This makes sense for all parties involved: the lenders are happy because they profit on interest, Bob is happy because he can leverage his positions, and the exchanges are happy because they’re getting extra trading volume.

While the example above is illustrative of how margin trading works, it doesn’t quite speak to the potential power and risk involved.

Margin Trading Risks

In Part 1 we discussed how a loan could get liquidized if the collateral rate got too low. This still applies to Margin Trading, though there are some additional nuances.

When you open a margin position, your position will display a call price (commonly called a liquidation price in decentralized circles) that is based on the collateral rate. This is the price at which your collateral is no longer valued high enough to be sold to reliably pay back your loan.

In Bob’s example above, if the price of ETH dropped below 130 DAI, Bob’s collateral of 2 ETH could no longer be sold to pay his 260 DAI loan back. Recall that in practice, the collateral rate (and thus the call price) is actually set with a built in safety margin to reliably pay the loans back. So with a 15% margin of safety, at the price of 149.5 DAI, Bob’s 2 ETH collateral would be sold to close out his position. Upon this liquidation, Bob would still hold onto his 1 ETH (from the 260 DAI he borrowed and traded), but he would lose access to his initial 2 ETH collateral.

The liquidation process for these loans varies heavily from platform to platform, and is an area of much nuance. Some hold what are referred to as dutch auctions, where outside participants watch like eager vultures to jump in on a tasty liquidation opportunity (the safety margin results in a unique arbitrage opportunity), while others atomically sell and repay the loans with a built in liquidation fee. Regardless of the mechanism, liquidation is a big risk for margin traders — amplifying your losses can be a painful process.

In part 3 I’ll discuss some more of the pros and cons of these different liquidation methods, along with their reliant price oracles.

The Power of Trading on Margin

While a 44% gain for Bob was nice, margin trading is often performed at significantly more aggressive leverage rates. Being able to actualize 500%+ of your profits (or losses!) is extremely powerful.

Platforms that allow for borrowing and trading in a single interface (many centralized exchanges, and some recent decentralized projects) can achieve leverage ratios much greater than 1.5x. If BOTH your loan and your collateral all stay on the same platform, extremely leveraged positions become possible.

Let’s break down why a platform needs access to both your collateral AND your borrowed assets in order to achieve higher leverage rates.

On platforms that don’t have trading built in, you are allowed to freely take your borrowed assets off of their platform. If they don’t have any control over these borrowed assets, your collateral must be able to completely cover the loan at all times. Thus the maximum leverage ratio for these platforms can never be more than 2x (with safety margins typically only 1.5x is the max).

Note — there are some clever workarounds for this involving specialized tokens, but for simplicity we will forgo these for now

Note — there are some clever workarounds for this involving specialized tokens, but for simplicity we will forgo these for now On platforms with trading built in, your borrowed assets stay in their system and can effectively be counted as part of your collateral. These platforms know exactly what your total account value is at anytime (collateral + borrowed amount). As long as the platform can use all of that to cover the initial loan (with a safety margin), your loan and position can stay open. Using this they can achieve leverage ratios far greater than 2x.

In Bob’s example above, if he was able to open a 4x leveraged position he would have been able to borrow 1,560 DAI instead of 260 DAI with still just a 2 ETH deposit → yielding a final result of 294 DAI profit instead of 80 DAI, 368% additional value.

Greater leverage comes with greater risk: when you use your borrowed assets as additional collateral, liquidations happen quicker and are much more costly.

In Bob’s example of 1.5x leverage, he was using a platform that did not count his borrowed assets as collateral: even if ETH dropped and his collateral was liquidated, he would still at least keep his borrowed assets. However, in the 4x example, liquidation would wipe out everything Bob had: all of his borrowed assets and his collateral. Additionally, his call/liquidation price would have been ~224 instead of 149.5 — the price variance required to liquidate his position would be much less.

With great power comes great responsibility

Next up, Spot Trading, Price Oracles, and Liquidations

The only way that lending, borrowing, and margin trading can thrive is if you have the ability to trade borrowed assets on an open market. This is referred to as spot trading. In the context of DeFi, this is done on decentralized exchanges (DEX’s).

Part 3 is now live! https://medium.com/hydro-protocol/defi-101-part-3-spot-trading-price-oracles-and-liquidations-e215fc17b36d

Part 3 covers a few key details we’ve glossed over in parts 1 and 2 that are critical to upholding lending, borrowing, and margin trading.