Published in


Getting Started With dYdX — Margin Trading (Part 1)

dYdX Layer 1 is winding down on November 1, 2021 at 18:00 UTC.

Users will still be able to withdraw at any time, but deposits, trades, and borrows will be disabled. Learn more in the blog post.

dYdX is a powerful open trading platform that currently supports three features:

  • Lending
  • Borrowing
  • Margin trading

This guide will walk you through how to open and manage a margin position on dYdX. If you are a new user looking to make your first deposit and automatically earn interest on your funds, you might want to first check out our guide to lending.

dYdX currently offers three trading pairs: ETH-DAI, ETH-USDC, USDC-DAI. If you would like to margin trade other assets or do not want to trade on dYdX, you can also borrow assets from dYdX to margin trade somewhere else. Check out our guide to borrowing on dYdX.

Different trading modes

On the trade page, you’ll see two tabs underneath your account balances on the left that allow you to select your trading mode: “Margin” and “Trade”. You can margin trade and ultimately get exactly the same exposure using either trading mode, but the underlying mechanics of trading in each mode are slightly different.

Let’s take a look at a quick summary of the pros and cons of each mode:

“Margin” —

Pros —

  • Simple and more intuitive.
  • Calculations like “Leverage”, “PNL”, and “Liquidation Price” are done for you.
  • Able to open positions at a specific leverage.
  • Losses are capped to the size of your margin deposit.
  • Multiple independent positions can be opened at once.


  • Margin deposit assets are fixed and can not be changed at this time.
  • Once a position is opened, it can not be adjusted, so collateral can not be added or removed (less flexibility).
  • Stop orders can only fully close a position.

“Trade” —


  • Any asset can be used as collateral, including multiple assets at the same time.
  • Different aspects such as position size and leverage are more easily adjusted. This may be important for things like avoiding liquidation.
  • Limit orders are available.
  • Finer control of stop order amounts.


  • Values like “Leverage”, “PNL”, and “Liquidation Price” are not displayed due to the complexity of multiple collateral assets.
  • Leverage must be implied based on the collateralization ratio.
  • Entire account acts as a single “position”, so during liquidations/expirations your entire account is affected.

For this guide, we will be focusing on how to use the “Margin” tab to trade. Let’s dive into how to open your first margin position on dYdX.

Opening a position

While the most powerful way to trade on dYdX is on the “Trade” tab, the “Margin” tab offers a more intuitive experience for users to open margin positions on dYdX. Let’s take a look at each field when the “Margin” tab is selected:

Trading on the “Margin” tab

Position Side (Long/Short) — Selecting your position side is the first step to opening any position. Long positions gain value if the base asset increases in value, short positions gain value if the base asset decreases in value.

Position Size — This is your total position size, or the total amount you are long/short.

Leverage — Leverage controls how much of your position is borrowed. The higher the leverage is, the smaller your margin deposit is and the more funds you borrow to open your position. Borrowing more funds is riskier, amplifying both your gains and losses, while also giving your position a riskier liquidation price.

To open your position, you’ll need to have enough funds in your main account to cover the margin deposit. As an example, let’s say you want to open a 5X LONG position on ETH-DAI with a position size of 1.0000 ETH. The margin deposit for this position is 0.2 ETH, so you’ll need to have at least 0.2 ETH in your account to open this position.

Once you have selected the parameters for your position, more fields will appear to provide additional details about your position. All the fields here are important, but you’ll want to pay special attention to these:

Margin Deposit/Trade Amount — When placing trades on the “Margin” tab, there are two parts to your position: the margin deposit and the borrow/trade amount. The margin deposit is your own personal stake (equity) in the position. The borrow/trade amount is the remaining portion of your position, consisting of borrowed funds.

When opening a position on the “Margin” tab, you can lose no more than your margin deposit amount.

Liquidation Price — When margin trading, you are borrowing funds to gain additional exposure to the market than you normally would be able to. Borrowing funds like this comes with additional risk compared to trading with your own funds.

Each of your positions have a certain collateral (positive balances) to debt (negative balances) ratio. This ratio is called collateralization and you can read more about it in our guide to borrowing. If your collateralization ratio gets dangerously low and crosses dYdX’s liquidation threshold, your position will get liquidated. Upon liquidation, collateral in your position will be sold until all your negative balances are zero, and a 5% liquidation fee will be taken.

Liquidations on dYdX are open source and transparent, meaning anyone can participate in liquidations to earn the liquidation fee. You can learn more about running your own liquidator bot here.

Interest Rate — This is the average interest rate your position will pay/earn depending on the market rates: you will earn interest on the collateral locked in your position, and pay interest on the amount borrowed. Sometimes you may be earning more than you pay, or vice versa. A negative interest rate means you’ll be paying interest, and a positive interest rate means you’ll be earning interest. These interest rates change based on supply and demand, so you can always track each individual assets interest rate on the markets page.

Fee/Fee Amount — You can read about dYdX’s fee structure here. Fees enable dYdX to continue building a powerful and open product for our users, while also helping to cover gas costs. On dYdX, all trades are resolved on-chain, and dYdX covers 100% of the gas fees for each trade.

All trades on dYdX are resolved on-chain, and dYdX covers 100% of the gas fees for each trade.

Expiration — For US persons, regulations require all margin trades to have a 28 day expiration. If this applies to you, make sure you close your position before your position expires. During expirations, your negative balances get zero-ed out in a similar way to liquidations, but the fee is lower (1% — 5% vs. 5%). You can learn more about expirations here.

Once you have verified all the fields related to the position you are opening, simply click the “Open Position” button, sign the order that pops up in your wallet (completely free and does not require gas), and you should see a notification telling you that your position has successfully been filled.

Congratulations! You have opened your first position on dYdX. Once the fill transaction for your position is mined and your balances update, the spinner on your position will disappear and you’ll see live numbers appear in your position.

Understanding your open positions

You can view your open positions on the “Positions” tab on the bottom part of the trade page. Click on any position to expand the row and see more information about the position.

Click a position to expand the row and show more details

After your position has been opened, you’ll be able to view details about your position like:

PNL — This is the total profit/loss you would earn by closing the position. The PNL value includes things like fees, so your PNL will usually be slightly negative when first opened to account for the fee paid to open the position.

On dYdX, PNL is calculated based on value, not amount. For example, let’s say you open a long on ETH-DAI with 1 ETH as your margin deposit, and when you close your position, you end up with exactly 2 ETH. Let’s also assume the price of ETH increases from 100 DAI to 200 DAI between the time you opened and closed the position. In this case, your PNL will actually be 300% since the value of the ETH was 100 DAI when the position was opened, and 400 DAI when the position was closed.

Stop / Index — dYdX supports stop loss orders on your positions. A stop loss order will automatically close your position at a certain price if the market prices move unfavorably for your position. This allows you to prevent further losses without having to be present to close your position manually.

To place a stop order, hover over the “Stop / Index” column for your position to reveal the “Add Stop” button. Click this button to open a modal that will allow you add, edit, or cancel the stop order associated with your position. Each position can only have one stop order at any time, and the stop order will always fully close your position.

The index price is the on-chain oracle price, and is slightly different than the mid market price you may see in the orderbook or near the price chart. All liquidations and stop order triggers are based off of the index price. The index price is aggregated from multiple different sources, which protects you from things like flash crashes on a single exchange.

Closing your position

To close a position, hover over the position you would like to close. you’ll see the “Close” button appear on the right side of the position row. Clicking this button will open up a modal, where you can specify exactly how much of your position you would like to close. Clicking the “MAX” button will pre-fill the amount to fully close your position.

Once you have entered the amount you want to close, simply click “Close position”, sign the order (signing costs no gas, same as when you open a position), and you should see a notification indicating the trade to close your position has been filled! Once the transaction gets mined, you’ll see your position disappear from the “Positions” section.

When you close your position manually, the remaining equity in the position is automatically transferred to your main account. However, if your position is closed via liquidation, expiration, or stop loss order, you’ll need to withdraw your funds from the position.

Some accounts will need to be manually withdrawn

To do this, hover over the liquidated/expired/closed position and click the “Withdraw” button on the right side of the position row. you’ll get prompted to send a transaction that will transfer all the remaining funds in the position to your main account.

Hover over the position to reveal the “Withdraw” button

Awesome job making it this far! You are now well versed in opening and managing positions on the “Margin” tab. In the next guide, we will take a look at how trading works on the more powerful and versatile “Trade” tab.

If you have any questions, click “Help” in the header and check out the help center or chat with a dYdX team member. You can also always reach out on the dYdX Telegram group.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store