Node Orders
dYdX node order helpers.
Orders
dataclass
Bases: PlaceOrder, CancelOrder, BatchCancelOrders
Composed order helper surface.
Source code in pkg/src/dydx/node/orders/__init__.py
context
instance-attribute
Shared node context used for wallet and chain access.
tx
instance-attribute
Transaction helper used for signing and broadcasting.
dYdX order placement helper.
PlaceOrder
dataclass
Order placement endpoint.
Source code in pkg/src/dydx/node/orders/place_order.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
context
instance-attribute
Shared node context used for wallet and chain access.
tx
instance-attribute
Transaction helper used for signing and broadcasting.
build_order(*, market, order, subaccount=0, good_til_block=None, good_til_block_time=None)
async
Build a protocol order without broadcasting it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
market
|
Market | PerpetualMarket
|
Market metadata used to convert price and size into protocol subticks and quantums. |
required |
order
|
OrderParams
|
Ergonomic order parameters for the CLOB message. |
required |
subaccount
|
int
|
dYdX subaccount number owned by the wallet. |
0
|
good_til_block
|
int | None
|
Optional explicit short-term expiry block. |
None
|
good_til_block_time
|
int | None
|
Optional explicit stateful expiry timestamp. |
None
|
Returns:
| Type | Description |
|---|---|
Order
|
dYdX protocol order message. |
Source code in pkg/src/dydx/node/orders/place_order.py
default_good_til(flags)
async
Resolve default order expiry for an order flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags
|
Flags
|
Order flag determining whether expiry is block-based or timestamp-based. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Pair of |
int | None
|
the pair is populated depending on the order type. |
Raises:
| Type | Description |
|---|---|
BadRequest
|
Raised when latest block metadata needed for expiry is unavailable. |
Source code in pkg/src/dydx/node/orders/place_order.py
place_order(market, *, order, subaccount=0, mode=tx_proto.BroadcastMode(2), simulate=False)
async
Build, sign, and broadcast a long-term dYdX order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
market
|
Market | PerpetualMarket
|
Market metadata used to convert price and size into protocol
subticks and quantums. Accepts either a prepared |
required |
order
|
OrderParams
|
Order parameters for the CLOB message. dYdX only allows batched placement for stateful long-term or conditional orders. |
required |
subaccount
|
int
|
dYdX subaccount number owned by the wallet. |
0
|
mode
|
BroadcastMode
|
Cosmos broadcast mode. |
BroadcastMode(2)
|
simulate
|
bool
|
Whether to simulate the transaction instead of broadcasting it. |
False
|
Returns:
| Type | Description |
|---|---|
PlacedOrder
|
The broadcast response and protocol order that was signed. |
Source code in pkg/src/dydx/node/orders/place_order.py
place_orders(orders, *, mode=tx_proto.BroadcastMode(2), simulate=False)
async
Build, sign, and broadcast multiple stateful dYdX orders.
dYdX rejects transactions containing multiple short-term MsgPlaceOrder
messages. This helper only accepts long-term or conditional orders, which
are stateful and can be submitted together in one transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
Sequence[OrderPlacement]
|
Order placement items. Each item carries its market metadata, order parameters, and optional subaccount number. |
required |
mode
|
BroadcastMode
|
Cosmos broadcast mode. |
BroadcastMode(2)
|
simulate
|
bool
|
Whether to simulate the transaction before broadcasting. |
False
|
Returns:
| Type | Description |
|---|---|
PlacedOrders
|
The broadcast response and protocol orders that were signed. |
Raises:
| Type | Description |
|---|---|
BadRequest
|
Raised when no orders are supplied or any order is short-term. |
Source code in pkg/src/dydx/node/orders/place_order.py
PlacedOrder
dataclass
Result of a placed order.
Source code in pkg/src/dydx/node/orders/place_order.py
order
instance-attribute
Protocol order message that was signed and submitted.
tx
instance-attribute
Transaction broadcast response returned by the chain.
PlacedOrders
dataclass
Result of a multi-order placement transaction.
Source code in pkg/src/dydx/node/orders/place_order.py
orders
instance-attribute
Protocol order messages that were signed and submitted.
tx
instance-attribute
Transaction broadcast response returned by the chain.
parse_condition_type(condition_type)
Convert condition type into the protocol enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | None
|
Ergonomic conditional order type. |
required |
Returns:
| Type | Description |
|---|---|
OrderConditionType
|
dYdX protocol order condition enum. |
Source code in pkg/src/dydx/node/orders/place_order.py
parse_flags(flags)
Convert order flags into protocol flag bits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags
|
Flags
|
Ergonomic order flag value. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Integer order flag expected by dYdX CLOB order IDs. |
Source code in pkg/src/dydx/node/orders/place_order.py
parse_side(side)
Convert order side into the protocol enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
Side
|
Ergonomic order side value. |
required |
Returns:
| Type | Description |
|---|---|
OrderSide
|
dYdX protocol order side enum. |
Source code in pkg/src/dydx/node/orders/place_order.py
parse_time_in_force(time_in_force)
Convert time in force into the protocol enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_in_force
|
TimeInForce | None
|
Ergonomic time-in-force value. |
required |
Returns:
| Type | Description |
|---|---|
OrderTimeInForce
|
dYdX protocol time-in-force enum. |
Source code in pkg/src/dydx/node/orders/place_order.py
random_client_id()
Generate a dYdX client order ID.
Returns:
| Type | Description |
|---|---|
int
|
Random client order ID in the dYdX accepted range. |
dYdX order cancellation helper.
CancelOrder
dataclass
Order cancellation endpoint.
Source code in pkg/src/dydx/node/orders/cancel_order.py
context
instance-attribute
Shared node context used for wallet and chain access.
tx
instance-attribute
Transaction helper used for signing and broadcasting.
cancel_order(order_id, *, good_til_block=None, good_til_block_time=None, mode=tx_proto.BroadcastMode.SYNC, simulate=False)
async
Build, sign, and broadcast an order cancellation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
OrderId
|
Protocol order identifier to cancel. |
required |
good_til_block
|
int | None
|
Optional short-term cancellation expiry block. Loaded from the latest chain block when omitted for short-term orders. |
None
|
good_til_block_time
|
int | None
|
Optional stateful cancellation expiry timestamp. Loaded from the latest chain block time when omitted for stateful orders. |
None
|
mode
|
BroadcastMode
|
Cosmos broadcast mode. |
SYNC
|
simulate
|
bool
|
Whether to simulate the transaction before broadcasting. |
False
|
Returns:
| Type | Description |
|---|---|
BroadcastTxResponse
|
Cosmos broadcast response. |
Raises:
| Type | Description |
|---|---|
BadRequest
|
Raised when latest block metadata needed for default expiry is unavailable. |
Source code in pkg/src/dydx/node/orders/cancel_order.py
dYdX batch order cancellation helper.
BatchCancelOrders
dataclass
Batch order cancellation endpoint.
Source code in pkg/src/dydx/node/orders/batch_cancel_orders.py
context
instance-attribute
Shared node context used for wallet and chain access.
tx
instance-attribute
Transaction helper used for signing and broadcasting.
batch_cancel_orders(order_ids, *, good_til_block=None, mode=tx_proto.BroadcastMode(2), simulate=False)
async
Build, sign, and broadcast short-term order cancellations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_ids
|
Sequence[OrderId]
|
Short-term order identifiers to cancel. All must belong to the same subaccount. |
required |
good_til_block
|
int | None
|
Optional cancellation expiry block. Loaded from the latest chain block when omitted. |
None
|
mode
|
BroadcastMode
|
Cosmos broadcast mode. |
BroadcastMode(2)
|
simulate
|
bool
|
Whether to simulate the transaction before broadcasting. |
False
|
Returns:
| Type | Description |
|---|---|
BroadcastTxResponse
|
Cosmos broadcast response. |
Raises:
| Type | Description |
|---|---|
BadRequest
|
Raised when no orders are provided, orders are not short-term, orders belong to different subaccounts, or latest block metadata is unavailable. |
Source code in pkg/src/dydx/node/orders/batch_cancel_orders.py
Typed dYdX order parameters.
OrderParams
Bases: TypedDict
Ergonomic dYdX order parameters.
Source code in pkg/src/dydx/node/orders/types.py
client_id
instance-attribute
Optional client-generated order ID.
client_metadata
instance-attribute
Optional client metadata integer included in the protocol order.
condition_type
instance-attribute
Optional conditional order trigger type.
conditional_order_trigger_subticks
instance-attribute
Optional conditional trigger price expressed as protocol subticks.
flags
instance-attribute
dYdX order flag category.
good_til_block
instance-attribute
Optional short-term expiry block.
good_til_block_time
instance-attribute
Optional stateful expiry timestamp.
price
instance-attribute
Human-readable order price.
reduce_only
instance-attribute
Whether the order may only reduce exposure.
side
instance-attribute
Order side.
size
instance-attribute
Human-readable base asset size.
time_in_force
instance-attribute
Optional dYdX time-in-force behavior.
OrderPlacement
Bases: TypedDict
One dYdX order placement inside a multi-order transaction.
Source code in pkg/src/dydx/node/orders/types.py
market
instance-attribute
Market metadata used to convert price and size into protocol values.
order
instance-attribute
Order parameters for the CLOB message.
subaccount
instance-attribute
Optional dYdX subaccount number under the signing wallet.