Class: Trade
Constructorsβ
constructorβ
β’ new Trade(): Trade
Returnsβ
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β
Name | Type |
---|---|
params | TradeParams |
market | KeyResolvedForCalculation |
bs | BS |
Returnsβ
Object
Name | Type |
---|---|
maxTick | number |
fillVolume | BigNumber |
fillWants | boolean |
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:30
validateSlippageβ
βΈ validateSlippage(slippage?
): number
Parametersβ
Name | Type | Default value |
---|---|---|
slippage | number | 0 |
Returnsβ
number
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:132
comparePricesβ
βΈ comparePrices(price
, priceComparison
, referencePrice
): boolean
Parametersβ
Name | Type |
---|---|
price | BigSource |
priceComparison | "gt" | "lt" |
referencePrice | BigSource |
Returnsβ
boolean
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:141
isPriceBetterβ
βΈ isPriceBetter(price
, referencePrice
, ba
): boolean
Parametersβ
Name | Type |
---|---|
price | undefined | BigSource |
referencePrice | undefined | BigSource |
ba | BA |
Returnsβ
boolean
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:150
isPriceWorseβ
βΈ isPriceWorse(price
, referencePrice
, ba
): boolean
Parametersβ
Name | Type |
---|---|
price | undefined | BigSource |
referencePrice | undefined | BigSource |
ba | BA |
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β
Name | Type | Description |
---|---|---|
bs | BS | buy or sell |
params | TradeParams | trade parameters - see Market.TradeParams |
market | Market | market to trade on |
Returnsβ
Object
raw parameters for a market order to send to Mangrove
Name | Type |
---|---|
maxTick | number |
fillVolume | BigNumber |
fillWants | boolean |
restingOrderParams | undefined | null | RestingOrderParams |
orderType | string |
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β
Name | Type | Description |
---|---|---|
bs | BS | whether to buy or sell base token |
params | TradeParams | trade parameters - see Market.TradeParams |
market | Market | the market to trade on |
overrides | Overrides | ethers 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β
Name | Type | Description |
---|---|---|
market | Market | the market to retract the order on |
ba | BA | whether the offer is a bid or ask |
params | UpdateRestingOrderParams | update parameters - see Market.UpdateRestingOrderParams |
overrides | Overrides | overrides 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β
Name | Type | Description |
---|---|---|
params | UpdateRestingOrderParams | update parameters - see Market.UpdateRestingOrderParams |
market | KeyResolvedForCalculation | the market to retract the order on |
ba | BA | whether the offer is a bid or ask |
tick | number | - |
gives | Big | - |
Returnsβ
Object
the raw parameters to send to the MangroveOrder contract
Name | Type |
---|---|
gives | BigNumber |
tick | number |
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β
Name | Type | Default value | Description |
---|---|---|---|
market | Market | undefined | the market to retract the order on |
ba | BA | undefined | whether the offer is a bid or ask |
id | number | undefined | the offer id |
deprovision | boolean | false | whether to deprovision the offer. If true, the offer's provision will be returned to the maker's balance on Mangrove. |
overrides | Overrides | {} | 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β
Name | Type | Description |
---|---|---|
params | CleanParams | Parameters for the cleaning, specifying the target offers, the side of the market to clean, and optionally the taker to impersonate. |
market | Market | the market to clean on |
overrides | Overrides | ethers 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β
Name | Type | Description |
---|---|---|
params | CleanParams | Parameters for the cleaning, specifying the target offers, the side of the market to clean, and optionally the taker to impersonate. |
market | Market | the 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β
Name | Type | Description |
---|---|---|
bs | BS | buy or sell |
params | TradeParams | The parameters for the trade |
market | Market | The 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β
Name | Type | Description |
---|---|---|
bs | BS | buy or sell |
params | TradeParams | trade parameters - see Market.TradeParams |
market | Market | the 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β
Name | Type |
---|---|
T | extends any [] |
Parametersβ
Name | Type |
---|---|
createTx | (...args : T ) => Promise <ContractTransaction > |
estimateTx | (...args : T ) => Promise <BigNumber > |
gasLowerBound | BigNumberish |
overrides | Overrides |
args | T |
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β
Name | Type |
---|---|
Β«destructuredΒ» | Object |
βΊΒ maxTick | number |
βΊΒ fillVolume | BigNumber |
βΊΒ orderType | BS |
βΊΒ fillWants | boolean |
βΊΒ market | Market |
βΊΒ gasLowerBound | BigNumberish |
overrides | Overrides |
Returnsβ
Promise
<Transaction
<OrderResult
>>
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:585
responseToMarketOrderResultβ
βΈ responseToMarketOrderResult(response
, orderType
, fillWants
, fillVolume
, market
): Promise
<OrderResult
>
Parametersβ
Name | Type |
---|---|
response | Promise <ContractTransaction > |
orderType | BS |
fillWants | boolean |
fillVolume | BigNumber |
market | Market |
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β
Name | Type |
---|---|
Β«destructuredΒ» | Object |
βΊΒ maxTick | number |
βΊΒ fillVolume | BigNumber |
βΊΒ orderType | BS |
βΊΒ fillWants | boolean |
βΊΒ fillOrKill | boolean |
βΊΒ expiryDate | number |
βΊΒ restingParams | undefined | RestingOrderParams |
βΊΒ market | Market |
βΊΒ gasLowerBound | BigNumberish |
overrides | Overrides |
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β
Name | Type |
---|---|
response | Promise <ContractTransaction > |
orderType | BS |
fillWants | boolean |
fillVolume | BigNumber |
market | Market |
offerId | undefined | 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β
Name | Type | Description |
---|---|---|
params | RestingOrderParams | The resting order params. See Market.RestingOrderParams. |
market | Market | The market. |
ba | BA | The 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β
Name | Type |
---|---|
receipt | ContractReceipt |
Returnsβ
OrderResultWithOptionalSummary
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:856
baToBsβ
βΈ baToBs(ba
): BS
Parametersβ
Name | Type |
---|---|
ba | BA |
Returnsβ
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:869
bsToBaβ
βΈ bsToBa(bs
): BA
Parametersβ
Name | Type |
---|---|
bs | BS |
Returnsβ
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β
Name | Type |
---|---|
unitParams | CleanUnitParams |
market | Market |
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β
Name | Type |
---|---|
raw | RawCleanParams |
market | Market |
overrides | Overrides |
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β
Name | Type |
---|---|
response | Promise <ContractTransaction > |
raw | RawCleanParams |
market | Market |
Returnsβ
Promise
<OrderResult
>
Defined inβ
@mangrovedao/mangrove.js/src/util/trade.ts:943