Skip to main content

Trade

createTradeExactIn#

Constructs an exact in trade with the given amount in and route

createTradeExactIn(
tradeRoute: TradeRoute! # The route of the exact in trade and the amount being passed in
): Trade!

createTradeExactOut#

Constructs an exact out trade with the given amount out and route

createTradeExactOut(
tradeRoute: TradeRoute! # The route of the exact out trade and the amount returned
): Trade!

createTradeFromRoute#

Constructs a trade by simulating swaps through the given route

createTradeFromRoute(
tradeRoute: TradeRoute! # The route to swap through and the amount specified, either input or output, depending on the trade type
tradeType: TradeType! # Whether the trade is an exact input or exact output swap
): Trade!

createTradeFromRoutes#

Constructs a trade by simulating swaps through the given routes

createTradeFromRoutes(
tradeRoutes: TradeRoute[]! # The routes to swap through and how much of the amount should be routed through each
tradeType: TradeType! # Whether the trade is an exact input or exact output swap
): Trade!

createUncheckedTrade#

Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade elsewhere and do not have any tick data

createUncheckedTrade(
swap: TradeSwap! # The route to swap through, the amount being passed in, and the amount returned when the trade is executed
tradeType: TradeType! # The type of the trade, either exact in or exact out
): Trade!

createUncheckedTradeWithMultipleRoutes#

Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade elsewhere and do not have any tick data

createUncheckedTradeWithMultipleRoutes(
swaps: TradeSwap[]! # The routes to swap through, the amounts being passed in, and the amounts returned when the trade is executed
tradeType: TradeType! # The type of the trade, either exact in or exact out
): Trade!

tradeInputAmount#

The input amount for the trade assuming no slippage

tradeInputAmount(
swaps: TradeSwap[]! # The routes to swap through, the amounts being passed in, and the amounts returned when the trade is executed
): TokenAmount!

tradeOutputAmount#

The output amount for the trade assuming no slippage

tradeOutputAmount(
swaps: TradeSwap[]! # The routes to swap through, the amounts being passed in, and the amounts returned when the trade is executed
): TokenAmount!

tradeExecutionPrice#

The price expressed in terms of output amount/input amount

tradeExecutionPrice(
inputAmount: TokenAmount! # The trade input amount, e.g. from Trade object or tradeInputAmount(...)
outputAmount: TokenAmount! # The trade output amount, e.g. from Trade object or tradeOutputAmount(...)
): Price!

tradePriceImpact#

Returns the percent difference between the route's mid price and the price impact

tradePriceImpact(
swaps: TradeSwap[]! # The routes to swap through, the amounts being passed in, and the amounts returned when the trade is executed
outputAmount: TokenAmount! # The trade output amount, e.g. from Trade object or tradeOutputAmount(...)
): Fraction!

tradeMinimumAmountOut#

Get the minimum amount that must be received from the trade for the given slippage tolerance

tradeMinimumAmountOut(
slippageTolerance: String! # The tolerance of unfavorable slippage from the execution price of this trade; a decimal number between 0 and 1 (e.g. '0.03') that represents a percentage
amountOut: TokenAmount! # The output amount of the trade, before slippage, e.g. from Trade object or tradeOutputAmount(...)
tradeType: TradeType! # The type of the trade, either exact in or exact out
): TokenAmount!

tradeMaximumAmountIn#

Get the maximum amount in that can be spent via the trade for the given slippage tolerance

tradeMaximumAmountIn(
slippageTolerance: String! # The tolerance of unfavorable slippage from the execution price of this trade; a decimal number between 0 and 1 (e.g. '0.03') that represents a percentage
amountIn: TokenAmount! # The input amount of the trade, before slippage, e.g. from Trade object or tradeInputAmount(...)
tradeType: TradeType! # The type of the trade, either exact in or exact out
): TokenAmount!

tradeWorstExecutionPrice#

Return the execution price after accounting for slippage tolerance

tradeWorstExecutionPrice(
trade: Trade! # Trade for which to calculate execution price
slippageTolerance: String! # The allowed tolerated slippage
): Price!

bestTradeExactIn#

Given a list of pools, and a fixed amount in, returns the top maxNumResults trades that go from an input token amount to an output token, making at most maxHops hops. Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting the amount in among multiple routes.

bestTradeExactIn(
pools: Pool[]! # The pools to consider in finding the best trade
amountIn: TokenAmount! # Exact amount of input currency to spend
tokenOut: Token! # The desired currency out
options: BestTradeOptions # Options used when determining the best trade
): Trade[]!

bestTradeExactOut#

similar to bestTradeExactIn(...) but instead targets a fixed output amount given a list of pools, and a fixed amount out, returns the top maxNumResults trades that go from an input token to an output token amount, making at most maxHops hops note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting the amount in among multiple routes.

bestTradeExactOut(
pools: Pool[]! # The pools to consider in finding the best trade
tokenIn: Token! # The currency to spend
amountOut: TokenAmount! # The desired currency amount out
options: BestTradeOptions # Options used when determining the best trade
): Trade[]!