OxaPay Docs
v1
v1
  • Introduction
    • Welcome to OxaPay
    • Integrations
      • Payment Link
      • Donation Service
      • Merchant Service
      • Payout Service
      • Swap Service
      • Plugins
        • WooCommerce
        • WISECP
        • Clientexec
        • Blesta
        • WHMCS
        • PrestaShop
        • Easy Digital Downloads
        • Paid Memberships Pro
        • Gravity Forms
        • Restrict Content Pro
        • VirtueMart
  • API Reference
    • Payment
      • Generate Invoice
      • Generate White Label
      • Generate Static Address
      • Revoking Static Address
      • Static Address List
      • Payment Information
      • Payment History
      • Accepted Currencies
      • Payment Status Table
    • Payout
      • Generate Payout
      • Payout Information
      • Payout History
      • Payout Status Table
    • Swap
      • Swap Request
      • Swap History
      • Swap Pairs
      • Swap Calculate
      • Swap Rate
    • Common
      • Account Balance
      • Prices
      • Supported Currencies
      • Supported Fiat Currencies
      • Supported Networks
      • System Status
    • Error
  • Webhook
  • Use Cases
Powered by GitBook
On this page
  • API Request Sample Codes
  • API Response Example
  1. API Reference
  2. Swap

Swap Calculate

This endpoint allows you to instantly calculate how much cryptocurrency you'll receive when swapping one currency for another. Designed for ease of use, it provides real-time rates to ensure accurate calculations. Simply integrate this feature into your app to access the latest rates anytime. Whether you're buying or selling, this endpoint simplifies the process by giving you quick and precise swap amounts for your desired currency.

POST https://api.oxapay.com/v1/general/swap/calculate

Authentication

You must include the General API Key in the request header to authenticate your access to the API.

Name
Type
Description

general_api_key*

string

Your General API Key for authentication and authorization.

Request Body

Name
Type
Description

from_currency*

string

to_currency*

string

amount*

decimal

Specify the amount of currency you want to swap.

{
  "data": {
    "to_amount": decimal, // The amount of the "to_currency" received after the swap, represented with high precision (e.g., 94763.06 USDT).
    "rate": decimal, // The swap rate between the "from_currency" and "to_currency" at the time of the request (e.g., 1 BTC = 94763.06000000 USDT).
    "amount": decimal // The amount of the "from_currency" being swapped, represented with high precision (e.g., 1 BTC).
  },
  "message": string, // A message containing additional information about the result of the request.
  "error": {
    "type": string,
    "key": string,
    "message": string
  } || {}, // An object that provides details about any errors that occurred.
  "status": integer, // The status of the request response. Typically provided as a numeric code (e.g., 200 for success or other codes for errors).
  "version": string // The version of the API being used.
}

API Request Sample Codes

curl -X POST https://api.oxapay.com/v1/general/swap/calculate \
  -H "general_api_key: YOUR_GENERAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 12,
    "from_currency": "USDT",
    "to_currency": "TRX"
  }'
<?php

$url = 'https://api.oxapay.com/v1/general/swap/calculate';

$data = [
    "amount" => 12,
    "from_currency" => "USDT",
    "to_currency" => "TRX"
];

$headers = [
    'Content-Type: application/json',
    'general_api_key: YOUR_GENERAL_API_KEY'
];

$options = array(
    'http' => array(
        'header'  => implode("\r\n", $headers),
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === FALSE) {
    die('Error occurred');
}

$result = json_decode($response, true);
var_dump($result);

?>
const axios = require('axios');

const url = 'https://api.oxapay.com/v1/general/swap/calculate';

const data = {
  amount: 12,
  from_currency: "USDT",
  to_currency: "TRX",
};

const headers = {
  'general_api_key': `YOUR_GENERAL_API_KEY`,
  'Content-Type': 'application/json',
};

axios.post(url, data, { headers })
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error(error);
  });
import requests
import json

url = 'https://api.oxapay.com/v1/general/swap/calculate'

data = {
    "amount": 12,
    "from_currency": "USDT",
    "to_currency": "TRX"
}

headers = {
    'general_api_key': 'YOUR_GENERAL_API_KEY',
    'Content-Type': 'application/json'
}

response = requests.post(url, data=json.dumps(data), headers=headers)
result = response.json()
print(result)

These example code snippets demonstrate how to request the "Swap Calculate" endpoint using different programming languages. You can customize the data parameters according to your specific requirements.

Please make sure to replace YOUR_GENERAL_API_KEY in the code snippets with your actual General API Key.

API Response Example

{
    "data": {
        "to_amount": 94763.06,
        "rate": 94763.06000000,
        "amount": 1
    },
    "message": "Operation completed successfully!",
    "error": {},
    "status": 200,
    "version": "1.0.0"
}

The response example above is provided to help you understand the format and structure of the response. If you have any further questions or need assistance, please feel free to contact to your account manager.

PreviousSwap PairsNextSwap Rate

Last updated 4 months ago

Specify the you want to swap from.

Specify the you want to swap to.

Please note that a successful request will return status 200. In case of any issues or validation problems, refer to the corresponding for further details.

error
currency symbol
currency symbol