Skip to main content

Estimate fixed rate exchange

Method returns a fixed exchange estimation for the provided amount. It needs an additional parameter amountFrom or amountTo to estimate a fixed exchange result.

So, the main difference between getFixRateForAmount and getFixRate methods is that getFixRateForAmount fetches fixed amount based on the additional amountFrom or amountTo parameter.

info

Before getting the fixed rate for specific amount, you need to ensure that your amount is greater or equal than minimal amount and less or equal than maximal amount. For this, you need to call getPairsParams method for fetching minimal and maximal amount for a current pair.

If amount will not correspond with the minimal and maximal range for amount, the request will result in error: see the sample error response in the right section.

warning

Although amountFrom and amountTo are optional parameters, it is required to set one of them. If you provide none or both, the request will result in error.

HTTP request

post
/v2/#getFixRateForAmount

Request

Header parameters

Requires authentification.

Body parameters

Requires JSON-RPC 2.0 protocol request body.

info

You can set params as:

  • an object to get result for 1 currency pair
  • an array of 1 object to get result even if you request only 1 currency pair
  • an array of objects when requesting more than 1 currency pair
If you set params as an object without an array, getFixRateForAmount will return an error.
If you set params as an object in an array, getExchangeAmount will return an array without an invalid currency pair or an empty array.

The params parameter schema:

NameTypeRequiredDescription
fromstringtruePayin currency ticker (in lowercase).
tostringtruePayout currency ticker (in lowercase).
amountFromstringfalseAmount that user is going to exchange.
amountTostringfalseAmount that user is going to receive.
userMetadatastringfalseEscaped JSON.
You can use userMetadata to include any additional parameters for customization purposes.
To use this feature, please contact us at [email protected].
Sample request payload
application/json
{
"jsonrpc": "2.0",
"id": "test",
"method": "getFixRateForAmount",
"params": [
{
"from": "eth",
"to": "btc",
"amountFrom": "5.2"
},
{
"from": "btc",
"to": "eth",
"amountTo": "2.25"
}
]
}
Sample request payload with the userMetadata
application/json
{
"jsonrpc": "2.0",
"id": "test",
"method": "getFixRateForAmount",
"params": [
{
"from": "eth",
"to": "btc",
"amountFrom": "5.2",
"userMetadata": "{\"param1\": 50, \"param2\": \"string\", \"param3\": \"50.5189\"}"
},
{
"from": "btc",
"to": "eth",
"amountTo": "2.25",
"userMetadata": "{\"param1\": 50, \"param2\": \"string\", \"param3\": \"50.5189\"}"
}
]
}
Sample cURL
curl --location --request POST 'https://api.changelly.com/v2' \
--header 'X-Api-Key: {{apiKey}}' \
--header 'X-Api-Signature: {{sign}}' \
--data-raw '{
"id": "test",
"jsonrpc": "2.0",
"method": "getFixRateForAmount",
"params": [
{
"from": "eth",
"to": "btc",
"amountFrom": "5.2"
},
{
"from": "btc",
"to": "eth",
"amountTo": "2.25"
}
]
}'

Response

Response parameters

Requires JSON-RPC 2.0 protocol response body.

The result parameter schema:

NameTypeDescription
idstringRate ID that can be used during 1 minute. This time should be enough for user to initiate the exchange. Expired rate id cannot be used for creation of the fixed rate transaction.
id has to be stored somewhere. It will be used as rateId value while calling.
resultstringExchange rate before withholding the network fee.
Important. To calculate the exact amount that the user will get, you need to multiply the amount that the user wants to send to the result and deduct the value of the networkFee.
fromstringPayin currency ticker.
tostringPayout currency ticker.
networkFeestringCommission taken by the network from the amount sent to the user. Displayed in pay-out currency.
maxstringMaximum exchangeable amount.
maxFromstringMaximum payin amount for which we would be able to perform the exchange.
maxTostringMaximum payout amount for which we would be able to perform the exchange.
minstringMinimum exchangeable amount.
minFromstringMinimum payin amount for which we would be able to perform the exchange.
minTostringMinimum payout amount for which we would be able to perform the exchange.
amountFromstringAmount of assets that user will exchange after creating a fixed rate transaction.
amountTostringFixed exchange amount that user will receive after finishing a fixed-rate transaction using current rateId.
expiredAtintegerUnix timestamp in seconds (10 digits) representing the expiration time of the fixed rate.
Sample response
application/json
{
"jsonrpc": "2.0",
"id": "test",
"result": [
{
"id": "f4dd43106d63b65b88955a0b36******ffb7a8480dd32e799431177f",
"result": "0.02556948",
"networkFee": "0.000175",
"from": "eth",
"to": "btc",
"max": "50.000000000000000000",
"maxFrom": "50.000000000000000000",
"maxTo": "1.27847400",
"min": "0.148414210000000000",
"minFrom": "0.148414210000000000",
"minTo": "0.00379488",
"amountFrom": "5.2",
"amountTo": "0.34047438",
"expiredAt": 1664890979
}
]
}

Error response

Error response parameters

Check the error response schema.

Error codes

CodeMessageDescription
-32600Error: You reached requests limit {limit} rpsYou have been sending more than 10 requests per second.
-32602Invalid amount for pair {from_currency}->{to_currency}The attempt to exchange more currency than a maximal amount or less than the minimal one.
-32602Invalid amount for pair {from_currency}->{to_currency}. {limit_type} amount is {limit} {currency}The attempt to exchange currency out of limits. {limit_type} is a “Minimal“ or “Maximum“ value.
-32602Invalid currency: {currency} temporary disabledThis currency is currently disabled.
-32602Invalid currency: {currency} temporary disabled for fix rate transactionsThis currency is currently disabled for fix-rate transactions.
-32602Invalid currency: {currency} is temporary disabled on API as output currencyThis currency is currently disabled on API as an output currency.
-32602Invalid currency: {currency} is temporary disabled on API as input currencyThis currency is currently disabled on API as an input currency.
-32602Invalid currency: {currency} not foundThis currency is not listed on Changelly or the ticker is invalid.
-32602Parameter {param} is invalidYou've specified an invalid parameter.
-32603Internal Error or ErrorMost likely, the problem is on our side. Further investigation is required.