DeltaCalc.Liquidation (DeltaCalc v0.3.0)

Copy Markdown View Source

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

API Functions

FunctionArityDescriptionParam Kinds
liquidation4Calculate liquidation price using simplified analytical model.entry: value, leff: value, mmr_total: value, side: value

Summary

Functions

Calculate liquidation price using simplified analytical model.

Types

decimal_result()

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

Functions

liquidation(entry, leff, mmr_total, side)

@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)

# 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}"
  }
}