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 button on the dYdX website.
You will need API credentials to deploy live algorithms. After you have an account, click on in the menu, click on , store them somewhere safe, and click on .
Paper Trading
Click 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 Type | Crypto Future |
|---|---|
| Market | ![]() |
| Limit | ![]() |
| Stop market | ![]() |
| Stop limit | ![]() |
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 |
|---|---|---|---|
TimeInForcetime_in_force | TimeInForce |
A TimeInForce instruction to apply to the order. The following instructions are supported:
| TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED |
GasLimitgas_limit | ulongint | The maximum amount of gas to use for the order. | 1_000_000 |
GoodTilBlockOffsetgood_til_block_offset | ulongint | The block height at which the order expires. | 20 |
PostOnlypost_only | 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. | ReduceOnlyreduce_only | bool?bool/NoneType | 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 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.
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.
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:
- Open the project you want to deploy.
- Click the
Deploy Live icon. - On the Deploy Live page, click the Brokerage field and then click from the drop-down menu.
- Enter your private key, wallet address, and sub-account number
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) In the Data Provider section, click and change the data provider or add additional providers.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
To generate your API credentials, see the Create an Account section in the Account Types documentation. Your account details are not saved on QuantConnect.
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.
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.
