Skip to main content

Class: TickPriceHelper

Constructors​

constructor​

β€’ new TickPriceHelper(ba, market): TickPriceHelper

Ctor

Parameters​

NameTypeDescription
baBAbids or asks
marketKeyResolvedForCalculationthe decimals for the market

Returns​

TickPriceHelper

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:21

Properties​

ba​

β€’ Readonly ba: BA

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:13


market​

β€’ Readonly market: KeyResolvedForCalculation

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:14

Methods​

priceFromTick​

β–Έ priceFromTick(tick, roundingMode): Big

Calculates the price at a given raw offer list tick.

Parameters​

NameTypeDescription
ticknumbertick to calculate price for (is coerced to nearest bin)
roundingModeRoundingModethe rounding mode for coercing tick to a representable tick. See RoundingMode. roundDown is to a lower price, roundUp is to a higher price.

Returns​

Big

price at tick (not to be confused with offer list ratio).

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:66


tickFromPrice​

β–Έ tickFromPrice(price, roundingMode): number

Calculates the raw offer list tick (coerced to nearest bin) at a given order book price (not to be confused with offer list ratio).

Parameters​

NameTypeDescription
priceBigSourceprice to calculate tick for
roundingModeRoundingModeSee RoundingMode roundDown is to a lower tick, roundUp is to a higher tick.

Returns​

number

raw offer list tick (coerced to nearest bin) for price

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:97


coercePrice​

β–Έ coercePrice(price, roundingMode): Big

Coerces a price to a representable price on a tick. Note that due to rounding, coercing a coerced price may yield a price on an adjacent tick.

Parameters​

NameTypeDescription
priceBigSourceprice to coerce
roundingModeRoundingModeSee RoundingMode roundUp is to a higher price, roundDown is to a lower price.

Returns​

Big

the price coerced to nearest representable tick

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:124


inboundFromOutbound​

β–Έ inboundFromOutbound(tick, outboundAmount, roundingMode): Big

Calculates the inbound amount from an outbound amount at a given tick.

Parameters​

NameTypeDescription
ticknumbertick to calculate the amount for (coerced to nearest bin)
outboundAmountBigSourceamount to calculate the inbound amount for
roundingModeRoundingModeSee RoundingMode. roundDown is to a lower tick, roundUp is to a higher tick and usage of inboundFromOutboundUp

Returns​

Big

inbound amount.

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:154


outboundFromInbound​

β–Έ outboundFromInbound(tick, inboundAmount, roundingMode): Big

Calculates the outbound amount from an inbound amount at a given tick.

Parameters​

NameTypeDescription
ticknumbertick to calculate the amount for (coerced to nearest bin)
inboundAmountBigSourceamount to calculate the outbound amount for
roundingModeRoundingModeSee RoundingMode. roundDown is to a lower tick, roundUp is to a higher tick and usage of outboundFromInboundUp

Returns​

Big

inbound amount.

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:179


volumeForGivesAndPrice​

β–Έ volumeForGivesAndPrice(gives, price): Big

Determine the volume of an offer from the amount of token to give and the price.

Parameters​

NameTypeDescription
givesBigSourceamount of token to give
priceBigSourceprice of the offer

Returns​

Big

the volume of the offer.

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:203


tickFromVolumes​

β–Έ tickFromVolumes(inboundVolume, outboundVolume, roundingMode): number

Calculates the tick (coerced to nearest bin) from inbound and outbound volumes.

Parameters​

NameTypeDescription
inboundVolumeBigSourceinbound amount to calculate the tick for
outboundVolumeBigSourceoutbound amount to calculate the tick for
roundingModeRoundingModeSee RoundingMode. roundDown is to a lower tick, roundUp is to a higher tick.

Returns​

number

raw offer list tick (coerced to nearest bin) for volumes

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:214


coerceTick​

β–Έ coerceTick(tick, roundingMode): number

Coerce a tick to its nearest bin

Parameters​

NameTypeDescription
ticknumbertick to coerce
roundingModeRoundingModeSee RoundingMode. roundDown is to a lower tick, roundUp is to a higher tick.

Returns​

number

tick coerced to its nearest bin

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:257


isTickExact​

β–Έ isTickExact(tick): boolean

Check if tick is exact, as in it does not change when coerced due to tick spacing

Parameters​

NameTypeDescription
ticknumbertick to check

Returns​

boolean

true if tick is exact; otherwise, false

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:268


rawRatioFromTick​

β–Έ rawRatioFromTick(tick, roundingMode): Big

Calculates the raw ratio as a Big with big precision.

NB: Raw ratios do not take token decimals into account.

Parameters​

NameTypeDescription
ticknumbertick to calculate the ratio for (coerced to nearest bin)
roundingModeRoundingModethe rounding mode for coercing tick to a representable tick. See RoundingMode

Returns​

Big

ratio as a Big.

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:321


tickFromRawRatio​

β–Έ tickFromRawRatio(rawRatio, roundingMode): number

Converts a raw ratio as a Big to a tick (coerced to nearest bin).

NB: Raw ratios do not take token decimals into account. NB: This is a lossy conversions since ticks are discrete and ratios are not.

Parameters​

NameTypeDescription
rawRatioBiginbound/outbound ratio to calculate the tick for
roundingModeRoundingModethe rounding mode for coercing tick to a representable tick. See RoundingMode

Returns​

number

a tick (coerced to nearest bin) that approximates the given ratio.

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:345


rawRatioToMantissaExponent​

β–Έ rawRatioToMantissaExponent(ratio): Object

Parameters​

NameType
ratioBig

Returns​

Object

NameType
manBigNumber
expBigNumber

Defined in​

@mangrovedao/mangrove.js/src/util/tickPriceHelper.ts:366

  • Constructors
    • constructor
  • Properties
    • ba
    • market
  • Methods
    • priceFromTick
    • tickFromPrice
    • coercePrice
    • inboundFromOutbound
    • outboundFromInbound
    • volumeForGivesAndPrice
    • tickFromVolumes
    • coerceTick
    • isTickExact
    • rawRatioFromTick
    • tickFromRawRatio
    • rawRatioToMantissaExponent