@swapx-lib/v3-sdk / Exports / Trade
Class: Trade<TInput, TOutput, TTradeType>
Represents a trade executed against a set of routes where some percentage of the input is split across each route.
Each route has its own set of pools. Pools can not be re-used across routes.
Does not account for slippage, i.e., changes in price environment that can occur between the time the trade is submitted and when it is executed.
Type parameters
| Name | Type | Description |
|---|---|---|
TInput | extends Currency | The input token, either Ether or an ERC-20 |
TOutput | extends Currency | The output token, either Ether or an ERC-20 |
TTradeType | extends TradeType | The trade type, either exact input or exact output |
Table of contents
Constructors
Properties
Accessors
Methods
- maximumAmountIn
- minimumAmountOut
- worstExecutionPrice
- bestTradeExactIn
- bestTradeExactOut
- createUncheckedTrade
- createUncheckedTradeWithMultipleRoutes
- exactIn
- exactOut
- fromRoute
- fromRoutes
Constructors
constructor
• Private new Trade<TInput, TOutput, TTradeType>(__namedParameters)
Construct a trade by passing in the pre-computed property values
Type parameters
| Name | Type |
|---|---|
TInput | extends Currency |
TOutput | extends Currency |
TTradeType | extends TradeType |
Parameters
| Name | Type |
|---|---|
__namedParameters | Object |
__namedParameters.routes | { inputAmount: CurrencyAmount<TInput> ; outputAmount: CurrencyAmount<TOutput> ; route: Route<TInput, TOutput> }[] |
__namedParameters.tradeType | TTradeType |
Defined in
entities/trade.ts:397
Properties
_executionPrice
• Private _executionPrice: undefined | Price<TInput, TOutput>
The cached result of the computed execution price
Defined in
entities/trade.ts:143
_inputAmount
• Private _inputAmount: undefined | CurrencyAmount<TInput>
The cached result of the input amount computation
Defined in
entities/trade.ts:97
_outputAmount
• Private _outputAmount: undefined | CurrencyAmount<TOutput>
The cached result of the output amount computation
Defined in
entities/trade.ts:120
_priceImpact
• Private _priceImpact: undefined | Percent
The cached result of the price impact computation
Defined in
entities/trade.ts:164
swaps
• Readonly swaps: { inputAmount: CurrencyAmount<TInput> ; outputAmount: CurrencyAmount<TOutput> ; route: Route<TInput, TOutput> }[]
The swaps of the trade, i.e. which routes and how much is swapped in each that make up the trade.
Defined in
entities/trade.ts:82
tradeType
• Readonly tradeType: TTradeType
The type of the trade, either exact in or exact out.
Defined in
entities/trade.ts:91
Accessors
executionPrice
• get executionPrice(): Price<TInput, TOutput>
The price expressed in terms of output amount/input amount.
Returns
Price<TInput, TOutput>
Defined in
entities/trade.ts:148
inputAmount
• get inputAmount(): CurrencyAmount<TInput>
The input amount for the trade assuming no slippage.
Returns
CurrencyAmount<TInput>
Defined in
entities/trade.ts:102
outputAmount
• get outputAmount(): CurrencyAmount<TOutput>
The output amount for the trade assuming no slippage.
Returns
CurrencyAmount<TOutput>
Defined in
entities/trade.ts:125
priceImpact
• get priceImpact(): Percent
Returns the percent difference between the route's mid price and the price impact
Returns
Percent
Defined in
entities/trade.ts:169
route
• get route(): Route<TInput, TOutput>
Deprecated
Deprecated in favor of 'swaps' property. If the trade consists of multiple routes this will return an error.
When the trade consists of just a single route, this returns the route of the trade, i.e. which pools the trade goes through.
Returns
Route<TInput, TOutput>