What a swap costs
The gasPrice hint
Single-chain quotes and swaps require params.gasPrice: a gas price in whole gwei, as a string such as "35". It is a hint. Some liquidity sources use it when they price a route. The fee estimates in dataFeeTransaction don’t use it: dataFeeTransaction.effectiveGasPrice reports the gas price the estimate used, in wei. On chains with EIP-1559 fees it is a maximum fee per gas (maxFeePerGas, about twice the latest base fee plus a priority fee), so treat the estimates as high rather than as the expected cost. In the example on the Get a quote page, the request sends "35" and the estimate uses an effectiveGasPrice of 385800996250 wei, about 386 gwei.
Send the chain’s gas price from your RPC (eth_gasPrice) so sources that use the hint price realistically. Convert it from wei to whole gwei, rounded up, for example Math.ceil(Number(gasPriceWei) / 1e9).toString(). Some sources reject fractional gwei: openOceanV3, for example, fails on "35.2" and drops out of the comparison. The hint doesn’t set the gas price of your transaction: POST /swap returns no gas price, and your wallet or signer sets the fee parameters when it sends. Cross-chain requests don’t take gasPrice.
On a chain whose gas price is below 1 gwei, rounding up sends "1", which is higher than the real price, so the sources that use the hint price gas as more expensive than it is. The API also accepts a decimal hint such as "0.05", but then the sources that reject fractional gwei drop out of the comparison. Send whole gwei, rounded up, so that every source can quote. Either way, the hint doesn’t change what your transaction pays for gas.
Gas estimates in a quote
AddincludeGasInfo: true to a single-chain quote to receive dataFeeTransaction, a gas cost estimate for the winning route:
The example is a 10 USDT quote on Polygon.
estimatedGas of 1578462 at 385800996250 wei per gas gives 608972212142767500 wei, about 0.609 POL. At 0.12285 USD per POL that is about 0.075 USD, which is 0.074812 USDT at a token price of 1 USD.
dataFeeTransaction is based on the winning source’s estimatedGas. If the source returns no estimate, the quote omits both estimatedGas and dataFeeTransaction. If it reports "0", dataFeeTransaction is present but its fee fields are zero. Check for both before you display a cost.
estimatedGas is the liquidity source’s estimate for its own part of the route. It doesn’t include the Olympex contracts, so the swap transaction uses more gas: in measured swaps, two to three and a half times the quoted estimatedGas. Treat dataFeeTransaction, and the transactionFeeInToken and valueToApprove derived from it, as a lower bound. For the transaction you send, estimate gas yourself, as described below.
valueToApprove combines the input amount and the estimated gas, both expressed in the input token. The approval that POST /swap calldata needs is the exact input amount; see Approvals. For a limit order, valueToApprove is the starting point for the allowance: see Limit orders and DCA.
gasMultiplier
params.gasMultiplier scales estimatedGas when includeGasInfo is true:
Because
transactionFee is estimatedGas × effectiveGasPrice, the fee estimate and the USD and token amounts derived from it scale too. The quote echoes the value in quote.gasMultiplier. Use it to show a conservative cost. It changes only the estimate in the quote: POST /swap doesn’t take it, so it has no effect on the calldata.
estimatedGas and gasLimit are estimates
The gas fields come from the liquidity source or provider, and their quality varies:
Estimate gas yourself for the exact transaction you send, then add a buffer, for example 20%:
eth_estimateGas (data shortened)
from is the account you sent to /swap, and to, data (or calldata) and value come from the /swap response, with value converted to hex. The data value above is shortened: send the full calldata. For ERC-20 input, the estimate fails until your approval of contractToApprove is mined, because the simulated swap has no allowance to spend.
Run the estimate for every swap, not only to size the gas limit. A 200 from POST /swap doesn’t guarantee that the calldata executes: a source can build calldata that reverts. If the estimate reverts and the allowance, the balance and the expiry are in order, don’t send the transaction. Build the swap again with the next aggregatorId in the quote’s aggregatorOrder, or, for a cross-chain transfer, request a new quote. See Falling back with aggregatorOrder.
Integrator fees
You can charge your own fee on each trade. Add a top-levelfees object to POST /quotes and POST /swap:
Fees apply only to signed requests from API accounts, and are ignored otherwise. Send the same
fees object on the quote and the swap, so the quote you show matches the calldata you send.
The fee breakdown
Quotes for API accounts include the Olympex protocol fee, shown inintegratorFeeBreakdown. Every quote carries the breakdown, including when you send no fees object: integratorMarginBps and integratorMarginAmount are then 0, and the protocol fee still applies. Its rate is as returned in integratorFeeBreakdown; the examples show 15, which is 0.15%.
protocolFeeBps is in basis points, like feeBps: divide it by 100 to get a percentage. It can be fractional, so parse it as a decimal number, not an integer.outAmount "9979975" with a protocolFeeAmount of "14969", which is 0.014969 USDC. With "feeBps": 25, the same trade returns integratorMarginBps 25, an outAmount of "9954962", and "14932" base units for the protocol fee and "24887" for your fee.
Read the protocol fee rate from each response instead of hard-coding it. For commercial terms, contact partners@olympex.io.
Limit orders and DCA
For limit orders and DCA strategies, Olympex sends the execution transaction and pays its gas in the native token. The maker reimburses it in tokens, so the maker needs native token only for its own approvals. The two products differ in which token pays and in what the allowance must cover:
To estimate a limit order’s gas cost, request a single-chain quote for the same chain, pair and amount with
includeGasInfo: true. dataFeeTransaction.transactionFeeInToken is the estimate in the token sold, and valueToApprove is amount plus that estimate. Both are low: the estimate leaves out the Olympex contracts, and the maker reimburses the gas the execution transaction actually uses, at the gas price it actually pays, converted to the token sold. The order’s gasPrice field doesn’t cap that cost. So add a generous buffer, for example by requesting the quote with gasMultiplier HIGH. Convert the total to base units before you approve it. Order signatures and allowances covers the allowance, including how several orders share it.
The limit-order and DCA endpoints don’t take a fees object: integrator fees apply to POST /quotes and POST /swap. For commercial terms on limit orders and DCA, contact partners@olympex.io.
What this means for your integration
- Send the
gasPricehint from your RPC as whole gwei, rounded up ("1"on a chain below 1 gwei), and let your wallet set the transaction’s fees. - Estimate gas yourself with a buffer for every swap, and don’t send one whose estimate reverts. Use
gasLimitonly as a fallback, anddataFeeTransactionandestimateCostInUSDfor display. - Send the same
feeson/quotesand/swap, and readprotocolFeeBpsas basis points. Liquidity-source fees are already inoutAmount. - For a limit order, approve
amountplus the gas estimate in the token sold, with a generous buffer. For a DCA strategy, approvetotalAmount.
Related
Slippage and price impact
The costs that show up in the output.
Execute a swap
Approve, estimate gas and send.
Get a quote
includeGasInfo, gasMultiplier and fees.Order signatures and allowances
How much to approve for limit orders and DCA.
