SELL
orders) involve specifying the inputAmount
and receiving a calculated outputAmount
, the Buy Order functionality allows users to define their desired outputAmount
of tokens, with the router calculating the required inputAmount
to achieve that target. This provides greater flexibility for users focused on acquiring a specific amount of an asset
How It Works
When orderType is set toBUY
, the GlueX Router fundamentally reverses its calculation logic:
- Input calculation: Instead of starting with a fixed input, the router determines the minimum
inputAmount
(and thusinputToken
) necessary to acquire theoutputAmount
specified by the user, taking into account current market rates, fees and slippage - Market buy optimization: The routing engine optimizes the path to achieve the target outputAmount using the most cost effective
inputAmount
possible
SELL
order behavior, where inputAmount
is predefined, and the outputAmount
is the calculated variable
Configuration
To initiate a Buy Order, you must include theorderType
and outputAmount
parameters in your /v1/price
or /v1/quote
request payload:
orderType | Required Field | Description |
---|---|---|
BUY | outputAmount | Amount of output token to receive |
SELL | inputAmount | Amount of input token to swap |
If
orderType
is not specified, it defaults to SELL
. In this case,
inputAmount
parameter becomes mandatory and outputAmount
will be computed
by the APIBenefits
- Flexibility: Caters directly to users who know exactly how much of a target token they wish to acquire
- Simplified user flow: For specific use cases (eg: buying a fixed amount of governance tokens), this simplifies the user experience by reducing mental calculation
- Optimized input calculation: The router automatically finds the most efficient way to achieve the desired
outputAmount