---
title: "dYdX"
description: "This page explains the default security-level models and markets of the dYdXBrokerageModel."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/dydx.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/24%20Reality%20Modeling/05%20Brokerages/02%20Supported%20Models/16%20dYdX
modified: 2026-11-15
index: https://www.quantconnect.com/llms.txt
---

# dYdX

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Reality Modeling > Brokerages > [Supported Models](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md) > dYdX

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

## Introduction

This page explains the `dYdXBrokerageModel`, including the asset classes it supports, its default [security-level models](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/key-concepts.md#02-Security-Level-Models), and its default markets.

```python
self.set_brokerage_model(BrokerageName.DYDX, AccountType.MARGIN)
```

For more information about this model, see the [class reference](https://www.lean.io/docs/v2/lean-engine/class-reference/py/QuantConnect/Brokerages/dYdXBrokerageModel/) and [implementation](https://github.com/QuantConnect/Lean/blob/master/Common/Brokerages/dYdXBrokerageModel.cs).

## Asset Classes

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

## Orders

The `dYdXBrokerageModel` supports several order types, order properties, and order updates.

### Order Types

The following table describes the available order types for each asset class that the `dYdXBrokerageModel` 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

The `dYdXBrokerageModel` supports custom order properties. 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.

```python
def initialize(self) -> None:
    # Set the default order properties
    self.default_order_properties = dYdXOrderProperties()
    self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    self.default_order_properties.reduce_only = False
    self.default_order_properties.post_only = False

def on_data(self, slice: Slice) -> None:
    # Use default order order properties
    self.limit_order(self._symbol, quantity, limit_price)

    # Override the default order properties
    order_properties = dYdXOrderProperties()
    order_properties.time_in_force = TimeInForce.DAY
    order_properties.reduce_only = True
    order_properties.post_only = False
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

    order_properties.time_in_force = TimeInForce.good_til_date(datetime(year, month, day))
    order_properties.reduce_only = False
    order_properties.post_only = True
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
```

### Updates

The `dYdXBrokerageModel` doesn't support 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).

## Fills

The `dYdXBrokerageModel` uses the [ImmediateFillModel](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/trade-fills/supported-models/immediate-model.md).

## Slippage

The `dYdXBrokerageModel` uses the [NullSlippageModel](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/slippage/supported-models.md#02-Null-Model).

## Fees

The `dYdXBrokerageModel` uses the [dYdXFeeModel](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/transaction-fees/supported-models.md#12-dYdX-Model) with the default argument values that models the current dYdX fee schedule.

## Buying Power

The `dYdXBrokerageModel` uses the `SecurityMarginModel` and allows 3.3x leverage.

## Settlement

The `dYdXBrokerageModel` uses the [ImmediateSettlementModel](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/settlement/supported-models.md#02-Immediate-Model).

## Margin Interest Rate

The `dYdXBrokerageModel` uses the [dYdXFutureMarginInterestRateModel](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/margin-interest-rate/supported-models.md#06-dYdX-Futures-Model).

## Default Markets

The default market of the `dYdXBrokerageModel` is `Market.DYDX`.

## Account Currency

The `dYdXBrokerageModel` doesn't set a default currency. To change the algorithm's currency from USD to a different currency, see [Set Account Currency](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#03-Set-Account-Currency).
