Skip to main content

Class: KandelDistribution

Title

A distribution of bids and ask for Kandel.

Hierarchy​

Constructors​

constructor​

β€’ new KandelDistribution(pricePoints, stepSize, offers, market): KandelDistribution

Constructor

Parameters​

NameTypeDescription
pricePointsnumberThe number of price points in the distribution.
stepSizenumberThe step size used when transporting funds from an offer to its dual. Should be >=1.
offersOfferDistributionThe distribution of bids and asks.
marketKeyResolvedForCalculationThe key data about the market.

Returns​

KandelDistribution

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:39

Properties​

offers​

β€’ offers: OfferDistribution

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:27


market​

β€’ market: KeyResolvedForCalculation

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:28


pricePoints​

β€’ pricePoints: number

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:29


stepSize​

β€’ stepSize: number

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:30


helper​

β€’ helper: KandelDistributionHelper

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:31

Methods​

calculateOfferGives​

β–Έ calculateOfferGives(offerType, offerCount, totalVolume): Big

Calculates the gives for a single offer of the given type given the total available volume and the count of offers of that type.

Parameters​

NameTypeDescription
offerTypeBAThe type of offer.
offerCountnumberThe count of offers of the given type.
totalVolumeBigThe total available volume.

Returns​

Big

The amount of base or quote to give for the offer.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:60


getOffers​

β–Έ getOffers(offerType): OfferList

Gets all offers of the given type

Parameters​

NameTypeDescription
offerTypeBAThe type of offer.

Returns​

OfferList

All offers of the given type.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:88


getLiveOffers​

β–Έ getLiveOffers(offerType): { index: number ; gives: Big ; tick: number }[]

Gets all live offers of the given type (offers with non-zero gives)

Parameters​

NameTypeDescription
offerTypeBAThe type of offer.

Returns​

{ index: number ; gives: Big ; tick: number }[]

All live offers of the given type (offers with non-zero gives)

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:96


getDeadOffers​

β–Έ getDeadOffers(offerType): { index: number ; gives: Big ; tick: number }[]

Gets all dead offers of the given type (offers with 0 gives)

Parameters​

NameTypeDescription
offerTypeBAThe type of offer.

Returns​

{ index: number ; gives: Big ; tick: number }[]

All dead offers of the given type (offers with 0 gives)

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:104


getOfferAtIndex​

β–Έ getOfferAtIndex(offerType, index): undefined | { index: number ; gives: Big ; tick: number }

Gets the offer at the given index for the given offer type

Parameters​

NameTypeDescription
offerTypeBAThe type of offer.
indexnumberThe index of the offer.

Returns​

undefined | { index: number ; gives: Big ; tick: number }

The offer at the given index for the given offer type.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:115


getOffersWithPrices​

β–Έ getOffersWithPrices(): Object

Gets an offer distribution adorned with prices of offers.

Returns​

Object

An offer distribution adorned with prices of offers.

NameType
bids{ index: number ; gives: Big ; tick: number ; price: Big }[]
asks{ index: number ; gives: Big ; tick: number ; price: Big }[]

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:122


calculateConstantGivesPerOffer​

β–Έ calculateConstantGivesPerOffer(availableBase?, availableQuote?): Object

Calculates the gives for bids and asks based on the available volume for the distribution.

Parameters​

NameTypeDescription
availableBase?BigThe available base to consume.
availableQuote?BigThe available quote to consume.

Returns​

Object

The amount of base or quote to give for each offer.

NameType
askGivesundefined | Big
bidGivesundefined | Big

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:141


getFirstLiveAskIndex​

β–Έ getFirstLiveAskIndex(): number

Gets the index of the first ask in the distribution. If there are no live asks, then the length of the distribution is returned.

Returns​

number

The index of the first ask in the distribution. If there are no live asks, then the length of the distribution is returned.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:166


getLastLiveBidIndex​

β–Έ getLastLiveBidIndex(): number

Gets the index of the last live ask in the distribution. If there are no live bids, then -1 is returned.

Returns​

number

The index of the last live ask in the distribution. If there are no live bids, then -1 is returned.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:176


getOfferedVolumeForDistribution​

β–Έ getOfferedVolumeForDistribution(): Object

Gets the required volume of base and quote for the distribution to be fully provisioned.

Returns​

Object

The offered volume of base and quote for the distribution to be fully provisioned.

NameType
requiredBaseBig
requiredQuoteBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:187


verifyDistribution​

β–Έ verifyDistribution(): void

Verifies the distribution is valid.

Returns​

void

Remarks

Throws if the distribution is invalid. The verification checks that indices are ascending and bids come before asks. The price distribution is not verified, except that the tick of each offer is a multiple of the tick spacing.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:199


getRequiredProvision​

β–Έ getRequiredProvision(params): Promise<Big>

Determines the required provision for the price points in the distribution.

Parameters​

NameTypeDescription
paramsObjectThe parameters used to calculate the provision.
params.marketMarketThe market to get provisions for bids and asks from.
params.gasreqnumberThe gas required to execute a trade.
params.gaspricenumberThe gas price to calculate provision for.

Returns​

Promise<Big>

The provision required for the number of offers.

Remarks

This takes into account that each of the offers represent a price point which can become both an ask and a bid which both require provision.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:251


calculateMinimumInitialGives​

β–Έ calculateMinimumInitialGives(minimumBasePerOffer, minimumQuotePerOffer): Object

Calculates the minimum initial gives for each offer such that all possible gives of fully taken offers at all price points will be above the minimums provided.

Parameters​

NameTypeDescription
minimumBasePerOfferBigThe minimum base to give for each offer.
minimumQuotePerOfferBigThe minimum quote to give for each offer.

Returns​

Object

The minimum initial gives for each offer such that all possible gives of fully taken offers at all price points will be above the minimums provided.

NameType
askGivesBig
bidGivesBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:268


mapAsyncOffers​

β–Έ mapAsyncOffers<T, R>(offers, f): Promise<{ bids: Awaited<R>[] ; asks: Awaited<R>[] }>

Maps bids and asks arrays to a new value using an async function

Type parameters​

Name
T
R

Parameters​

NameType
offersObject
offers.bidsT[]
offers.asksT[]
f(x: T, ba: BA) => Promise<R>

Returns​

Promise<{ bids: Awaited<R>[] ; asks: Awaited<R>[] }>

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:281


mapOffers​

β–Έ mapOffers<T, R>(offers, f): Object

Maps bids and asks arrays to a new value using a function

Type parameters​

Name
T
R

Parameters​

NameType
offersObject
offers.bidsT[]
offers.asksT[]
f(x: T, ba: BA) => R

Returns​

Object

NameType
bidsR[]
asksR[]

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:292

  • Hierarchy
  • Constructors
    • constructor
  • Properties
    • offers
    • market
    • pricePoints
    • stepSize
    • helper
  • Methods
    • calculateOfferGives
    • getOffers
    • getLiveOffers
    • getDeadOffers
    • getOfferAtIndex
    • getOffersWithPrices
    • calculateConstantGivesPerOffer
    • getFirstLiveAskIndex
    • getLastLiveBidIndex
    • getOfferedVolumeForDistribution
    • verifyDistribution
    • getRequiredProvision
    • calculateMinimumInitialGives
    • mapAsyncOffers
    • mapOffers