margin

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Risk

type Risk struct {
	MMR *big.Int // Maintenance Margin Requirement
	IMR *big.Int // Initial Margin Requirement
	NC  *big.Int // Net Collateral
}

Risk is a struct to hold net collateral and margin requirements. This can be applied to a single position or an entire account.

func ZeroRisk

func ZeroRisk() Risk

ZeroRisk returns a Risk object with all fields set to zero.

func (*Risk) AddInPlace

func (a *Risk) AddInPlace(b Risk)

AddInPlace adds the values of b to a (in-place).

func (*Risk) Cmp

func (a *Risk) Cmp(b Risk) int

Note that here we are effectively checking that `a.NetCollateral / a.MaintenanceMargin >= b.NetCollateral / b.MaintenanceMargin`. However, to avoid rounding errors, we factor this as `a.NetCollateral * b.MaintenanceMargin >= b.NetCollateral * a.MaintenanceMargin`.

func (*Risk) IsInitialCollateralized

func (a *Risk) IsInitialCollateralized() bool

IsInitialCollateralized returns true if the account has enough net collateral to meet the initial margin requirement.

func (*Risk) IsLiquidatable

func (a *Risk) IsLiquidatable() bool

IsLiquidatable returns true if the account is liquidatable given its maintenance margin requirement and net collateral.

The account is liquidatable if both of the following are true: - The maintenance margin requirements are greater than zero (note that they can never be negative). - The maintenance margin requirements are greater than the account's net collateral.

func (*Risk) IsMaintenanceCollateralized

func (a *Risk) IsMaintenanceCollateralized() bool

IsMaintenanceCollateralized returns true if the account has enough net collateral to meet the maintenance margin requirement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL