Skip to main content

Class: Trade

Constructors​

constructor​

β€’ new Trade(): Trade

Returns​

Trade

Properties​

tradeEventManagement​

β€’ tradeEventManagement: TradeEventManagement

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:25

Methods​

getParamsForTrade​

β–Έ getParamsForTrade(params, market, bs): Object

Get raw parameters to send to Mangrove for a buy or sell order for the given trade and market parameters.

Parameters​

NameType
paramsTradeParams
marketKeyResolvedForCalculation
bsBS

Returns​

Object

NameType
maxTicknumber
fillVolumeBigNumber
fillWantsboolean

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:30


validateSlippage​

β–Έ validateSlippage(slippage?): number

Parameters​

NameTypeDefault value
slippagenumber0

Returns​

number

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:132


comparePrices​

β–Έ comparePrices(price, priceComparison, referencePrice): boolean

Parameters​

NameType
priceBigSource
priceComparison"gt" | "lt"
referencePriceBigSource

Returns​

boolean

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:141


isPriceBetter​

β–Έ isPriceBetter(price, referencePrice, ba): boolean

Parameters​

NameType
priceundefined | BigSource
referencePriceundefined | BigSource
baBA

Returns​

boolean

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:150


isPriceWorse​

β–Έ isPriceWorse(price, referencePrice, ba): boolean

Parameters​

NameType
priceundefined | BigSource
referencePriceundefined | BigSource
baBA

Returns​

boolean

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:169


getRawParams​

β–Έ getRawParams(bs, params, market): Object

Get raw parameters to send to Mangrove for a buy or sell order for the given trade and market parameters.

Parameters​

NameTypeDescription
bsBSbuy or sell
paramsTradeParamstrade parameters - see Market.TradeParams
marketMarketmarket to trade on

Returns​

Object

raw parameters for a market order to send to Mangrove

NameType
maxTicknumber
fillVolumeBigNumber
fillWantsboolean
restingOrderParamsundefined | null | RestingOrderParams
orderTypestring

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:194


order​

β–Έ order(bs, params, market, overrides?): Promise<Transaction<OrderResult>>

Market order. Will attempt to buy or sell base token using quote tokens.

Parameters​

NameTypeDescription
bsBSwhether to buy or sell base token
paramsTradeParamstrade parameters - see Market.TradeParams
marketMarketthe market to trade on
overridesOverridesethers overrides for the transaction

Returns​

Promise<Transaction<OrderResult>>

a promise that resolves to the transaction response and the result of the trade

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:228


updateRestingOrder​

β–Έ updateRestingOrder(market, ba, params, overrides?): Promise<Transaction<void>>

Update a resting order posted by MangroveOrder.

Parameters​

NameTypeDescription
marketMarketthe market to retract the order on
baBAwhether the offer is a bid or ask
paramsUpdateRestingOrderParamsupdate parameters - see Market.UpdateRestingOrderParams
overridesOverridesoverrides for the transaction

Returns​

Promise<Transaction<void>>

a promise that resolves to the transaction response and the result of the update.

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:277


getRawUpdateRestingOrderParams​

β–Έ getRawUpdateRestingOrderParams(params, market, ba, tick, gives): Object

Gets parameters to send to function market.mgv.orderContract.updateOffer.

Parameters​

NameTypeDescription
paramsUpdateRestingOrderParamsupdate parameters - see Market.UpdateRestingOrderParams
marketKeyResolvedForCalculationthe market to retract the order on
baBAwhether the offer is a bid or ask
ticknumber-
givesBig-

Returns​

Object

the raw parameters to send to the MangroveOrder contract

NameType
givesBigNumber
ticknumber

Defined in​

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


retractRestingOrder​

β–Έ retractRestingOrder(market, ba, id, deprovision?, overrides?): Promise<Transaction<void>>

Retract a resting order posted by MangroveOrder.

Parameters​

NameTypeDefault valueDescription
marketMarketundefinedthe market to retract the order on
baBAundefinedwhether the offer is a bid or ask
idnumberundefinedthe offer id
deprovisionbooleanfalsewhether to deprovision the offer. If true, the offer's provision will be returned to the maker's balance on Mangrove.
overridesOverrides{}overrides for the transaction

Returns​

Promise<Transaction<void>>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:401


clean​

β–Έ clean(params, market, overrides?): Promise<{ result: Promise<CleanResult> ; response: Promise<ContractTransaction> }>

Clean a set of given offers.

Parameters​

NameTypeDescription
paramsCleanParamsParameters for the cleaning, specifying the target offers, the side of the market to clean, and optionally the taker to impersonate.
marketMarketthe market to clean on
overridesOverridesethers overrides for the transaction

Returns​

Promise<{ result: Promise<CleanResult> ; response: Promise<ContractTransaction> }>

a promise that resolves to the transaction response and the result of the cleaning.

See

Market.CleanParams for a more thorough description of cleaning parameters.

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:440


getRawCleanParams​

β–Έ getRawCleanParams(params, market): Promise<RawCleanParams>

Gets parameters to send to function market.mgv.cleanerContract.cleanByImpersonation.

Parameters​

NameTypeDescription
paramsCleanParamsParameters for the cleaning, specifying the target offers, the side of the market to clean, and optionally the taker to impersonate.
marketMarketthe market to clean on

Returns​

Promise<RawCleanParams>

a promise that resolves to the raw parameters to send to the cleaner contract

Remarks

See

Market.CleanParams for a more thorough description of cleaning parameters.

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:474


estimateGas​

β–Έ estimateGas(bs, params, market): Promise<BigNumber>

Estimate amount of gas for a buy or sell order for the given volume.

Parameters​

NameTypeDescription
bsBSbuy or sell
paramsTradeParamsThe parameters for the trade
marketMarketThe market

Returns​

Promise<BigNumber>

an estimate of the gas required for the trade

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:507


simulateGas​

β–Έ simulateGas(bs, params, market): Promise<undefined | BigNumber>

Simulate the gas required for a market order.

Parameters​

NameTypeDescription
bsBSbuy or sell
paramsTradeParamstrade parameters - see Market.TradeParams
marketMarketthe market to trade on

Returns​

Promise<undefined | BigNumber>

an estimate of the gas required for the trade

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:531


createTxWithOptionalGasEstimation​

β–Έ createTxWithOptionalGasEstimation<T>(createTx, estimateTx, gasLowerBound, overrides, args): Promise<ContractTransaction>

Type parameters​

NameType
Textends any[]

Parameters​

NameType
createTx(...args: T) => Promise<ContractTransaction>
estimateTx(...args: T) => Promise<BigNumber>
gasLowerBoundBigNumberish
overridesOverrides
argsT

Returns​

Promise<ContractTransaction>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:554


marketOrder​

β–Έ marketOrder(Β«destructuredΒ», overrides): Promise<Transaction<OrderResult>>

Low level Mangrove market order. If orderType is "buy", the base/quote market will be used,

If orderType is "sell", the quote/base market will be used,

fillWants defines whether the market order stops immediately once wants tokens have been purchased or whether it tries to keep going until gives tokens have been spent.

In addition, slippage defines an allowed slippage in % of the amount of quote token.

Returns a promise for market order result after 1 confirmation. Will throw on same conditions as ethers.js transaction.wait.

Parameters​

NameType
Β«destructuredΒ»Object
β€ΊΒ maxTicknumber
β€ΊΒ fillVolumeBigNumber
β€ΊΒ orderTypeBS
β€ΊΒ fillWantsboolean
β€ΊΒ marketMarket
β€ΊΒ gasLowerBoundBigNumberish
overridesOverrides

Returns​

Promise<Transaction<OrderResult>>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:585


responseToMarketOrderResult​

β–Έ responseToMarketOrderResult(response, orderType, fillWants, fillVolume, market): Promise<OrderResult>

Parameters​

NameType
responsePromise<ContractTransaction>
orderTypeBS
fillWantsboolean
fillVolumeBigNumber
marketMarket

Returns​

Promise<OrderResult>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:638


mangroveOrder​

β–Έ mangroveOrder(Β«destructuredΒ», overrides): Promise<Transaction<OrderResult>>

Low level resting order.

Returns a promise for market order result after 1 confirmation.

Will throw on same conditions as ethers.js transaction.wait.

Parameters​

NameType
Β«destructuredΒ»Object
β€ΊΒ maxTicknumber
β€ΊΒ fillVolumeBigNumber
β€ΊΒ orderTypeBS
β€ΊΒ fillWantsboolean
β€ΊΒ fillOrKillboolean
β€ΊΒ expiryDatenumber
β€ΊΒ restingParamsundefined | RestingOrderParams
β€ΊΒ marketMarket
β€ΊΒ gasLowerBoundBigNumberish
overridesOverrides

Returns​

Promise<Transaction<OrderResult>>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:673


responseToMangroveOrderResult​

β–Έ responseToMangroveOrderResult(response, orderType, fillWants, fillVolume, market, offerId): Promise<OrderResult>

Parameters​

NameType
responsePromise<ContractTransaction>
orderTypeBS
fillWantsboolean
fillVolumeBigNumber
marketMarket
offerIdundefined | number

Returns​

Promise<OrderResult>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:745


getRestingOrderParams​

β–Έ getRestingOrderParams(params, market, ba): Promise<{ provision: BigSource ; restingOrderGasreq: number ; gaspriceFactor: number ; restingOrderBa: string }>

Determines the parameters for a resting order which can be provided via default configuration value.

Parameters​

NameTypeDescription
paramsRestingOrderParamsThe resting order params. See Market.RestingOrderParams.
marketMarketThe market.
baBAThe BA of the taker order; the resting order will be the opposite.

Returns​

Promise<{ provision: BigSource ; restingOrderGasreq: number ; gaspriceFactor: number ; restingOrderBa: string }>

The resting order parameters.

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:810


initialResult​

β–Έ initialResult(receipt): OrderResultWithOptionalSummary

Parameters​

NameType
receiptContractReceipt

Returns​

OrderResultWithOptionalSummary

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:856


baToBs​

β–Έ baToBs(ba): BS

Parameters​

NameType
baBA

Returns​

BS

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:869


bsToBa​

β–Έ bsToBa(bs): BA

Parameters​

NameType
bsBS

Returns​

BA

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:873


getCleanRawParamsFromUnitParams​

β–Έ getCleanRawParamsFromUnitParams(unitParams, market): Promise<RawCleanParams>

Gets parameters to send to functions market.mgv.contract.cleanByImpersonation.

Parameters​

NameType
unitParamsCleanUnitParams
marketMarket

Returns​

Promise<RawCleanParams>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:880


cleanWithRawParameters​

β–Έ cleanWithRawParameters(raw, market, overrides): Promise<{ result: Promise<DirtyOrderResult> ; response: Promise<ContractTransaction> }>

Low level sniping of targets.

Returns a promise for clean result after 1 confirmation. Will throw on same conditions as ethers.js transaction.wait.

Parameters​

NameType
rawRawCleanParams
marketMarket
overridesOverrides

Returns​

Promise<{ result: Promise<DirtyOrderResult> ; response: Promise<ContractTransaction> }>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:920


responseToCleanResult​

β–Έ responseToCleanResult(response, raw, market): Promise<OrderResult>

Parameters​

NameType
responsePromise<ContractTransaction>
rawRawCleanParams
marketMarket

Returns​

Promise<OrderResult>

Defined in​

@mangrovedao/mangrove.js/src/util/trade.ts:943

  • Constructors
    • constructor
  • Properties
    • tradeEventManagement
  • Methods
    • getParamsForTrade
    • validateSlippage
    • comparePrices
    • isPriceBetter
    • isPriceWorse
    • getRawParams
    • order
    • updateRestingOrder
    • getRawUpdateRestingOrderParams
    • retractRestingOrder
    • clean
    • getRawCleanParams
    • estimateGas
    • simulateGas
    • createTxWithOptionalGasEstimation
    • marketOrder
    • responseToMarketOrderResult
    • mangroveOrder
    • responseToMangroveOrderResult
    • getRestingOrderParams
    • initialResult
    • baToBs
    • bsToBa
    • getCleanRawParamsFromUnitParams
    • cleanWithRawParameters
    • responseToCleanResult