Brokerages

dYdX

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 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.

To view the implementation of the dYdX brokerage integration, see the Lean.Brokerages.dYdX repository.

Account Types

dYdX supports margin accounts. To set the account type in an algorithm, see the dYdX brokerage model documentation.

Create an Account

Click Sign In button on the dYdX website.

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. To create paper trading API keys, follow the process described above.

Asset Classes

Our dYdX integration supports trading Crypto futures.

Data Providers

The QuantConnect data provider 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 through the IDE.

Order Types

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

Order TypeCrypto Future
Marketgreen check
Limitgreen check
Stop marketgreen check
Stop limitgreen check

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:

PropertyData TypeDescriptionDefault Value
TimeInForcetime_in_forceTimeInForce A TimeInForce instruction to apply to the order. The following instructions are supported:
  • DayDAY
  • GoodTilCanceledGOOD_TIL_CANCELED
  • GoodTilDategood_til_date
TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED
GasLimitgas_limitulongintThe maximum amount of gas to use for the order.1_000_000
GoodTilBlockOffsetgood_til_block_offsetulongintThe block height at which the order expires.20
PostOnlypost_onlyboolA 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.
ReduceOnlyreduce_onlybool?bool/NoneTypeA flag to signal that the order must only reduce your current position size. For more information about this order property, see Reduce-Only Order on the dYdX website.

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.

Fees

To view the dYdX trading fees, see the Fees page on the dYdX website. To view how we model their fees, see Fees.

Margin

We model buying power and margin calls 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.

Fills

We fill market orders immediately and completely in backtests. In dYdX paper trading and live trading, if the quantity of your market orders exceeds the quantity available at the top of the order book, your orders are filled according to what is available in the order book.

To view how we model dYdX order fills, see Fills.

Settlements

Trades settle immediately after the transaction

To view how we model settlement for dYdX trades, see 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 brokerage account credentials.

API Outages

We call the dYdX API to place live trades. Sometimes the API may be down. Check the dYdX status page to see if the API is currently working.

Deposits and Withdrawals

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

Demo Algorithm

The following algorithm demonstrates the functionality of the dYdX brokerage:

Deploy Live Algorithms

You must have an available live trading node for each live trading algorithm you deploy.

Follow these steps to deploy a live algorithm:

  1. Open the project you want to deploy.
  2. Click the Lightning icon 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 your private key, wallet address, and sub-account number
  5. To generate your API credentials, see the Create an Account section in the Account Types documentation. Your account details are not saved on QuantConnect.

  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.
  9. Configure the Automatically restart algorithm setting.
  10. By enabling 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.

  11. Click Deploy.

The deployment process can take up to 5 minutes. When the algorithm deploys, the live results page 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.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: