dYdX

dYdX perpetual fills change position size and quote balance

Updated:

dYdX perpetual trade checks match executed fills to changes in the same subaccount's position and balances. Record the starting exposure and margin, then compare fill quantity, execution price, and fees with the resulting account state. Order status alone cannot explain the full change in equity.

From the selected market to the recorded position

An opening or increasing perpetual trade requires sufficient margin in the selected subaccount before execution.

Starting exposure and margin

Record the market, subaccount identifier, existing position direction and size, and available collateral before submitting an order. Keep that baseline alongside the requested side, quantity, and execution settings. Close-only mode on frontends operated by dYdX Operations Services Ltd. permits reductions but prevents opening new positions. Close-only access remains an opening restriction even when the account has sufficient margin.

Execution and account result

Follow the submitted order into its fill history, retaining actual quantities, execution prices, and charged fees. Then compare the resulting position with the recorded baseline for the same market and subaccount. Use the executed quantity to explain the adjustment; an unfilled remainder has made no position change. The account snapshot must cover the fill's block before it can corroborate that outcome.

Fill quantity, position size, and trade value

Executed quantity measures the trade adjustment, while position size describes the exposure that remains after all relevant activity. A buy adds to signed position size; a sell subtracts from it. Long positions have positive size, and short positions have negative size. An opposite-side fill may reduce exposure, close it, or reverse direction if it exceeds the existing position and no reduce-only constraint prevents that change.

Trade value and base quantity use different units. Fill value is execution price multiplied by filled size. When an order has several fills, its average execution price is the sum of those fill values divided by total filled quantity. A simple average of prices does not account for differences in fill size. Neither the original requested amount nor the best price shown before execution replaces those records.

Account scope and comparable snapshots

Comparable records must describe the same account scope and include the activity between the chosen snapshots. A subaccount is identified by the account address and its number. Filters for a different market, product type, or interval can omit relevant fills. The indexer supports separate retrieval of orders, fills, positions, and transfers, so an account total should not silently stand in for a single position.

Account scope and comparable snapshots (dYdX) - illustration
Account scope and comparable snapshots - diagram

View full-size image

The dYdX web frontend holds isolated positions in separate child subaccounts. Its parent-subaccount APIs can aggregate the parent and associated children. A consolidated portfolio view can therefore show more activity than a query against one subaccount. Keep that aggregation choice consistent across the comparison. The protocol permits multiple cross-marginable positions in a subaccount; the frontend's isolated-position arrangement does not impose a universal protocol restriction.

Record the retrieval time for each account snapshot. Its processing height determines which committed activity it can include.

Fees and balance changes around a fill

Trading fees, funding, and collateral movements can change balances within the same interval as a position adjustment.

Execution fees

The liquidity role of a fill identifies whether it added liquidity as a maker or removed liquidity as a taker. That role and the applicable fee schedule determine the base trading charge. Fee tiers, eligible discounts, and maker rebates can alter the amount; governance can change the schedule. A maker rebate has the opposite accounting sign from a fee charge. Staking discounts apply to eligible positive charges, not maker rebates. Use the fee recorded for the execution when reconciling historical activity. A later fee tier is not evidence of the charge that applied earlier.

Quote balance and equity

Quote balance is an accounting balance, and it can be negative while the account still has positive equity. For these perpetual subaccounts, equity combines the USDC quote balance with signed positions valued at oracle prices. A fill changes quote balance and signed exposure together, so its notional value alone cannot explain the equity change. Free collateral equals equity minus the total initial margin requirement. Oracle price changes can move equity and available margin without a fresh execution. Compare the same measures at both observation points.

Funding and collateral movements

Funding payments credit or debit the account while positions are held. Deposits, withdrawals, and transfers also change its balance. For isolated orders in the web frontend, collateral may move into a child subaccount before the order fills. That movement can explain a lower cross-account balance without proving that an execution occurred.

A fill ahead of the displayed account snapshot

A fill recorded beyond the snapshot's processed block height cannot be reconciled against that older snapshot. The indexer reads chain data and serves it through a separate data service. Its order updates may also contain off-chain information. An order notification and a committed fill therefore describe different states of the trading process.

Compare the fill's block height with the account response's latest processed block height, then obtain a fresh account response once processing covers that fill. Refreshing or reconnecting the display does not reverse an execution. If the snapshot already includes the relevant block, inspect the complete interval for other fills, transfers, or protocol events before attributing a size difference to delayed data.

Preserve unresolved records before submitting another trade; another fill creates an additional account change.

How do order settings affect the quantity that actually trades?

Order settings determine execution timing, price constraints, and whether unfilled quantity can remain available for matching. An immediate-or-cancel limit order combines a price boundary with cancellation of its unfilled remainder.

Order setting Execution condition Unfilled quantity Account interpretation
Market order, frontend default Matches available opposing liquidity immediately Cancelled after the immediate attempt Executed quantity determines this order's position adjustment
Good-til-date limit order Specified price or better Can rest until filled, cancelled, or expired Compare filled quantity with remaining open quantity
Post-only limit order Must enter the book without immediately matching A crossing placement is cancelled A cancelled crossing placement contributes no executed quantity
Immediate-or-cancel limit order Immediate matching within the limit price The unfilled part is cancelled A partial fill remains an executed adjustment
Reduce-only immediate-or-cancel order Execution may only reduce existing exposure The unfilled part is cancelled These fills cannot increase or reverse exposure

The dYdX frontend requires immediate-or-cancel behaviour for its reduce-only setting. The order side must reduce the position that exists when execution is attempted. A smaller executed amount can leave residual exposure even when the order itself has ended.

Protocol events without a fresh manual order

Liquidations and automatic deleveraging can produce position changes without a new manual order from the account owner. The fill type identifies the event category, which helps explain why an order-only search misses activity. LIQUIDATED denotes the subaccount's own position being liquidated; LIQUIDATION denotes a maker fill against another trader's liquidation. Treating those labels as interchangeable reverses whose position triggered the event. A liquidation can partially or fully close a position. Match its executed quantity to the account change without treating it as a user-selected order.

Funding records explain balance adjustments from holding exposure; they do not supply missing executed quantity. If every applicable event is included and the positions still disagree, the comparison remains unresolved.

dYdX: the short answers

How do I avoid counting the same fill twice?

Use the fill identifier to recognise duplicate records when combining overlapping responses. A repeated identifier represents the same fill and should contribute its size and fee once. Different fill identifiers can represent separate executions even when their market, price, and displayed time match. Similar appearance alone is not a reason to discard a trade.

Which timestamp format should I use for a trade-history comparison?

Use ISO 8601 timestamps in Coordinated Universal Time (UTC) when comparing indexer records. Keep any time-zone offset explicit when converting a screenshot or downloaded record that uses local time. Aligning the time basis prevents an apparent missing fill caused by comparing different clock representations of the same execution.

Is a missing order ID proof that a dYdX fill is invalid?

A missing order ID alone does not establish that a fill is invalid. The fill response permits that field to be absent, and fill types distinguish ordinary trading from protocol-generated events. Retain the fill identifier, subaccount, market, execution quantity, and event type when interpreting a record without an associated order.

Does cancelling an unfilled order create a trading fee?

Under the default dYdX Chain fee rules, cancelling unfilled quantity does not incur a trading fee. Fees apply to executed fills. If an order filled partially before cancellation, those executions retain their applicable charges. Cancelling the remainder does not remove the fees or account changes from the completed portion.