# Dynamic Slippage

### **Overview**

The Dynamic Slippage mechanism is designed to accurately reflect the market impact of user trades. Every order impacts market liquidity, particularly when the trade volume is large. To ensure fair pricing and risk management, slippage is calculated dynamically based on the order size, the current Open Interest (OI) imbalance, and real-time market depth.

### **Calculation Logic**

The system determines the slippage percentage by comparing the calculated Market Impact against a configured Minimum Slippage threshold. The greater of the two values is applied.

**A. Long Scenario (Open Long / Close Short)**

This formula applies when a user opens a Long position or closes a Short position.

$$
SlippageLong= Max{(NewPostion-Symbol Short OI+Symbol Long OI)/DepthAbove, MinLongSlippage)}
$$

**B. Short Scenario (Open Short / Close Long)**

This formula applies when a user opens a Short position or closes a Long position.

$$
SlippageShort=Max{(NewPostion-Symbol Long OI+Symbol Short OI)/DepthBelow, MinShortSlippage)}
$$

### **Parameter Definitions**

#### **Market Depth (Liquidity)**

Market depth data is aggregated from major exchanges via the CMC interface to determine the available liquidity for absorbing orders.

* Data Sources: Binance, Coinbase, OKX, Kraken and other major exchanges (USDT or USD pairs).
* Update Frequency: Every 5 seconds.

#### **Depth Formulas**

The depth values used in the denominator are calculated as follows:

**Depth Above (Ask Liquidity):**

$$
Depthabove​=k×100×∑(depthpositive\_two​)​
$$

* *`depth_positive_two`: Aggregated +2% depth data from sources.*

**Depth Below (Bid Liquidity):**

$$
Depthbelow​=k×2100×∑(depthnegative\_two​)​
$$

* *`depth_negative_two`: Aggregated -2% depth data from sources.*

**Adjustment Coefficient (k):** A scalar used to adjust liquidity sensitivity.

* **Default:** k = 1.5
* **Configuration:** Configurable per Symbol.

**Minimum Slippage:**&#x20;

A fixed parameter configured at the Symbol level. This acts as a floor to ensure slippage never drops below a baseline value, even in high liquidity conditions.

### **Precision and Rounding Logic**

The final slippage percentage is processed with a precision of **1/10,000 (0.01%)**. The rounding method depends on which value is selected by the `MAX` function:

**Scenario A (Calculated Impact > Min Slippage):**

If the dynamic market impact calculation is higher than the minimum slippage, the system applies an **Unconditional Carry (Ceiling)** logic.

* Action: Round **UP** to the nearest 1/10,000.

**Scenario B (Calculated Impact ≤ Min Slippage):**

If the minimum slippage is used, standard rounding applies.

* Action: **Round Half Up (Nearest)** to 1/10,000.

#### **Example Logic:**

```abap
// precision = 0.0001 # 1/10000

if calculated_impact > min_slippage:
    # Unconditional carry (Ceiling)
    final_slippage = math.ceil(calculated_impact / precision) * precision
else:
    # Standard rounding (Round Half Up) for Min Slippage
    final_slippage = round(min_slippage / precision) * precision

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.asterdex.com/trading/shield-mode/dynamic-slippage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
