Skip to main content

prices

This module provides utilities for calculating prices, price impacts, and acceptable price ranges for GMX trading operations. It handles mark price determination, order threshold types, and acceptable price calculations for various trading scenarios.

Methods

getMarkPrice

  • getMarkPrice(params): bigint

Parameters

  • prices: TokenPrices - Token price information containing min and max prices
  • isIncrease: boolean - Whether this is an increase position operation
  • isLong: boolean - Whether this is a long position

Returns the appropriate mark price (min or max) based on the operation type and position direction.

import { getMarkPrice } from "@gmx-ui/sdk/utils/prices";

const markPrice = getMarkPrice({
prices: {
minPrice: 1800000000000000000000n, // $1800
maxPrice: 1820000000000000000000n, // $1820
},
isIncrease: true,
isLong: true
});
// Returns maxPrice for long increase operations

getShouldUseMaxPrice

  • getShouldUseMaxPrice(isIncrease: boolean, isLong: boolean): boolean

Parameters

  • isIncrease: boolean - Whether this is an increase position operation
  • isLong: boolean - Whether this is a long position

Determines whether to use the maximum price based on operation type and position direction.

import { getShouldUseMaxPrice } from "@gmx-ui/sdk/utils/prices";

const useMaxPrice = getShouldUseMaxPrice(true, true);
// Returns true for long increase operations

getOrderThresholdType

  • getOrderThresholdType(orderType: OrderType, isLong: boolean): TriggerThresholdType | undefined

Parameters

  • orderType: OrderType - The type of order (LimitIncrease, StopIncrease, LimitDecrease, StopLossDecrease)
  • isLong: boolean - Whether this is a long position

Returns the appropriate trigger threshold type for the given order type and position direction.

import { getOrderThresholdType } from "@gmx-ui/sdk/utils/prices";
import { OrderType } from "@gmx-ui/sdk/types/orders";

const thresholdType = getOrderThresholdType(OrderType.LimitIncrease, true);
// Returns TriggerThresholdType.Below for long limit increase orders

getAcceptablePriceInfo

  • getAcceptablePriceInfo(params): object

Parameters

  • marketInfo: MarketInfo - Market information including index token details
  • isIncrease: boolean - Whether this is an increase position operation
  • isLong: boolean - Whether this is a long position
  • indexPrice: bigint - Current index price of the token
  • sizeDeltaUsd: bigint - Size change in USD
  • maxNegativePriceImpactBps?: bigint - Maximum negative price impact in basis points (optional)

Calculates comprehensive acceptable price information including price impact and acceptable price ranges.

import { getAcceptablePriceInfo } from "@gmx-ui/sdk/utils/prices";

const priceInfo = getAcceptablePriceInfo({
marketInfo: marketInfo,
isIncrease: true,
isLong: true,
indexPrice: 1800000000000000000000n,
sizeDeltaUsd: 1000000000000000000000n, // $1000
maxNegativePriceImpactBps: 50n // 0.5%
});

// Returns object with acceptablePrice, priceImpactDeltaUsd, etc.

getAcceptablePriceByPriceImpact

  • getAcceptablePriceByPriceImpact(params): object

Parameters

  • isIncrease: boolean - Whether this is an increase position operation
  • isLong: boolean - Whether this is a long position
  • indexPrice: bigint - Current index price of the token
  • sizeDeltaUsd: bigint - Size change in USD
  • priceImpactDeltaUsd: bigint - Price impact in USD

Calculates acceptable price based on price impact considerations.

import { getAcceptablePriceByPriceImpact } from "@gmx-ui/sdk/utils/prices";

const acceptablePrice = getAcceptablePriceByPriceImpact({
isIncrease: true,
isLong: true,
indexPrice: 1800000000000000000000n,
sizeDeltaUsd: 1000000000000000000000n,
priceImpactDeltaUsd: -5000000000000000000n // -$5 impact
});

// Returns { acceptablePrice, acceptablePriceDeltaBps, priceDelta }

getDefaultAcceptablePriceImpactBps

  • getDefaultAcceptablePriceImpactBps(params): bigint

Parameters

  • isIncrease: boolean - Whether this is an increase position operation
  • isLong: boolean - Whether this is a long position
  • indexPrice: bigint - Current index price of the token
  • sizeDeltaUsd: bigint - Size change in USD
  • priceImpactDeltaUsd: bigint - Price impact in USD
  • acceptablePriceImapctBuffer?: number - Buffer for acceptable price impact (optional)

Returns the default acceptable price impact in basis points with appropriate buffer.

import { getDefaultAcceptablePriceImpactBps } from "@gmx-ui/sdk/utils/prices";

const acceptableBps = getDefaultAcceptablePriceImpactBps({
isIncrease: true,
isLong: true,
indexPrice: 1800000000000000000000n,
sizeDeltaUsd: 1000000000000000000000n,
priceImpactDeltaUsd: -5000000000000000000n,
acceptablePriceImapctBuffer: 30 // 0.3% buffer
});

// Returns acceptable price impact in basis points