# Dry Run Orders

## Overview

Dry Run Orders provide a read-only mechanism to simulate order placement without affecting market state or account balances. This feature is useful for building user interfaces that need to display expected order outcomes before actual submission.

## Purpose

Dry run orders allow developers and traders to:
- Preview margin requirements before placing orders
- Validate order parameters without market impact
- Build responsive trading interfaces with real-time feedback
- Test order scenarios without consuming actual resources

## How to Use Dry Run Orders

### Endpoint

```
POST http://control-gateway:8181/AccountAdmin/Order/DryRun
```

### Request Format

The dry run endpoint accepts identical parameters to the standard order placement endpoint. Simply send your order request to the dry run endpoint instead of the live trading endpoint.

### Response Format

```json
{
  "marginRequired": 0,
  "marginAvailable": 0,
  "totalUsedMargin": 0,
  "riskUsed": 0,
  "riskAvailable": 0,
  "rejectReason": "ImmediateMatchPostOnly",
  "rejectionType": "InvalidTickSize",
  "amendRejectionType": "InvalidTickSize"
}
```

## Response Fields

### Margin Information

| Field | Description |
|-------|-------------|
| `marginAvailable` | Available margin on the account, excluding any margin that would be used by resting orders and positions, **not including** the effect of the dry run order |
| `marginRequired` | Additional margin that would be required by the order being simulated |
| `totalUsedMargin` | Total margin currently used by existing positions and orders, **excluding** the dry run order |

### Risk Information

| Field | Description |
|-------|-------------|
| `riskUsed` | Total risk that would be used by the dry run order |
| `riskAvailable` | Total amount of risk available before adding the dry run order |

### Rejection Information

| Field | Description |
|-------|-------------|
| `rejectReason` | Indicates a **stateful** validation failure (e.g., reduce-only order would increase position) |
| `rejectionType` | Indicates a **stateless** validation failure (e.g., order quantity exceeds maximum) |
| `amendRejectionType` | Reserved for future amendment dry run functionality |

## Important Limitations

### No Market Impact
- Dry run orders **never** interact with the market
- No executions are generated
- Account state remains completely unchanged
- Orders cannot be canceled (they don't exist after the response)

### Hidden Order Information
- Dry run responses **do not leak information** about hidden orders in the market
- Actual execution results may differ from dry run results if hidden orders are present
- This protects market integrity while providing useful simulation data

### Contingent Order Behavior
- Contingent and conditional flags are **ignored** on dry run orders
- Orders are treated as if they would trigger immediately
- `OneTriggersTheOther` and `OneCancelsTheOther` behaviors are not simulated

## Best Practices

### Performance Considerations
- Use dry run orders judiciously to avoid unnecessary server load
- Consider debouncing rapid dry run requests in real-time interfaces
