---
title: "dYdX"
description: "Our dYdX integration lets you deploy live trading algorithms on our co-located servers that trade the capital you have in your dYdX account."
canonical: https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/brokerages/dydx
markdown: https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/brokerages/dydx.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/01%20Cloud%20Platform/10%20Live%20Trading/02%20Brokerages/16%20dYdX
modified: 2026-11-16
index: https://www.quantconnect.com/llms.txt
---

# dYdX

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Cloud Platform](https://www.quantconnect.com/docs/v2/cloud-platform.md) > [Live Trading](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading.md) > [Brokerages](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/brokerages.md) > dYdX

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

QuantConnect enables you to run your algorithms in live mode with real-time market data.

dYdX was founded by Antonio Juliano, a California-based entrepreneur, and former software engineer at Coinbase and Uber in July 2017 initially offering crypto margin trading, lending, and borrowing services. dYdX is not registered with any government authority as a broker or dealer, it is a decentralised, disintermediated and permissionless protocol, and is not available in the U.S. or to other Restricted Persons. All use of dYdX software is subject to the [dYdX Software Terms of Use](https://dydx.exchange/v4-terms).

To view the implementation of the dYdX integration, see the [Lean dYdX Repository](https://github.com/QuantConnect/Lean.Brokerages.dYdX). USE OF DYDX IS ENTIRELY AT YOUR OWN RISK ASSETS HELD ON DYDX ARE NOT GUARANTEED BY ANY GOVERNMENT AUTHORITY OR OTHER PARTY.

## Account Types

dYdX supports margin accounts. To set the account type in an algorithm, see the [dYdX model documentation](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md).

### Create an Account

Click **Sign In** button on the [dYdX website](https://dydx.trade/).

You will need API credentials to deploy live algorithms. After you have an account, click on **More > API Trading Keys** in the menu, click on **Generated New API Key**, store them somewhere safe, and click on **Authorize API Key**.

### Paper Trading

Click **Sign In** button on the [dYdX Testnet website](https://v4.testnet.dydx.exchange//). To create paper trading API keys, follow the process described above.

## Asset Classes

Our dYdX integration supports trading [Crypto futures](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/crypto-futures.md).

## Data Providers

The [QuantConnect data provider](https://www.quantconnect.com/docs/v2/cloud-platform/datasets/quantconnect/crypto.md) provides Crypto futures data during live trading.

## Orders

We model the dYdX API by supporting several order types, order properties, and order updates. When you deploy live algorithms, you can [place manual orders](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/algorithm-control.md#03-Place-Manual-Trades) through the IDE.

### Order Types

The following table describes the available order types for each asset class that our dYdX integration supports:

| Order Type | Crypto Future |
| --- | --- |
| [Market](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/market-orders.md) | ![green check](https://cdn.quantconnect.com/i/tu/check.png) |
| [Limit](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/limit-orders.md) | ![green check](https://cdn.quantconnect.com/i/tu/check.png) |
| [Stop market](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/stop-market-orders.md) | ![green check](https://cdn.quantconnect.com/i/tu/check.png) |
| [Stop limit](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/stop-limit-orders.md) | ![green check](https://cdn.quantconnect.com/i/tu/check.png) |

### Order Properties

We model custom order properties from the dYdX API. The following table describes the members of the `dYdXOrderProperties` object that you can set to customize order execution:

| Property | Data Type | Description | Default Value |
| --- | --- | --- | --- |
| `time_in_force` | `TimeInForce` | A [TimeInForce](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-properties.md#03-Time-In-Force) instruction to apply to the order. The following instructions are supported: `DAY` `GOOD_TIL_CANCELED`1 `good_til_date` | `TimeInForce.GOOD_TIL_CANCELED` |
| `gas_limit` | `int` | The maximum amount of gas to use for the order. | 1_000_000 |
| `good_til_block_offset` | `int` | The block height at which the order expires. | 20 |
| `IOC`2 | `bool` | Enforces that an order only be placed on the book as a maker order. Note this means that validators will cancel any newly placed post only orders that would cross with other maker. | `False` |
| `post_only`2 | `bool` | A flag to signal that the order must only add liquidity to the order book and not take liquidity from the order book. If part of the order results in taking liquidity rather than providing liquidity, the order is rejected without any part of it being filled. This order property is only available for limit orders. | `False` |
| `reduce_only` | `bool` | A flag to signal that the order must only reduce your current position size. For more information about this order property, see [Reduce-Only Order](https://help.dydx.trade/en/articles/166978-reduce-only-order) on the dYdX website. | `False` |

1 `GOOD_TIL_CANCELED` is not fully supported. These orders expire in 90 days.

2 You cannot set `post_only` when `IOC` is already set and vice-versa. Only one execution type can be active at a time.

### Updates

We model the dYdX API by not supporting order updates, but you can cancel an existing order and then create a new order with the desired arguments. For more information about this workaround, see the [Workaround for Brokerages That Don't Support Updates](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-management/order-tickets.md#workaround-for-brokerages-that-dont-support-updates).

## Fees

To view the dYdX trading fees, see the [Fees](https://dydx.trade/portfolio/fees) page on the dYdX website. To view how we model their fees, see [Fees](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md#06-Fees).

## Margin

We model [buying power](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md#07-Buying-Power) and [margin calls](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/margin-calls.md) to ensure your algorithm stays within the margin requirements.

## Slippage

Orders through dYdX do not experience slippage in backtests. In dYdX paper trading and live trading, your orders may experience slippage.

To view how we model dYdX slippage, see [Slippage](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md#05-Slippage).

## Fills

dYdX fills orders after they are added to the block on chain.

To view how we model dYdX order fills, see [Fills](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md#04-Fills).

## Settlements

Trades settle immediately after the transaction

To view how we model settlement for dYdX trades, see [Settlement](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md#08-Settlement).

## Security and Stability

Note the following security and stability aspects of our dYdX integration.

### Account Credentials

When you deploy live algorithms with dYdX, we don't save your credentials.

### API Outages

We call the dYdX API to place live trades. Sometimes the API may be down. Check the [dYdX status page](https://status.dydx.trade/) to see if the API is currently working.

## Deposits and Withdrawals

You can deposit and withdraw cash while you run an algorithm that's connected to a dYdX account. We sync the algorithm's cash holdings with the cash holdings in dYdX every day at 7:45 AM Eastern Time (ET).

## Demo Algorithm

The following algorithm demonstrates the functionality of the dYdX integration:

```python
# Demonstrate dYdX brokerage functionality with an EMA crossover strategy.
class DydxDemoAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)
        self.set_brokerage_model(BrokerageName.DYDX, AccountType.MARGIN)
        self._symbol = self.add_crypto_future("BTCUSD", Resolution.DAILY, Market.DYDX).symbol
        self._fast = self.ema(self._symbol, 10, Resolution.DAILY)
        self._slow = self.ema(self._symbol, 50, Resolution.DAILY)

    def on_data(self, slice: Slice) -> None:
        if not self._slow.is_ready:
            return
        if self._fast.current.value > self._slow.current.value and not self.portfolio.invested:
            self.set_holdings(self._symbol, 1)
        elif self._fast.current.value < self._slow.current.value and self.portfolio.invested:
            self.liquidate()
```

## Deploy Live Algorithms

dYdX is not a brokerage, it is a decentralised, disintermediated and permissionless protocol. However many parts of the QuantConnect platform include dYdX in a brokerage list for simple user-experience.

You must have an available [live trading node](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/resources.md#04-Live-Trading-Nodes) for each live trading algorithm you deploy.

Follow these steps to deploy a live algorithm:

1. [Open the project](https://www.quantconnect.com/docs/v2/cloud-platform/projects/getting-started.md#02-View-All-Projects) you want to deploy.
2. Click the ![Lightning icon](https://cdn.quantconnect.com/i/tu/deploy-live-icon.png) **Deploy Live** icon.
3. On the Deploy Live page, click the **Brokerage** field and then click **dYdX Exchange** from the drop-down menu.
4. Enter API your private key, wallet address, and sub-account number
   To generate your API credentials, see the **Create an Account** section in the [Account Types](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/brokerages/dydx.md#02-Account-Types) documentation. Your account details are not saved on QuantConnect.
5. In the **Region** section, click the [region](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/getting-started.md#07-Redundancy) where you want to run the algorithm.
6. Click the **Node** field and then click the live trading node that you want to use from the drop-down menu.
7. (Optional) In the **Data Provider** section, click **Show** and change the data provider or add additional providers.
8. (Optional) [Set up notifications](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/notifications.md).
9. Configure the **Automatically restart algorithm** setting.
   By enabling [automatic restarts](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/deployment.md#07-Automatic-Restarts), the algorithm will use best efforts to restart the algorithm if it fails due to a runtime error. This can help improve the algorithm's resilience to temporary outages such as a brokerage API disconnection.
10. Click **Deploy**.

The deployment process can take up to 5 minutes. When the algorithm deploys, the [live results page](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/results.md) displays. If you know your brokerage positions before you deployed, you can verify they have been loaded properly by checking your equity value in the runtime statistics, your cashbook holdings, and your position holdings.

Restarts, including automatic restarts and redeployments, don't save the state of your algorithm. To learn what a restart recovers and how to persist the rest, see [State Persistence](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/deployment.md#10-State-Persistence).

## Deployment Details

When you deploy a live algorithm with dYdX, the brokerage shares some details of the deployment, like the account it trades. Use them to tell concurrent deployments apart or to check that the algorithm connected to the account you expect. The details never include credentials.

The following table describes the deployment details that dYdX shares:

| Key | Description |
| --- | --- |
| `dydx-address` | The wallet address of the account that receives the orders. |
| `dydx-chain-id` | The dYdX chain of the account, which is `dydx-mainnet-1` for real money and `dydx-testnet-4` for the testnet. |
| `dydx-subaccount-number` | The subaccount of the wallet that receives the orders. |

The `deployment_details` property of your algorithm is a read-only dictionary of the details. LEAN populates it before it calls the `initialize` method, so you can read it anywhere in your algorithm.

```python
deployment_details = [f'{kvp.key}:{kvp.value}' for kvp in self.deployment_details]
self.log(f'deployment_details: {deployment_details}')
```

The [/live/read](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/live-algorithm-statistics.md) API endpoint also returns the details in its `deploymentDetails` field, so you can read them outside of the algorithm.
