Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ClearingHouseUser

Hierarchy

  • ClearingHouseUser

Index

Constructors

Properties

_isSubscribed: boolean = false
accountSubscriber: UserAccountSubscriber
authority: PublicKey
clearingHouse: ClearingHouse
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents, UserAccountEvents, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit">
userAccountPublicKey?: PublicKey

Accessors

  • get isSubscribed(): boolean
  • set isSubscribed(val: boolean): void

Methods

  • Returns the leverage ratio for the account after adding (or subtracting) the given quote size to the given position

    Parameters

    Returns BN

    leverageRatio : Precision TEN_THOUSAND

  • calculateFeeForQuoteAmount(quoteAmount: BN): BN
  • Calculates how much fee will be taken for a given sized trade

    Parameters

    • quoteAmount: BN

    Returns BN

    feeForQuote : Precision QUOTE_PRECISION

  • canBeLiquidated(): [boolean, BN]
  • exists(): Promise<boolean>
  • fetchAccounts(): Promise<void>
  • getBuyingPower(): BN
  • getFreeCollateral(): BN
  • getLeverage(): BN
  • getMarginRatio(): BN
  • getMaxLeverage(category?: "Initial" | "Partial" | "Maintenance"): BN
  • calculates max allowable leverage exceeding hitting requirement category

    params

    category {Initial, Partial, Maintenance}

    Parameters

    • Optional category: "Initial" | "Partial" | "Maintenance"

    Returns BN

    : Precision TEN_THOUSAND

  • 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

    Parameters

    • targetMarketIndex: BN
    • tradeSide: PositionDirection
    • userMaxLeverageSetting: BN

      leverage : Precision TEN_THOUSAND

    Returns BN

    tradeSizeAllowed : Precision QUOTE_PRECISION

  • getPositionValue(marketIndex: BN): BN
  • getTotalCollateral(): BN
  • getTotalPositionValue(): BN
  • getTotalPositionValueExcludingMarket(marketToIgnore: BN): BN
  • Get the total position value, excluding any position coming from the given target market

    Parameters

    • marketToIgnore: BN

    Returns BN

    positionValue : Precision QUOTE_PRECISION

  • getUnrealizedFundingPNL(marketIndex?: BN): BN
  • getUnrealizedPNL(withFunding?: boolean, marketIndex?: BN): BN
  • calculates unrealized position price pnl

    Parameters

    • Optional withFunding: boolean
    • Optional marketIndex: BN

    Returns BN

    : Precision QUOTE_PRECISION

  • getUserAccountPublicKey(): Promise<PublicKey>
  • liquidationPrice(targetMarket: Pick<UserPosition, "marketIndex">, positionBaseSizeChange?: BN, partial?: boolean): BN
  • Calculate the liquidation price of a position, with optional parameter to calculate the liquidation price after a trade

    Parameters

    • targetMarket: Pick<UserPosition, "marketIndex">
    • positionBaseSizeChange: BN = ZERO

      // change in position size to calculate liquidation price for : Precision 10^13

    • partial: boolean = false

    Returns BN

    Precision : MARK_PRICE_PRECISION

  • liquidationPriceAfterClose(positionMarketIndex: BN, closeQuoteAmount: BN): BN
  • Calculates the estimated liquidation price for a position after closing a quote amount of the position.

    Parameters

    • positionMarketIndex: BN
    • closeQuoteAmount: BN

    Returns BN

    : Precision MARK_PRICE_PRECISION

  • liquidationPriceOld(targetMarket: Pick<UserPosition, "marketIndex">, positionBaseSizeChange?: BN, partial?: boolean): BN
  • Calculate the liquidation price of a position, with optional parameter to calculate the liquidation price after a trade

    Parameters

    • targetMarket: Pick<UserPosition, "marketIndex">
    • positionBaseSizeChange: BN = ZERO

      // change in position size to calculate liquidation price for : Precision 10^13

    • partial: boolean = false

    Returns BN

    Precision : MARK_PRICE_PRECISION

  • needsToSettleFundingPayment(): boolean
  • subscribe(): Promise<boolean>
  • unsubscribe(): Promise<void>

Generated using TypeDoc