dYdX swap

dYdX swap execution changes token holdings or perpetual positions

dYdX swap trading in perpetual markets changes a collateral-backed position when a buy or sell order matches another order. A perpetual contract provides price exposure without delivering the underlying token. The order specifies a market, direction, quantity, and execution conditions; completed fills determine the actual position change. Account balances then reflect the trade alongside fees and other account activity. dYdX also offers spot trading, where buying and selling changes token holdings. The distinction matters before reviewing any quote: a perpetual order produces a derivatives position, while a spot exchange produces a different asset balance. Order status, execution records, and the resulting account state establish what completed.

Last updated ยท

Perpetual Orders and Spot Trades

dYdX supports exchange actions with different outputs, so the selected market determines what a successful trade adds to or removes from an account.

Perpetual Exposure

Perpetual trading uses an order book on dYdX Chain. Buy fills increase signed position size, and sell fills decrease it. A buy can therefore reduce a short position or increase a long position. The starting position determines which effect occurs. Contracts have no scheduled expiry, and holding a position involves continuing margin requirements and funding payments.

Spot Holdings

The Solana spot offering lets users buy and sell assets on that network through the trading interface. Spot trades execute on Solana and use a dedicated spot deposit address, separate from the perpetual trading address. Before funding a trade, confirm the selected product and deposit address. Before authorizing it, check the asset and quantity being spent and the token being received. After execution, verify the completed Solana transaction and resulting token holdings. A shared interface does not make the balances interchangeable or extend perpetual order controls to every spot trade. Someone seeking token ownership needs the spot output, while someone changing derivatives exposure needs the perpetual position record.


A Bounded Order With a Clear Stopping Point

Consider a reader preparing a perpetual limit order who wants to preserve the option to stop before any exposure changes. Readiness means the selected trading account shows usable collateral and a known starting position. An unfinished deposit does not establish either condition.

  • Confirm that the interface permits you to trade the selected perpetual market and the selected trading subaccount holds usable USDC collateral.
  • Compare the order direction and quantity with the existing position.
  • Choose a limit price and inspect the order's expiry and execution policy.
  • Check the projected margin requirement and any existing orders affecting the same market.
  • Leave the order unsigned if the preview does not match the intended position change.

Submitting the signed order commits the instruction to the execution process. A limit price constrains acceptable fills; it does not reserve a cancellation window. If sufficient matching liquidity exists within that limit, the order can fill before a cancellation reaches the relevant node.

If the order fills completely, its completed fills total the intended quantity. The resulting position should equal the starting position plus those signed fills. Then check remaining open orders separately to identify any instruction still capable of changing that position.

A partial fill requires a different response. If the reader no longer wants the remainder, cancellation targets only that remainder. Already completed fills remain effective. For short-term orders, a cancellation request alone does not guarantee the order has become unfillable; its block expiry supplies the firm boundary. After the chain passes that expiry block, recheck completed fills and the current position. If you still want additional execution, size a new order for only the quantity still needed.


Quote Estimates and Executable Prices

A perpetual order preview estimates execution from available market data, while actual fills depend on the matching liquidity available when the order reaches execution.

The best bid and ask describe the nearest prices on opposite sides of the book. They do not describe enough liquidity for every order size. An order consuming several price levels can have an average execution price different from the first visible price. Liquidity can also change between preview and execution.

A buy limit sets the highest acceptable purchase price; a sell limit sets the lowest acceptable sale price. Those boundaries apply to execution, not to whether the whole quantity fills. Market orders prioritize immediate matching and can leave an unfilled remainder under their execution policy.


Signed Orders and Validator Matching

dYdX Chain distributes order handling across network nodes, with block proposers selecting matches from their local order books for inclusion in blocks.

Each full node maintains an in-memory book. Messages can arrive in different orders, so nodes can briefly hold different views of available orders. A local match remains provisional until the chain commits the relevant execution. Nodes then reconcile their books with the committed block.

This architecture explains the cancellation boundary. A short-term cancellation travels through the network and may miss a proposer before matching occurs. A short-term order cannot fill at a block height greater than its good-til-block value. A cancellation acknowledgement and a settled fill therefore answer different questions.


What Does a Fill Actually Change?

A perpetual fill changes the signed quantity of a position and its associated quote balance, while fees also affect the account's financial result.

Position size records exposure in the selected market. A long position has positive signed size; a short has negative signed size. Buying adds to that signed quantity, and selling subtracts from it. An opposite-side fill can reduce exposure, close it, or continue through zero into the opposite direction.

The order amount describes the quantity to trade, rather than the final position size. That distinction matters whenever the account already holds a position. Multiple fills can complete one order at different prices, so the requested quantity and a single displayed price cannot fully describe its execution.

Account equity includes both the quote balance and the value of open positions. A quote-balance change therefore does not, by itself, measure profit or loss. The position value must enter the calculation too. Closing exposure realizes the trading result, but later fees, transfers, or funding entries can affect the account record.

Collateral Across Cross and Isolated Positions

Trading collateral supports perpetual exposure, and its allocation determines which positions share financial resources when prices move or an order changes account risk.

Shared Cross Margin

Cross-margin positions share collateral within their trading account. The protocol compares account equity with the combined margin requirements of those positions. Initial margin governs opening or increasing exposure; maintenance margin governs whether existing exposure remains sufficiently collateralized. A position's risk therefore depends partly on other positions sharing that collateral.

Allocated Isolated Margin

Isolated margin allocates collateral to a particular position through a separate subaccount. The amount assigned there determines its available backing. Pending isolated orders can also affect where collateral sits, so cancelling one order does not always return that collateral to the cross account when other orders remain.

Allocated Isolated Margin: Liquidation becomes possible when the relevant account falls below its maintenance requirement.; The protocol can close part or all of a position. An intended exit order does not suspend that process while it waits for execution.

View image file

Liquidation becomes possible when the relevant account falls below its maintenance requirement. The protocol can close part or all of a position. An intended exit order does not suspend that process while it waits for execution.

Order Timing and Unfilled Remainders

An order's execution policy determines whether unmatched quantity remains available for later trading or expires after an immediate attempt to match.

Immediate-or-cancel orders execute whatever quantity they can immediately and cancel the remainder. Resting limit orders can remain available until execution, cancellation, or expiry. Post-only instructions prevent immediate taker execution when the order would cross existing liquidity. A limit order without that restriction can execute immediately.

The protocol also distinguishes short-term orders from stateful orders. Short-term orders live in node memory before execution. Stateful orders have placement records on the chain and support longer-lived instructions. Their validity uses different expiry mechanisms, so a duration displayed in an interface should not become a universal execution-time promise.


Fees and Funding in Account Records

Trading fees attach to completed execution, while funding payments arise from holding perpetual exposure. Maker and taker treatment depends on how a fill interacts with book liquidity. Funding can increase or decrease the account balance, depending on position direction and the applicable rate. Spread and slippage affect execution price rather than necessarily appearing as separate charges. Reconciling a balance change therefore requires the actual fills, fees, and funding entries for the same period.

Conditional Orders and Position Reductions

Conditional orders activate when their configured price condition occurs, while reduce-only instructions constrain the position effect of an eligible order.

A stop or take-profit trigger activates an execution instruction. It does not establish the final fill price. A triggered limit order still needs matching liquidity within its limit, and a triggered market order depends on available liquidity. Triggering and closing are separate events.

Reduce-only prevents an order from increasing exposure or opening an opposite-side position. Eligibility and handling depend on the order type and execution policy. The documented front-end implementation requires immediate-or-cancel execution for reduce-only orders; a resting limit order should not automatically inherit that protection. Existing exit instructions also need attention after another trade changes position size.


Fill Records and Balance Reconciliation

Execution records explain completed trading activity more precisely than an order submission message, because they identify the quantity and price the account actually traded.

Order records describe instructions and their status. Fill records describe executions. Position records describe remaining exposure, while transfer and funding records explain other balance movements. Match the account and subaccount across those records, and match the market for orders, fills, positions, and funding. Transfers affect the subaccount balance without belonging to a particular perpetual market.

The Indexer supplies account and market data through APIs and streaming updates. A display can reflect information received at different moments, especially while execution continues. Comparing a fresh position with an older balance snapshot can create an apparent discrepancy. The useful reconciliation uses records covering the same account and period, including partial fills and other activity.


Trading Access and Authorization

Order authorization controls who can instruct the trading account, while product access determines which exchange actions the selected interface permits.

Programmatic trading can use API Trading Keys without handing over the main wallet's seed phrase. The documented front-end keys permit trading cross markets in the owner's cross-margin account. They cannot trade isolated markets, withdraw funds, or transfer assets. They can nevertheless use the account's available cross margin, so withdrawal restrictions do not prevent trading losses.

Spot availability also does not establish perpetual eligibility. Product restrictions apply separately. After any authorized perpetual execution, the remaining position continues to face price movement, funding, and margin requirements until subsequent activity closes it. A completed order ends that instruction, not the obligations of the exposure it created.

dYdX swap: common questions

Does Trading a dYdX Perpetual Buy the DYDX Token?

Trading a perpetual creates or changes exposure in the selected contract; it does not automatically buy DYDX tokens. The dYdX platform name and the DYDX token identify different things. Token ownership requires a transaction whose actual output is that token, rather than a perpetual position.

Why Can the Quote Balance Be Negative While Account Equity Remains Positive?

The quote balance is only one component of perpetual account equity. Equity also includes the signed value of open positions, so a negative quote balance can coexist with positive total equity. Assessing margin requires the combined account calculation rather than reading the quote balance as an isolated wallet holding.

How Can a market's Required Initial Margin Increase Without a New Trade?

The effective initial margin fraction can rise as the market's open notional increases through its configured scaling range. Open notional combines open interest with the oracle price. That mechanism can change collateral requirements even when an individual account has not submitted another order; the market's configured thresholds determine the applicable range.

Is There a Trading Fee for Cancelling an Unfilled Order?

Under the documented default fee model, cancelling an unfilled perpetual order does not incur a trading fee. Fees apply to completed fills. If an order partially executed before cancellation, those fills retain their applicable charges, so a cancelled status does not establish that the entire instruction incurred no cost.

Will Disconnecting a Wallet Close an Existing Position?

Disconnecting a wallet from an interface does not close an existing perpetual position. The position belongs to the trading account's on-chain state, which persists independently of that browser connection. Closing exposure requires an executed position-reducing action or a protocol event, and existing orders can remain relevant after disconnection.