import { API, OrderSide } from '@kodiak-finance/orderly-types'; import { Decimal } from '@kodiak-finance/orderly-utils'; declare global { interface Window { __ORDERLY_VERSION__?: { [key: string]: string; }; } } declare const _default: "4.7.4"; /** * Calculates the notional value of a single position. * @param qty The quantity of the position. * @param mark_price The price of the position. * @returns The notional value of the position. */ declare function notional(qty: number, mark_price: number): number; /** * Calculates the total notional value of all positions. * @param positions The array of positions. * @returns The total notional value of all positions. */ declare function totalNotional(positions: API.Position[]): number; type UnrealPnLInputs = { markPrice: number; openPrice: number; qty: number; }; /** * Calculates the unrealized profit or loss of a single position. * @param inputs The inputs for calculating the unrealized profit or loss. * @returns The unrealized profit or loss of the position. */ declare function unrealizedPnL(inputs: UnrealPnLInputs): number; type UnrealPnLROIInputs = { positionQty: number; openPrice: number; IMR: number; unrealizedPnL: number; }; /** * Calculates the return on investment (ROI) of a single position's unrealized profit or loss. * @param inputs The inputs for calculating the ROI. * @returns The ROI of the position's unrealized profit or loss. */ declare function unrealizedPnLROI(inputs: UnrealPnLROIInputs): number; /** * Calculates the total unrealized profit or loss of all positions. * @param positions The array of positions. * @returns The total unrealized profit or loss of all positions. */ declare function totalUnrealizedPnL(positions: API.Position[]): number; declare const liqPrice: (inputs: { markPrice: number; symbol: string; totalCollateral: number; positionQty: number; positions: Pick[]; MMR: number; baseMMR: number; baseIMR: number; IMRFactor: number; costPosition: number; }) => number | null; type MMInputs = { positionQty: number; markPrice: number; MMR: number; }; /** * Calculates the maintenance margin of a position. * @param inputs The inputs for calculating the maintenance margin. * @returns The maintenance margin of the position. */ declare function maintenanceMargin(inputs: MMInputs): number; type UnsettlementPnLInputs = { positionQty: number; markPrice: number; costPosition: number; sumUnitaryFunding: number; lastSumUnitaryFunding: number; }; /** * Calculates the unrealized profit or loss of each position. * @param inputs The inputs for calculating the unrealized profit or loss. * @returns The unrealized profit or loss of each position. */ declare function unsettlementPnL(inputs: UnsettlementPnLInputs): number; type TotalUnsettlementPnLInputs = { positions: (API.Position & { sum_unitary_funding: number; })[]; sumUnitaryFunding: number; }; /** * Calculates the total unrealized profit or loss of all positions. * @param positions The array of positions. * @returns The total unrealized profit or loss of all positions. */ declare function totalUnsettlementPnL(positions: (API.Position & { sum_unitary_funding: number; })[]): number; type MMRInputs = { baseMMR: number; baseIMR: number; IMRFactor: number; positionNotional: number; IMR_factor_power: number; }; /** * Calculates the maintenance margin requirement (MMR) of a position. * @param inputs The inputs for calculating the MMR. * @returns The MMR of the position. */ declare function MMR$1(inputs: MMRInputs): number; /** * Calculates the profit or loss for take profit. * @returns The profit or loss for take profit. */ declare function estPnLForTP(inputs: { positionQty: number; entryPrice: number; price: number; }): number; /** * Calculates the estimated price for take profit. * This is the inverse of estPnLForTP: given PnL, calculates the price. * Formula: price = PnL / positionQty + entryPrice */ declare function estPriceForTP(inputs: { positionQty: number; entryPrice: number; pnl: number; }): number; /** * Calculates the estimated offset for take profit. */ declare function estOffsetForTP(inputs: { price: number; entryPrice: number; }): number; /** * Calculates the estimated price from offset for take profit. */ declare function estPriceFromOffsetForTP(inputs: { offset: number; entryPrice: number; }): number; /** * Calculates the PnL for stop loss. */ declare function estPnLForSL(inputs: { positionQty: number; entryPrice: number; }): number; /** * calculate the max position notional * max_notional = ( (1/ (leverage * imr_factor) ) ^ (1/0.8) */ declare function maxPositionNotional(inputs: { /** symbol leverage */ leverage: number; IMRFactor: number; }): number; /** * symbol_leverage_max = 1 / ( imr_factor * notional ^ 0.8 ) */ declare function maxPositionLeverage(inputs: { IMRFactor: number; notional: number; }): number; type positions_MMInputs = MMInputs; type positions_MMRInputs = MMRInputs; type positions_TotalUnsettlementPnLInputs = TotalUnsettlementPnLInputs; type positions_UnrealPnLInputs = UnrealPnLInputs; type positions_UnrealPnLROIInputs = UnrealPnLROIInputs; type positions_UnsettlementPnLInputs = UnsettlementPnLInputs; declare const positions_estOffsetForTP: typeof estOffsetForTP; declare const positions_estPnLForSL: typeof estPnLForSL; declare const positions_estPnLForTP: typeof estPnLForTP; declare const positions_estPriceForTP: typeof estPriceForTP; declare const positions_estPriceFromOffsetForTP: typeof estPriceFromOffsetForTP; declare const positions_liqPrice: typeof liqPrice; declare const positions_maintenanceMargin: typeof maintenanceMargin; declare const positions_maxPositionLeverage: typeof maxPositionLeverage; declare const positions_maxPositionNotional: typeof maxPositionNotional; declare const positions_notional: typeof notional; declare const positions_totalNotional: typeof totalNotional; declare const positions_totalUnrealizedPnL: typeof totalUnrealizedPnL; declare const positions_totalUnsettlementPnL: typeof totalUnsettlementPnL; declare const positions_unrealizedPnL: typeof unrealizedPnL; declare const positions_unrealizedPnLROI: typeof unrealizedPnLROI; declare const positions_unsettlementPnL: typeof unsettlementPnL; declare namespace positions { export { type positions_MMInputs as MMInputs, MMR$1 as MMR, type positions_MMRInputs as MMRInputs, type positions_TotalUnsettlementPnLInputs as TotalUnsettlementPnLInputs, type positions_UnrealPnLInputs as UnrealPnLInputs, type positions_UnrealPnLROIInputs as UnrealPnLROIInputs, type positions_UnsettlementPnLInputs as UnsettlementPnLInputs, positions_estOffsetForTP as estOffsetForTP, positions_estPnLForSL as estPnLForSL, positions_estPnLForTP as estPnLForTP, positions_estPriceForTP as estPriceForTP, positions_estPriceFromOffsetForTP as estPriceFromOffsetForTP, positions_liqPrice as liqPrice, positions_maintenanceMargin as maintenanceMargin, positions_maxPositionLeverage as maxPositionLeverage, positions_maxPositionNotional as maxPositionNotional, positions_notional as notional, positions_totalNotional as totalNotional, positions_totalUnrealizedPnL as totalUnrealizedPnL, positions_totalUnsettlementPnL as totalUnsettlementPnL, positions_unrealizedPnL as unrealizedPnL, positions_unrealizedPnLROI as unrealizedPnLROI, positions_unsettlementPnL as unsettlementPnL }; } type ResultOptions = { dp: number; }; type TotalValueInputs = { totalUnsettlementPnL: number; USDCHolding: number; nonUSDCHolding: { holding: number; indexPrice: number; }[]; }; /** * User's total asset value (denominated in USDC), including assets that cannot be used as collateral. */ declare function totalValue(inputs: TotalValueInputs): Decimal; /** * Total value of available collateral in the user's account (denominated in USDC). */ type FreeCollateralInputs = { totalCollateral: Decimal; totalInitialMarginWithOrders: number; }; /** * Calculate free collateral. */ declare function freeCollateral(inputs: FreeCollateralInputs): Decimal; type TotalCollateralValueInputs = { USDCHolding: number; nonUSDCHolding: { holding: number; indexPrice: number; collateralCap: number; collateralRatio: Decimal; }[]; unsettlementPnL: number; }; /** * Calculate total collateral. */ declare function totalCollateral(inputs: TotalCollateralValueInputs): Decimal; declare function initialMarginWithOrder(): void; type PositionNotionalWithOrderInputs = { markPrice: number; positionQtyWithOrders: number; }; /** * Sum of notional value for a symbol's position and orders. */ declare function positionNotionalWithOrder_by_symbol(inputs: PositionNotionalWithOrderInputs): Decimal; type PositionQtyWithOrderInputs = { positionQty: number; buyOrdersQty: number; sellOrdersQty: number; }; /** * Sum of position quantity and orders quantity for a symbol. */ declare function positionQtyWithOrders_by_symbol(inputs: PositionQtyWithOrderInputs): number; type IMRInputs = { /** * effective max leverage */ maxLeverage: number; baseIMR: number; IMR_Factor: number; positionNotional: number; ordersNotional: number; IMR_factor_power?: number; }; /** * Initial margin rate for a symbol. * Max(1 / Max Account Leverage, Base IMR i, IMR Factor i * Abs(Position Notional i + Order Notional i)^(4/5)) */ declare function IMR(inputs: IMRInputs): number; declare function buyOrdersFilter_by_symbol(orders: API.Order[], symbol: string): API.Order[]; declare function sellOrdersFilter_by_symbol(orders: API.Order[], symbol: string): API.Order[]; /** * Get the quantity of a specified symbol from the list of positions. */ declare function getQtyFromPositions(positions: API.Position[], symbol: string): number; /** * Get the quantity of long and short orders for a specified symbol from the list of orders. */ declare function getQtyFromOrdersBySide(orders: API.Order[], symbol: string, side: OrderSide): number; declare function getPositonsAndOrdersNotionalBySymbol(inputs: { positions: API.Position[]; orders: API.Order[]; symbol: string; markPrice: number; }): number; type TotalInitialMarginWithOrdersInputs = { positions: API.Position[]; orders: API.Order[]; markPrices: { [key: string]: number; }; symbolInfo: any; IMR_Factors: { [key: string]: number; }; } & Pick; /** * @deprecated * Calculate the total initial margin used by the user (including positions and orders). */ declare function totalInitialMarginWithOrders(inputs: TotalInitialMarginWithOrdersInputs): number; declare function totalInitialMarginWithQty(inputs: { positions: API.Position[]; markPrices: { [key: string]: number; }; symbolInfo: any; IMR_Factors: { [key: string]: number; }; /** * account max leverage */ maxLeverage: number; }): number; /** * Group orders by symbol, as a symbol can have multiple orders. */ declare function groupOrdersBySymbol(orders: API.Order[]): { [key: string]: API.Order[]; }; /** * Extracts all unique symbols from positions and orders. * @param positions - An array of position objects. * @param orders - An array of order objects. * @returns An array of unique symbols. */ declare function extractSymbols(positions: Pick[], orders: Pick[]): string[]; type OtherIMsInputs = { positions: API.Position[]; markPrices: { [key: string]: number; }; /** * account max leverage */ maxLeverage: number; symbolInfo: any; IMR_Factors: { [key: string]: number; }; }; /** * Total margin used by other symbols (except the current symbol). */ declare function otherIMs(inputs: OtherIMsInputs): number; type MaxQtyInputs = { symbol: string; baseMaxQty: number; /** * Total collateral of the user (denominated in USDC), can be calculated from totalCollateral. * @see totalCollateral */ totalCollateral: number; maxLeverage: number; baseIMR: number; /** * @see otherIMs */ otherIMs: number; markPrice: number; positionQty: number; buyOrdersQty: number; sellOrdersQty: number; IMR_Factor: number; takerFeeRate: number; }; /** * Maximum order quantity. */ declare function maxQty(side: OrderSide, inputs: MaxQtyInputs, options?: ResultOptions): number; declare function maxQtyByLong(inputs: Omit, options?: ResultOptions): number; declare function maxQtyByShort(inputs: Omit, options?: ResultOptions): number; type TotalMarginRatioInputs = { totalCollateral: number; markPrices: { [key: string]: number; }; positions: API.Position[]; }; /** * total margin ratio */ declare function totalMarginRatio(inputs: TotalMarginRatioInputs, dp?: number): number; type TotalUnrealizedROIInputs = { totalUnrealizedPnL: number; totalValue: number; }; /** * totalUnrealizedROI */ declare function totalUnrealizedROI(inputs: TotalUnrealizedROIInputs): number; /** * current account leverage */ declare function currentLeverage(totalMarginRatio: number): number; type AvailableBalanceInputs = { USDCHolding: number; unsettlementPnL: number; }; declare function availableBalance(inputs: AvailableBalanceInputs): number; type AccountMMRInputs = { positionsMMR: number; /** * Notional sum of all positions, * positions.totalNotional() */ positionsNotional: number; }; /** * total maintenance margin ratio * @param inputs AccountMMRInputs * @returns number|null */ declare function MMR(inputs: AccountMMRInputs): number | null; declare const collateralRatio: (params: { baseWeight: number; discountFactor: number | null; collateralQty: number; collateralCap: number; indexPrice: number; }) => Decimal; /** collateral_value_i = min(collateral_qty_i , collateral_cap_i) * weight_i * index_price_i */ declare const collateralContribution: (params: { collateralQty: number; collateralCap: number; collateralRatio: number; indexPrice: number; }) => number; declare const LTV: (params: { usdcBalance: number; upnl: number; assets: Array<{ qty: number; indexPrice: number; weight: number; }>; }) => number; /** * max(0, min(USDC_balance, free_collateral - max(upnl, 0))) */ declare const maxWithdrawalUSDC: (inputs: { USDCBalance: number; freeCollateral: Decimal; upnl: number; }) => number; /** * * Other collateral: min(collateral_qty_i, free_collateral / (index_price_i × weight_i) * Other collateral with negative USDC: min(collateral_qty_i, free_collateral / (index_price_i × (1 + buffer) × weight_i) * buffer: 0.2% */ declare const maxWithdrawalOtherCollateral: (inputs: { USDCBalance: number; collateralQty: number; freeCollateral: Decimal; indexPrice: number; weight: Decimal; }) => Decimal; declare const calcMinimumReceived: (inputs: { amount: number; slippage: number; }) => number; /** * @deprecated This method will be removed soon. Please update your code to use symbolLeverage directly. */ declare const maxLeverage: (inputs: { symbolLeverage?: number; accountLeverage: number; }) => number; type account_AccountMMRInputs = AccountMMRInputs; type account_AvailableBalanceInputs = AvailableBalanceInputs; type account_FreeCollateralInputs = FreeCollateralInputs; declare const account_IMR: typeof IMR; type account_IMRInputs = IMRInputs; declare const account_LTV: typeof LTV; declare const account_MMR: typeof MMR; type account_MaxQtyInputs = MaxQtyInputs; type account_OtherIMsInputs = OtherIMsInputs; type account_PositionNotionalWithOrderInputs = PositionNotionalWithOrderInputs; type account_PositionQtyWithOrderInputs = PositionQtyWithOrderInputs; type account_ResultOptions = ResultOptions; type account_TotalCollateralValueInputs = TotalCollateralValueInputs; type account_TotalInitialMarginWithOrdersInputs = TotalInitialMarginWithOrdersInputs; type account_TotalMarginRatioInputs = TotalMarginRatioInputs; type account_TotalUnrealizedROIInputs = TotalUnrealizedROIInputs; type account_TotalValueInputs = TotalValueInputs; declare const account_availableBalance: typeof availableBalance; declare const account_buyOrdersFilter_by_symbol: typeof buyOrdersFilter_by_symbol; declare const account_calcMinimumReceived: typeof calcMinimumReceived; declare const account_collateralContribution: typeof collateralContribution; declare const account_collateralRatio: typeof collateralRatio; declare const account_currentLeverage: typeof currentLeverage; declare const account_extractSymbols: typeof extractSymbols; declare const account_freeCollateral: typeof freeCollateral; declare const account_getPositonsAndOrdersNotionalBySymbol: typeof getPositonsAndOrdersNotionalBySymbol; declare const account_getQtyFromOrdersBySide: typeof getQtyFromOrdersBySide; declare const account_getQtyFromPositions: typeof getQtyFromPositions; declare const account_groupOrdersBySymbol: typeof groupOrdersBySymbol; declare const account_initialMarginWithOrder: typeof initialMarginWithOrder; declare const account_maxLeverage: typeof maxLeverage; declare const account_maxQty: typeof maxQty; declare const account_maxQtyByLong: typeof maxQtyByLong; declare const account_maxQtyByShort: typeof maxQtyByShort; declare const account_maxWithdrawalOtherCollateral: typeof maxWithdrawalOtherCollateral; declare const account_maxWithdrawalUSDC: typeof maxWithdrawalUSDC; declare const account_otherIMs: typeof otherIMs; declare const account_positionNotionalWithOrder_by_symbol: typeof positionNotionalWithOrder_by_symbol; declare const account_positionQtyWithOrders_by_symbol: typeof positionQtyWithOrders_by_symbol; declare const account_sellOrdersFilter_by_symbol: typeof sellOrdersFilter_by_symbol; declare const account_totalCollateral: typeof totalCollateral; declare const account_totalInitialMarginWithOrders: typeof totalInitialMarginWithOrders; declare const account_totalInitialMarginWithQty: typeof totalInitialMarginWithQty; declare const account_totalMarginRatio: typeof totalMarginRatio; declare const account_totalUnrealizedROI: typeof totalUnrealizedROI; declare const account_totalValue: typeof totalValue; declare namespace account { export { type account_AccountMMRInputs as AccountMMRInputs, type account_AvailableBalanceInputs as AvailableBalanceInputs, type account_FreeCollateralInputs as FreeCollateralInputs, account_IMR as IMR, type account_IMRInputs as IMRInputs, account_LTV as LTV, account_MMR as MMR, type account_MaxQtyInputs as MaxQtyInputs, type account_OtherIMsInputs as OtherIMsInputs, type account_PositionNotionalWithOrderInputs as PositionNotionalWithOrderInputs, type account_PositionQtyWithOrderInputs as PositionQtyWithOrderInputs, type account_ResultOptions as ResultOptions, type account_TotalCollateralValueInputs as TotalCollateralValueInputs, type account_TotalInitialMarginWithOrdersInputs as TotalInitialMarginWithOrdersInputs, type account_TotalMarginRatioInputs as TotalMarginRatioInputs, type account_TotalUnrealizedROIInputs as TotalUnrealizedROIInputs, type account_TotalValueInputs as TotalValueInputs, account_availableBalance as availableBalance, account_buyOrdersFilter_by_symbol as buyOrdersFilter_by_symbol, account_calcMinimumReceived as calcMinimumReceived, account_collateralContribution as collateralContribution, account_collateralRatio as collateralRatio, account_currentLeverage as currentLeverage, account_extractSymbols as extractSymbols, account_freeCollateral as freeCollateral, account_getPositonsAndOrdersNotionalBySymbol as getPositonsAndOrdersNotionalBySymbol, account_getQtyFromOrdersBySide as getQtyFromOrdersBySide, account_getQtyFromPositions as getQtyFromPositions, account_groupOrdersBySymbol as groupOrdersBySymbol, account_initialMarginWithOrder as initialMarginWithOrder, account_maxLeverage as maxLeverage, account_maxQty as maxQty, account_maxQtyByLong as maxQtyByLong, account_maxQtyByShort as maxQtyByShort, account_maxWithdrawalOtherCollateral as maxWithdrawalOtherCollateral, account_maxWithdrawalUSDC as maxWithdrawalUSDC, account_otherIMs as otherIMs, account_positionNotionalWithOrder_by_symbol as positionNotionalWithOrder_by_symbol, account_positionQtyWithOrders_by_symbol as positionQtyWithOrders_by_symbol, account_sellOrdersFilter_by_symbol as sellOrdersFilter_by_symbol, account_totalCollateral as totalCollateral, account_totalInitialMarginWithOrders as totalInitialMarginWithOrders, account_totalInitialMarginWithQty as totalInitialMarginWithQty, account_totalMarginRatio as totalMarginRatio, account_totalUnrealizedROI as totalUnrealizedROI, account_totalValue as totalValue }; } /** * Maximum price when placing an order */ declare function maxPrice(markprice: number, range: number): number; /** * Minimum price when placing an order */ declare function minPrice(markprice: number, range: number): number; /** * Scope price when placing an order * @returns number */ declare function scopePrice(price: number, scope: number, side: "BUY" | "SELL"): number; /** * Calculate the order fee */ declare function orderFee(inputs: { /** * Order quantity */ qty: number; price: number; futuresTakeFeeRate: number; }): number; type EstimatedLiquidationPriceInputs = { totalCollateral: number; markPrice: number; baseMMR: number; baseIMR: number; IMR_Factor: number; orderFee: number; positions: Pick[]; newOrder: { symbol: string; qty: number; price: number; }; }; /** * Estimated liquidation price * @param inputs * @returns */ declare function estLiqPrice(inputs: EstimatedLiquidationPriceInputs): number; type EstimatedLeverageInputs = { totalCollateral: number; positions: Pick[]; newOrder: { symbol: string; qty: number; price: number; }; }; /** * Estimated leverage * @param inputs EstimtedLeverageInputs * @returns number */ declare function estLeverage(inputs: EstimatedLeverageInputs): number | null; declare function tpslROI(inputs: { side: OrderSide; type: "tp" | "sl"; closePrice: number; orderPrice: number; leverage: number; }): number; type order_EstimatedLeverageInputs = EstimatedLeverageInputs; type order_EstimatedLiquidationPriceInputs = EstimatedLiquidationPriceInputs; declare const order_estLeverage: typeof estLeverage; declare const order_estLiqPrice: typeof estLiqPrice; declare const order_maxPrice: typeof maxPrice; declare const order_minPrice: typeof minPrice; declare const order_orderFee: typeof orderFee; declare const order_scopePrice: typeof scopePrice; declare const order_tpslROI: typeof tpslROI; declare namespace order { export { type order_EstimatedLeverageInputs as EstimatedLeverageInputs, type order_EstimatedLiquidationPriceInputs as EstimatedLiquidationPriceInputs, order_estLeverage as estLeverage, order_estLiqPrice as estLiqPrice, order_maxPrice as maxPrice, order_minPrice as minPrice, order_orderFee as orderFee, order_scopePrice as scopePrice, order_tpslROI as tpslROI }; } export { account, order, order as orderUtils, positions, _default as version };