Class: GeneralKandelDistribution
Title
A general distribution of bids and ask for Kandel fully specified as bids and asks with tick and volumes and no other parameters.
Hierarchyβ
β³
GeneralKandelDistribution
Constructorsβ
constructorβ
β’ new GeneralKandelDistribution(params
): GeneralKandelDistribution
Constructor
Parametersβ
Name | Type | Description |
---|---|---|
params | Object | - |
params.pricePoints | number | The number of price points in the distribution. |
params.stepSize | number | The step size used when transporting funds from an offer to its dual. Should be >=1. |
params.offers | OfferDistribution | The distribution of bids and asks. |
params.market | KeyResolvedForCalculation | The key data about the market. |
Returnsβ
Overridesβ
KandelDistribution.constructor
Defined inβ
@mangrovedao/mangrove.js/src/kandel/generalKandelDistribution.ts:15
Propertiesβ
offersβ
β’ offers: OfferDistribution
Inherited fromβ
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:27
marketβ
β’ market: KeyResolvedForCalculation
Inherited fromβ
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:28
pricePointsβ
β’ pricePoints: number
Inherited fromβ
KandelDistribution.pricePoints
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:29
stepSizeβ
β’ stepSize: number
Inherited fromβ
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:30
helperβ
β’ helper: KandelDistributionHelper
Inherited fromβ
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:31
Methodsβ
chunkDistributionβ
βΈ chunkDistribution(maxOffersInChunk
): OfferDistribution
[]
Split a distribution into chunks according to the maximum number of offers in a single chunk.
Parametersβ
Name | Type | Description |
---|---|---|
maxOffersInChunk | number | The maximum number of offers in a single chunk. |
Returnsβ
The chunks.
Defined inβ
@mangrovedao/mangrove.js/src/kandel/generalKandelDistribution.ts:73
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β
Name | Type | Description |
---|---|---|
offerType | BA | The type of offer. |
offerCount | number | The count of offers of the given type. |
totalVolume | Big | The total available volume. |
Returnsβ
Big
The amount of base or quote to give for the offer.
Inherited fromβ
KandelDistribution.calculateOfferGives
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:60
getOffersβ
βΈ getOffers(offerType
): OfferList
Gets all offers of the given type
Parametersβ
Name | Type | Description |
---|---|---|
offerType | BA | The type of offer. |
Returnsβ
All offers of the given type.
Inherited fromβ
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β
Name | Type | Description |
---|---|---|
offerType | BA | The type of offer. |
Returnsβ
{ index
: number
; gives
: Big
; tick
: number
}[]
All live offers of the given type (offers with non-zero gives)
Inherited fromβ
KandelDistribution.getLiveOffers
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β
Name | Type | Description |
---|---|---|
offerType | BA | The type of offer. |
Returnsβ
{ index
: number
; gives
: Big
; tick
: number
}[]
All dead offers of the given type (offers with 0 gives)
Inherited fromβ
KandelDistribution.getDeadOffers
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β
Name | Type | Description |
---|---|---|
offerType | BA | The type of offer. |
index | number | The index of the offer. |
Returnsβ
undefined
| { index
: number
; gives
: Big
; tick
: number
}
The offer at the given index for the given offer type.
Inherited fromβ
KandelDistribution.getOfferAtIndex
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.
Name | Type |
---|---|
bids | { index : number ; gives : Big ; tick : number ; price : Big }[] |
asks | { index : number ; gives : Big ; tick : number ; price : Big }[] |
Inherited fromβ
KandelDistribution.getOffersWithPrices
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β
Name | Type | Description |
---|---|---|
availableBase? | Big | The available base to consume. |
availableQuote? | Big | The available quote to consume. |
Returnsβ
Object
The amount of base or quote to give for each offer.
Name | Type |
---|---|
askGives | undefined | Big |
bidGives | undefined | Big |
Inherited fromβ
KandelDistribution.calculateConstantGivesPerOffer
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.
Inherited fromβ
KandelDistribution.getFirstLiveAskIndex
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.
Inherited fromβ
KandelDistribution.getLastLiveBidIndex
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.
Name | Type |
---|---|
requiredBase | Big |
requiredQuote | Big |
Inherited fromβ
KandelDistribution.getOfferedVolumeForDistribution
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.
Inherited fromβ
KandelDistribution.verifyDistribution
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β
Name | Type | Description |
---|---|---|
params | Object | The parameters used to calculate the provision. |
params.market | Market | The market to get provisions for bids and asks from. |
params.gasreq | number | The gas required to execute a trade. |
params.gasprice | number | The 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.
Inherited fromβ
KandelDistribution.getRequiredProvision
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β
Name | Type | Description |
---|---|---|
minimumBasePerOffer | Big | The minimum base to give for each offer. |
minimumQuotePerOffer | Big | The 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.
Name | Type |
---|---|
askGives | Big |
bidGives | Big |
Inherited fromβ
KandelDistribution.calculateMinimumInitialGives
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β
Name | Type |
---|---|
offers | Object |
offers.bids | T [] |
offers.asks | T [] |
f | (x : T , ba : BA ) => Promise <R > |
Returnsβ
Promise
<{ bids
: Awaited
<R
>[] ; asks
: Awaited
<R
>[] }>
Inherited fromβ
KandelDistribution.mapAsyncOffers
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β
Name | Type |
---|---|
offers | Object |
offers.bids | T [] |
offers.asks | T [] |
f | (x : T , ba : BA ) => R |
Returnsβ
Object
Name | Type |
---|---|
bids | R [] |
asks | R [] |
Inherited fromβ
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:292