# `DeltaCalc.Liquidation`
[🔗](https://github.com/ZenHive/delta_calc/blob/v0.3.0/lib/delta_calc/liquidation.ex#L1)

Simplified analytical liquidation-price calculations for long and short positions.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `liquidation` | 4 | Calculate liquidation price using simplified analytical model. | `entry: value`, `leff: value`, `mmr_total: value`, `side: value` |

# `decimal_result`

```elixir
@type decimal_result() :: Decimal.t() | {:error, atom()}
```

# `liquidation`

```elixir
@spec liquidation(Decimal.t(), Decimal.t(), Decimal.t(), :long | :short) ::
  decimal_result()
```

Calculate liquidation price using simplified analytical model.

## Parameters

  * `entry` - Entry price (> 0) as a canonical decimal string; native Elixir callers may also pass Decimal or integer. (value)
  * `leff` - Effective leverage (>= 0) as a canonical decimal string; native Elixir callers may also pass Decimal or integer. (value)
  * `mmr_total` - Total minimum margin requirement (0-1) as a canonical decimal string; native Elixir callers may also pass Decimal or integer. (value)
  * `side` - Position side (:long or :short) (value)

## Returns

Estimated liquidation price, or \{:error, :non_positive_entry | :negative_effective_leverage\} (`decimal`)

```elixir
# descripex:contract
%{
  params: %{
    entry: %{
      description: "Entry price (> 0) as a canonical decimal string; native Elixir callers may also pass Decimal or integer.",
      kind: :value,
      schema: %{"type" => "string"}
    },
    side: %{
      description: "Position side (:long or :short)",
      kind: :value,
      schema: %{"enum" => ["long", "short"], "type" => "string"}
    },
    leff: %{
      description: "Effective leverage (>= 0) as a canonical decimal string; native Elixir callers may also pass Decimal or integer.",
      kind: :value,
      schema: %{"type" => "string"}
    },
    mmr_total: %{
      description: "Total minimum margin requirement (0-1) as a canonical decimal string; native Elixir callers may also pass Decimal or integer.",
      kind: :value,
      schema: %{"type" => "string"}
    }
  },
  returns: %{
    type: :decimal,
    description: "Estimated liquidation price, or {:error, :non_positive_entry | :negative_effective_leverage}"
  }
}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
