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.
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, such as "35.2", and drop 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
A single-chain quote returnsestimatedGas: the winning source’s estimate, in gas units, for its own part of the route. The quote doesn’t turn it into a fee. To show a cost, multiply it by the chain’s gas price from your RPC (eth_gasPrice), which gives the fee in wei of the native token.
estimatedGas 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 a fee computed from it as a lower bound. If the source gives no estimate, the quote reports "0" or omits estimatedGas, so check for both before you display a cost. For the transaction you send, estimate gas yourself, as described below.
gasMultiplier
Single-chain quotes accept params.gasMultiplier, one of NONE (the default), LOW, MEDIUM and HIGH, and echo it in quote.gasMultiplier. It doesn’t change the quote: estimatedGas is the same for every value. POST /swap doesn’t take it, so it has no effect on the calldata either.
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 dexHash in the quote’s aggregatorOrder, and compare its outAmount and minOutAmount before you show it, 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 is part of each signed request: Olympex stores no fee on your account, and rotating your API key doesn’t change it. A child account of a partner can’t call POST /quotes or POST /swap: it gets 403 FORBIDDEN, and the partner account signs quotes and swaps instead.
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 "9993151" with a protocolFeeAmount of "14989", which is 0.014989 USDC. The example with "feeBps": 25 returns integratorMarginBps 25, an outAmount of "9973236", and "14959" base units for the protocol fee and "24933" for your fee. The two were captured moments apart, so prices moved too.
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:
The API doesn’t return an estimate of a limit order’s execution fee, so estimate it yourself. Request a single-chain quote for the same chain, pair and amount, and multiply its
estimatedGas by the chain’s gas price (eth_gasPrice) to get a fee in wei of the native token. Multiply that by a generous buffer, for example 4: estimatedGas 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. To convert the fee to the token sold, quote the token sold to the native token (0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) for the order’s amount: the fee in base units of the token sold is the fee in wei times amount in base units, divided by that quote’s outAmount, rounded up. If estimatedGas is missing or "0", don’t size the allowance from it: request the quote again. Create a limit order has the code, and 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, andestimatedGasandestimateCostInUSDfor display. - Send the same
feeson/quotesand/swap, and readprotocolFeeBpsas basis points. Liquidity-source fees are already inoutAmount. - For a limit order, approve
amountplus your own estimate of the gas cost 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
orderBy, excludeMetaAggregatorId and fees.Order signatures and allowances
How much to approve for limit orders and DCA.
