# Dynamic spreads

Dynamic spreads are a per-pair execution mechanism that enable zero-spread trading under balanced conditions and apply cost only when short-term order flow becomes one-sided. By continuously tracking net buy and sell pressure and comparing it to a configured threshold, they allow most trades to execute at the mid-price while charging impact fees only to orders that deepen existing imbalances. This ensures pricing remains efficient, discourages momentum-driven flow, and aligns execution cost with real liquidity pressure rather than applying uniform spreads.

### When Are They Used?

Dynamic spreads are applied only to:

* **Less-liquid pairs**, or
* Pairs with **large OI caps** (to simulate liquidity constraints).

They mirror **underlying market costs** and **adjust by trade size**. We track a short-window **net flow** (buys − sells) that **decays back to 0**.\
If the **net volume** rises **above a per-asset threshold**, trades **with** the pressure pay impact, while trades **against** it execute at **mid (0% impact)**—incentivizing flow that reduces the imbalance.

{% hint style="warning" %}
**Current status:** Dynamic spread is **off for all pairs**. Stay tuned.
{% endhint %}

### On/Off Behavior

* **Dynamic Spreads: ON**\
  Execution is either:
  * **Mid (0%)**, if conditions are not met; or
  * **Spread + Dynamic impact**, when **net flow > threshold** and the **order is same direction of net flow**.
* **Dynamic Spreads: OFF**\
  Execution uses **oracle bid/ask**:
  * **Buy-equivalent** orders (open long / close short) execute at **ask**.
  * **Sell-equivalent** orders (close long / open short) execute at **bid**.

### Applicability Rules

* If `|finalImbalance| ≤ netVolThreshold` → **execute at mid (0%)**.
* If `|finalImbalance| > netVolThreshold` → **apply impact only to the portion above threshold** and **only to the side that increases the imbalance**.

**Example**\
Threshold = `1M`, current **buy** pressure = `2M`.\
**Sells** up to `3M` clear at **mid**, while **buys** pay impact.

### Price Impact: Components & Formula

Dynamic spread = **Spread from oracle** + **Dynamic price impact.**

#### 1) Spread from oracle

Live **bid/ask** from the oracle.

* For applicable trades, **half-spread** is applied to the **portion above threshold**.
* Intuition: same “base” cost as the underlying market.

#### 2) Dynamic price impact

Scales with **short-term net volume** and **trade size**, with extra cost in one-sided markets and **down-weighting for small trades**.

**Variables**

```
excessOverThreshold = |finalImbalance| − netVolThreshold   (must be > 0)
thresholdTradeSize  = min(tradeSize, excessOverThreshold)
thresholdRatio      = thresholdTradeSize / excessOverThreshold
excessSquared       = excessOverThreshold²
```

**Percent impact**

```
priceImpactP = (spreadComponent + dynamicComponent) / tradeSize * 100
```

**Components**

```
spreadComponent  = (spread * thresholdTradeSize) / 2
dynamicComponent = (thresholdTradeSize * thresholdRatio) * (priceImpactK * excessSquared)
```

* `spread`: current oracle spread (live quote).
* `priceImpactK`: curvature factor (how fast cost grows with excess flow).
* `thresholdRatio`: scales **down** the charge for small trades so small orders are minimally affected.

### Execution Logic (Side Selection)

* **Buy pressure (`finalImbalance > 0`)**
  * **Buys** (open long / close short): **pay** impact.
  * **Sells** (close long / open short): **mid (0%)**.
* **Sell pressure (`finalImbalance < 0`)**
  * **Sells**: **pay** impact.
  * **Buys**: **mid (0%)**.

This pushes flow to **offset** the current imbalance.

### Decaying

**Net volume decays over time** toward zero. The decay behaves **similarly to a negative exponential**, meaning it falls quickly at first and then tapers off. Until it drops **below the per-asset threshold**, impact can still apply to orders that *increase* the current net value. You can see the **exact remaining decay time** in the trading form under **“Simulated spread”**. This value reflects the pair’s configured **decayRate** and current **net flow**, and updates in real time.

### Triggers: TP / SL / Liquidation

* **Take Profit (TP)** — **Triggered on price&#x20;*****after*****&#x20;impact**\
  You realize the **exact % profit** you set. If net flow is against you, the TP may trigger slightly **later** to ensure you receive the configured %.
* **Stop Loss (SL) / Liquidation** — **Triggered on mid price**\
  We use mid for predictability. If net flow is against you, **P\&L may be slightly lower than expected**, because the **trigger** is at mid but **execution** may incur **spread + dynamic impact** when applicable.
