@drift-labs/common
Version:
Common functions for Drift
57 lines (56 loc) • 2.53 kB
TypeScript
import { BN, BigNum, DriftClient, PositionDirection, User } from '@drift-labs/sdk';
import { MarketId, UIOrderType } from 'src/types';
/**
* Checks if a given order amount represents an entire position order
* by comparing it with MAX_LEVERAGE_ORDER_SIZE
* @param orderAmount - The BigNum order amount to check
* @returns true if the order is for the entire position, false otherwise
*/
export declare const isEntirePositionOrder: (orderAmount: BigNum) => boolean;
export declare const TRADING_UTILS: {
calculatePnlPctFromPosition: (pnl: BN, quoteEntryAmount: BN, leverage?: number) => number;
calculatePotentialProfit: (props: {
currentPositionSize: BigNum;
currentPositionDirection: PositionDirection;
currentPositionEntryPrice: BigNum;
tradeDirection: PositionDirection;
/**
* Amount of position being closed in base asset size
*/
exitBaseSize: BigNum;
/**
* Either the user's limit price (for limit orders) or the estimated exit price (for market orders)
*/
exitPrice: BigNum;
takerFeeBps: number;
slippageTolerance?: number;
isMarketOrder?: boolean;
}) => {
estimatedProfit: BigNum;
estimatedProfitBeforeFees: BigNum;
estimatedTakerFee: BigNum;
notionalSizeAtEntry: BigNum;
notionalSizeAtExit: BigNum;
};
calculateLiquidationPriceAfterPerpTrade: ({ estEntryPrice, orderType, perpMarketIndex, tradeBaseSize, isLong, userClient, oraclePrice, limitPrice, offsetCollateral, precision, isEnteringHighLeverageMode, capLiqPrice, }: {
estEntryPrice: BN;
orderType: UIOrderType;
perpMarketIndex: number;
tradeBaseSize: BN;
isLong: boolean;
userClient: User;
oraclePrice: BN;
limitPrice?: BN;
offsetCollateral?: BN;
precision?: number;
isEnteringHighLeverageMode?: boolean;
capLiqPrice?: boolean;
}) => number;
checkIsMarketOrderType: (orderType: UIOrderType) => boolean;
convertLeverageToMarginRatio: (leverage: number) => number | undefined;
getMarketTickSize: (driftClient: DriftClient, marketId: MarketId) => BN;
getMarketTickSizeDecimals: (driftClient: DriftClient, marketId: MarketId) => number;
getMarketStepSize: (driftClient: DriftClient, marketId: MarketId) => BN;
getMarketStepSizeDecimals: (driftClient: DriftClient, marketId: MarketId) => number;
isEntirePositionOrder: (orderAmount: BigNum) => boolean;
};