@orderly.network/perp

A library of calculation formulas related to Orderly futures trading. This library is designed to be purely functional, with no context dependencies. Simply call the appropriate functions directly for seamless integration.

Install

npm install @orderly.network/perp

Usage

import { maxQty, liqPrice } from "@orderly.network/perp";
import { OrderSide } from "@orderly.network/types";

// calculation of the maximum allowable position size for an account
const myMaxQty = () => {
  const qty = maxQty("PERP_ETH_USDC", OrderSide.BUY);
  console.log(qty); //
};

// calculation of the liquidation price of a position
const myLiqPrice = () => {
  const price = liqPrice(
    25986.2, //markPrice
    1981.66, // total collateral
    0.2, // positions size
    0.05 //MMR
  );
  console.log(myLiqPrice);
};

If you are a React developer, we recommend utilizing our React Hooks library:@orderly.network/hooks. It encapsulates all the calculation formulas, and the hook internally manages the required data for computations.

Function list

account

  • IMR - Calculate the IMR of the account.
  • availableBalance - Calculate the available balance of the account.
  • currentLeverage - Calculate the current leverage of the account.
  • freeCollateral - Calculate the available collateral of the account.
  • maxQty - Calculate the maximum quantity the account can open.
  • totalCollateral - Calculate the total collateral of the account.
  • totalInitialMarginWithOrders - Calculate the total initial margin of the account with orders.
  • totalMarginRatio - Calculate the total margin ratio of the account.
  • totalUnrealizedROI - Calculate the total unrealized return on investment of the account.
  • totalValue - Calculate the total value of the account.

positions

  • MMR - Calculate the MMR of the position.
  • liqPrice - Calculate the liquidation price of the position.
  • maintenanceMargin - Calculate the maintenance margin of the position.
  • totalNotional - Calculate the total notional value of the position.
  • unrealizedPnL - Calculate the unrealized profit and loss of an individual position.
  • unrealizedPnLROI - Calculate the unrealized return on investment of an individual position.
  • totalUnrealizedPnL - Calculate the total unrealized profit and loss of the positions.
  • unsettlementPnL - Calculate the unsettlement profit and loss of an individual position.
  • totalUnsettlementPnL - Calculate the total unsettlement profit and loss of the positions.