Supported Models
dYdX
Introduction
This page explains the dYdXBrokerageModel, including the asset classes it supports, its default security-level models, and its default markets.
SetBrokerageModel(BrokerageName.dYdX, AccountType.Margin);
self.set_brokerage_model(BrokerageName.DYDX, AccountType.MARGIN)
For more information about this model, see the class referenceclass reference and implementation.
Asset Classes
The dYdXBrokerageModel supports trading Crypto futures.
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 | ![]() |
| Limit | ![]() |
| Stop market | ![]() |
| Stop limit | ![]() |
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 | |
|---|---|---|---|---|
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. |
public override void Initialize()
{
// Set the default order properties
DefaultOrderProperties = new dYdXOrderProperties
{
TimeInForce = TimeInForce.GoodTilCanceled,
ReduceOnly = false,
PostOnly = false
};
}
public override void OnData(Slice slice)
{
// Use default order order properties
LimitOrder(_symbol, quantity, limitPrice);
// Override the default order properties
LimitOrder(_symbol, quantity, limitPrice,
orderProperties: new dYdXOrderProperties
{
TimeInForce = TimeInForce.Day,
ReduceOnly = true,
PostOnly = false
});
LimitOrder(_symbol, quantity, limitPrice,
orderProperties: new dYdXOrderProperties
{
TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
ReduceOnly = false,
PostOnly = true
});
} 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.
Fills
The dYdXBrokerageModel uses the ImmediateFillModel.
Slippage
The dYdXBrokerageModel uses the NullSlippageModel.
Fees
The dYdXBrokerageModel uses the dYdXFeeModel with the default argument values that models the current dYdX fee schedule.
Settlement
The dYdXBrokerageModel uses the ImmediateSettlementModel.
Margin Interest Rate
The dYdXBrokerageModel uses the NullMarginInterestRateModel.
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.
