🔸Price API
Step by step guide to set up the Marswap Aggregator API
Last updated
Step by step guide to set up the Marswap Aggregator API
Last updated
GET
/v1/swap/price
This endpoint can be used to request the amount of token received for a swap between two tokens.
Name | Value |
---|---|
Parameter | Description | Required | Type |
---|---|---|---|
Parameter | Description |
---|---|
An "allowance" refers to the amount of a specific ERC-20 token that an owner has approved another Ethereum address to swap. In our case, we would like the Marswap Aggregator smart contract to trade ERC20 tokens.
To do so, we will need to give an allowance to the allowanceTarget
parameter that's returned by the API. The allowanceTarget
is the the target contract address, in our case the Marswap Aggregator smart contract address on the relevant network.
For swaps with "ETH" as sellToken, wrapping "ETH" to "WETH" or unwrapping "WETH" to "ETH" no allowance is needed.
Read more here about setting token allowances.
Marswap-Api-Key
string
sellToken
The address of the token you want to sell.
Yes
string
buyToken
The address of the token you want to buy.
Yes
string
sellAmount
The amount of sell token to swap in base units.
Yes
number
buyTokenOrSellTokenHasFees
Boolean indicating if buy or sell token has fees/taxes.
No. Default is true
boolean
slippagePercentage
Maximum slippage percentage for the swap.
Yes
number
integratorId
The integrator ID provided by the Marswap team for authentication.
Yes
string
buyTokenPercentageFee
The percentage of the buyAmount that will be sent to the feeRecipient as affiliate fees. Maximum is 1%.
No
number
feeRecipient
The wallet address that will receive affiliate fees from each trade.
No
string
chainId
The blockchain network ID.
price
The calculated swap price of the buy token relative to the sell token.
minimumPrice
The minimum acceptable swap price of the buy token relative to the sell token considering slippage.
value
The amount of ETH in Wei to be sent in the transaction.
buyTokenAddress
The address of the token you want to buy.
buyAmount
The calculated amount of buy token to receive in base units.
sellTokenAddress
The address of the token you want to sell.
sellAmount
The amount of sell token to swap in base units.
sellTokenToEthRate
The exchange rate of sell token to ETH. Multiply this by the USD price of ETH to get the USD value of the sell token.
buyTokenToEthRate
The exchange rate of buy token to ETH. Multiply this by the USD price of ETH to get the USD value of the buy token.
swapFeeInEth
The swap fee in ETH.
allowanceTarget
The address of the contract to grant approval allowance to for the swap.