# Mechanism

### OI utilization and skew&#x20;

For each symbol we track:

* **Long OI** and **Short OI** (current open interest on each side).
* **Max OI** per side (from price impact config or symbol config).

⠀We define utilization and skew as:

* **This side utilization** = (current OI on this side + new trade size) / max OI on this side
* **Opposite side utilization** = current OI on opposite side / max OI on opposite side
* **Skew ratio** = max(0, this side utilization − opposite side utilization), clamped to \[0, 1]

⠀When the side you’re trading is more utilized than the other, skew ratio is positive and spread increases.

### Spread formula

* **Dynamic spread** = `max_dynamic_spread × (skew_ratio ^ impact_exponent)`
* Exponent is between 1 (linear) and 3 (e.g. cubic); higher exponent = spread grows faster as skew increases.
* **Total spread** = base spread + dynamic spread, capped by **max total spread**.

⠀So:

* **Base spread** — Applied to every trade on the symbol.
* **Dynamic spread** — Extra spread from OI skew; larger when your side is more crowded.
* **Cap** — Total spread (base + dynamic) cannot exceed the configured max (e.g. 10% in the contract).

### Direction (how spread affects price)

Spread is applied so that the trader gets a worse execution when adding to the crowded side:

| **Action**  | **Effect on execution price**           |
| ----------- | --------------------------------------- |
| Open long   | Price **increases** (you pay more).     |
| Open short  | Price **decreases** (you receive less). |
| Close long  | Price **decreases** (you receive less). |
| Close short | Price **increases** (you pay more).     |

So: opening long or closing short worsens your price when spread is positive; opening short or closing long does the same in the opposite direction.

### Size scaling

Config can include a **reference size**. When set, the dynamic spread is scaled by a factor that increases with trade size (e.g. `1 + min(1, position_size / reference_size)`), so larger orders see more impact, similar to orderbook depth.

### Average spread over the trade

For large orders we don’t use only the end-state skew. We integrate the spread over the path from “OI before trade” to “OI after trade” and use an **average spread** over that path, so execution reflects the fact that the trade itself moves the skew.

### Summary

* Price impact = **simulated spread** from OI skew, not a change to the oracle.
* **Crowded side** (high utilization) → higher spread → worse execution for trades that add to that side.
* **Base + dynamic** spread, with a **hard cap** (e.g. 10%).
* **Direction logic** ensures longs/shorts and open/close are penalized in the right direction.
* Optional **size scaling** and **path-averaged** spread keep behavior consistent for small and large orders.
