Estimate fixed rate exchange
POST getFixRateForAmount
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.
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.
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
https://api.changelly.com/v2/#getFixRateForAmount
Request
- Request
- Payload
- cURL
Header parameters
Name | Type | Required | Description |
---|---|---|---|
X-Api-Key | string | true | Your API key (SHA256 from Public Key) |
X-Api-Signature | string | true | The query's serialized body signed by your private key according to the RSA-SHA256 method. |
Body parameters
Name | Type | Required | Description |
---|---|---|---|
jsonrpc | string | true | JSON-RPC version. |
id | string | true | Client's custom ID. |
method | string | true | API method name. |
params | object or array of objects | true | Request parameters. You can set params as:
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. |
params
object:
Name | Type | Required | Description |
---|---|---|---|
from | string | true | Payin currency ticker (in lowercase). |
to | string | true | Payout currency ticker (in lowercase). |
amountFrom | string | false | Amount that user is going to exchange. |
amountTo | string | false | Amount that user is going to receive. |
userMetadata | string | false | Escaped JSON. You can use userMetadata to include any additional parameters for customization purposes. To use this feature, please contact us at [email protected]. |
Example 1
{
"jsonrpc": "2.0",
"id": "test",
"method": "getFixRateForAmount",
"params": [
{
"from": "eth",
"to": "btc",
"amountFrom": "5.2"
},
{
"from": "btc",
"to": "eth",
"amountTo": "2.25"
}
]
}
Example with userMetadata
{
"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\"}"
}
]
}
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
- Example
- Success
- Errors
Sample response
{
"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
}
]
}
Response params
Name | Type | Description |
---|---|---|
jsonrpc | string | JSON-RPC version. |
id | string | Client's custom ID. |
result | array of objects | Result. |
result
schema:
Name | Type | Description |
---|---|---|
id | string | Rate 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. |
result | string | Exchange 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 . |
from | string | Payin currency ticker. |
to | string | Payout currency ticker. |
networkFee | string | Commission taken by the network from the amount sent to the user. Displayed in pay-out currency. |
max | string | Maximum exchangeable amount. |
maxFrom | string | Maximum payin amount for which we would be able to perform the exchange. |
maxTo | string | Maximum payout amount for which we would be able to perform the exchange. |
min | string | Minimum exchangeable amount. |
minFrom | string | Minimum payin amount for which we would be able to perform the exchange. |
minTo | string | Minimum payout amount for which we would be able to perform the exchange. |
amountFrom | string | Amount of assets that user will exchange after creating a fixed rate transaction. |
amountTo | string | Fixed exchange amount that user will receive after finishing a fixed-rate transaction using current rateId . |
expiredAt | integer | Unix timestamp in seconds (10 digits) representing the expiration time of the fixed rate. |
fee | string | Exchange fee in pay-out currency. |
Error schema
Name | Type | Description |
---|---|---|
jsonrpc | string | JSON-RPC version. |
id | string | Client's custom ID. |
error | object | Possible errors. |
»code | integer | Error code. |
»message | string | Error message. |
Error codes
Code | Message | Description |
---|---|---|
-32600 | Error: You reached requests limit {limit} rps | You have been sending more than 10 requests per second. |
-32600 | Invalid amount for pair {from_currency}->{to_currency} | The attempt to exchange more currency than a maximal amount or less than the minimal one. |
-32600 | Invalid 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. |
-32602 | Invalid currency: {currency} temporary disabled | This currency is currently disabled. |
-32602 | Invalid currency: {currency} temporary disabled for fix rate transactions | This currency is currently disabled for fix-rate transactions. |
-32602 | Invalid currency: {currency} is temporary disabled on API as output currency | This currency is currently disabled on API as an output currency. |
-32602 | Invalid currency: {currency} is temporary disabled on API as input currency | This currency is currently disabled on API as an input currency. |
-32602 | Invalid currency: {currency} not found | This currency is not listed on Changelly or the ticker is invalid. |
-32602 | Parameter {param} is invalid | You've specified an invalid parameter. |
-32603 | Internal Error or Error | Most likely, the problem is on our side. Further investigation is required. |