Returns the leverage ratio for the account after adding (or subtracting) the given quote size to the given position
leverageRatio : Precision TEN_THOUSAND
@param: targetMarketType
Optional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleancalculates Free Collateral = Total collateral - margin requirement
: Precision QUOTE_PRECISION
The margin requirement of a certain type (Initial or Maintenance) in USDC. : QUOTE_PRECISION
Optional
liquidationBuffer: BNcalculates max allowable leverage exceeding hitting requirement category for large sizes where imf factor activates, result is a lower bound
: Precision TEN_THOUSAND
{Initial, Maintenance}
if calculating max leveraging for adding lp, need to add buffer
calculates max allowable leverage exceeding hitting requirement category
: Precision TEN_THOUSAND
Calculates the max amount of token that can be swapped from inMarket to outMarket Assumes swap happens at oracle price
Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
To Calculate Max Quote Available:
Case 1: SameSide => Remaining quote to get to maxLeverage
Case 2: NOT SameSide && currentLeverage <= maxLeverage => Current opposite position x2 + remaining to get to maxLeverage
Case 3: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition > maxLeverage => strictly reduce current position size
Case 4: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition < maxLeverage => current position + remaining to get to maxLeverage
: Precision QUOTE_PRECISION
Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
tradeSizeAllowed : Precision QUOTE_PRECISION
Optional
currentQuoteAssetValue: BNOptional
currentSpotMarketNetValue: BNOptional
withWeightMarginCategory: MarginCategoryOptional
userAccount: UserAccountPrivate
getPrivate
getcalculates position liabiltiy value in margin system
: Precision QUOTE_PRECISION
calculates position value of a single perp market in margin system
: Precision QUOTE_PRECISION
Optional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleanGets the user's current position for a given perp market. If the user has no position returns undefined
userPerpPosition
Optional
oracleOptional
quotecalculates position value based on oracle
: Precision QUOTE_PRECISION
calculates the market position if the lp position was settled
: the settled userPosition
: the dust base asset amount (ie, < stepsize)
: pnl from settle
Optional
originalPosition: PerpPositioncalculates average exit price (optionally for closing up to 100% of position)
: Precision PRICE_PRECISION
Optional
amountToClose: BNOptional
marginCategory: MarginCategoryOptional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
marketIndex: numberOptional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleanOptional
now: BNOptional
marketIndex: numberOptional
marginCategory: MarginCategoryOptional
includeOpenOrders: booleanOptional
now: BNOptional
marketIndex: numberOptional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleanOptional
now: BNGets the user's current position for a given spot market. If the user has no position returns undefined
userSpotPosition
Optional
marginCategory: MarginCategoryOptional
includeOpenOrders: booleanOptional
now: BNOptional
marginCategory: MarginCategorycalculates TotalCollateral: collateral + unrealized pnl
: Precision QUOTE_PRECISION
Optional
marginCategory: MarginCategorycalculates sum of position value across all positions in margin system
: Precision QUOTE_PRECISION
Optional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleanPrivate
getGet the total position value, excluding any position coming from the given target market
positionValue : Precision QUOTE_PRECISION
Optional
marginCategory: MarginCategoryOptional
liquidationBuffer: BNOptional
includeOpenOrders: booleancalculates unrealized position price pnl
: Precision QUOTE_PRECISION
Optional
withFunding: booleanOptional
marketIndex: numberOptional
withWeightMarginCategory: MarginCategoryOptional
now: BNCalculates a user's max withdrawal amounts for a spot market. If reduceOnly is true, it will return the max withdrawal amount without opening a liability for the user
withdrawalLimit : Precision is the token precision for the chosen SpotMarket
Optional
reduceOnly: booleanCalculate the liquidation price of a perp position, with optional parameter to calculate the liquidation price after a trade
Precision : PRICE_PRECISION
// change in position size to calculate liquidation price for : Precision 10^9
// allow Initial to be passed in if we are trying to calculate price for DLP de-risking
// allows calculating the liquidation price after this offset collateral is added to the user's account (e.g. : what will the liquidation price be for this position AFTER I deposit $x worth of collateral)
Subscribe to User state accounts
SusbcriptionSuccess result
Optional
userAccount: UserAccountGenerated using TypeDoc
Estimates what the user leverage will be after swap