Сrypto to crypto exchange [Private]

Exchange crypto to crypto from available ticker pair.

Method name:/v2/exchange/internal/crypto
Request type:POST

📘

To call private endpoints, you need to get a JWT token or an API key for authentication.

Here you can learn in detail how to successfully authenticate.

This endpoint is used to exchange one cryptocurrency available to the customer for another.

Before making a request to /v2/exchange/internal/crypto, you must make a request to receive rateId to v2/rate/freeze. This request allows you to "freeze" the exchange rate for a certain (defined by the settings) time.

Unlike deposit-with-exchange and exchange-withdrawal transactions, depositPaymentCode/withdrawPaymentCode is NOT required to receive a freeze rate within this type of transaction, as neither deposit nor withdrawal is used in crypto-crypto exchange.

Crypto exchange can acquire the following statuses:

CreatedOperation created.
ProcessingOperation in processing.
OnHoldThe operation is blocked (for example, for checking AML).
DeclinedThe operation is rejected.
CompletedThe operation is successful

To provide information about the status of the operation, a callback service is implemented. The link for receiving callbacks should be provided in the cryptocurrency exchange request.

The duration of execution of a crypto exchange is instant.

Information about the amount of operation fees will be indicated along with other operation details.

Data dictionary

NameTypeParameter typeRequiredRangeDescription
walletIdstringBODYYES-Unique identifier of customer wallet in Kuna Core.
rateIdstringBODYYES-Freeze rate ID from /v2/rate/freeze endpoint.
callbackUrlstringBODYNO-After the exchange is completed, a POST request will be created to the callbackUrl.
externalIdstringBODYYES-Unique ID of operation in your system.

Exemplary request

const url = BASE_URL;
const path = "/v2/exchange/internal/crypto";

const body = {
  walletId: "1f44b1c7-9fd4-4d20-b9a4-7aca3646d0d5",
  rateId: "cbd59181-46e6-4287-95f5-81b8da4c1c97",
  callbackUrl: "https://webhook.site/12495b92-cbe4-4e88-a645-19b1ae5f4c97",
  externalId: "01-01-111",
};

const options = {
  method: "POST",
  headers: {
    accept: "application/json",
    "Content-Type": "application/json",
    "Authorization": `Bearer ${data.accessToken}` // data.accessToken - generated a JWT token via /v2/auth/login.
  },
  body: JSON.stringify(body),
};

fetch(url + path, options)
  .then((response) => response.json())
  .then((showResponse) => console.log(showResponse.data));
import requests

url = BASE_URL
path = "/v2/exchange/internal/crypto"
headers = {
    "accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": "Bearer " + data.accessToken # data.accessToken - generated a JWT token via /v2/auth/login.
}
body = {
  "walletId": '1f44b1c7-9fd4-4d20-b9a4-7aca3646d0d5',
  "rateId": 'cbd59181-46e6-4287-95f5-81b8da4c1c97',
  "callbackUrl": 'https://webhook.site/12495b92-cbe4-4e88-a645-19b1ae5f4c97',
  "externalId": '01-01-111'
}

request = requests.post(url + path, headers=headers, json=body)
print(request.json())

How to call private endpoints here

Swagger here

Response

{
  "data": {
    "address": null,                                                              // Always null for "Сrypto to crypto exchange".
    "blockchainTxId": null,                                                       // Always null for "Сrypto to crypto exchange".
    "callbackUrl": "https://webhook.site/12495b92-cbe4-4e88-a645-19b1ae5f4c97",   // Link to the callback handler.
    "id": "cbd59181-46e6-4287-95f5-81b8da4c1c97",                                 // Internal operation ID.
    "memo": null,                                                                 // Always null for "Сrypto to crypto exchange".
    "createdAt": "2024-03-08T13:39:18.595Z",                                      // Operation сreation time.
    "feeDepositAsset": "USDT",                                                    // Not required for "Сrypto to crypto exchange" request.
    "feeTradeAsset": "ETH",                                                       // Asset in which the fee is paid.
    "feeWithdrawAsset": "ETH",                                                    // Not required for "Сrypto to crypto exchange" request.
    "externalId": "01-01-111",                                                    // External operation ID.
    "feeDeposit": "0",                                                            // Not required for "Сrypto to crypto exchange" request.
    "feeTrade": "0",                                                              // Exchange fee.
    "feeWithdraw": "0",                                                           // Not required for "Сrypto to crypto exchange" request.
    "status": "Created",                                                          // Operation status.
    "network": null,                                                              // Always null for "Сrypto to crypto exchange".
    "rate": "0.00025717",                                                         // Exchange rate.
    "reason": null,                                                               // Reason for stopping the operation.
    "sourceAmount": "11",                                                         // Amount spent.
    "sourceAsset": "USDT",                                                        // Asset of the amount spent.
    "targetAmount": "0.00282887",                                                 // Amount received.
    "targetAsset": "ETH",                                                         // Asset of the amount received.
    "totalFeeSourceAsset": "0",                                                   // Total fees of the base (Source) asset. 
    "totalFeeTargetAsset": "0",                                                   // Total fees of the quote (Target) asset.  
    "type": "CryptoExchange",                                                     // Operation type.
    "walletId": "1f44b1c7-9fd4-4d20-b9a4-7aca3646d0d5",                           // Customer wallet ID.
    "completedAt": "2024-03-08T13:39:18.782Z"                                     // Operation сompletion Time..
  }
}

Callback example

You get a callback for each transaction status.

{
  "data": {
    "id": "cbd59181-46e6-4287-95f5-81b8da4c1c97",
    "memo": null,
    "rate": "0.00025717",
    "type": "CryptoExchange",
    "reason": null,
    "status": "Created | Processing | Completed | Declined",
    "address": null,
    "network": null,
    "feeTrade": "0",
    "metadata": {},
    "walletId": "1f44b1c7-9fd4-4d20-b9a4-7aca3646d0d5",
    "createdAt": "2024-03-08T13:39:18.595Z",
    "externalId": "01-01-111",
    "feeDeposit": "0",
    "callbackUrl": "https://webhook.site/12495b92-cbe4-4e88-a645-19b1ae5f4c97",
    "completedAt": "2024-03-08T13:39:18.782Z",
    "feeWithdraw": "0",
    "sourceAsset": "USDT",
    "targetAsset": "ETH",
    "sourceAmount": "11",
    "targetAmount": "0.00282887",
    "feeTradeAsset": "ETH",
    "initialAmount": null,
    "blockchainTxId": null,
    "feeDepositAsset": "USDT",
    "feeWithdrawAsset": "ETH",
    "totalFeeSourceAsset": "0",
    "totalFeeTargetAsset": "0"
  }
}