๐Ÿ”„Swap

This documentation provides details on the API endpoints available for Whirlprivacy.io, focusing on swap-related operations.

โš ๏ธ You must be logged in to use these requests below.

Common Headers

For all requests that require user authentication, you must include the following headers:

Header NameValueDescription

X-API-key

base64

API token obtained after authentication.

GET /swap/data - Retrieve Swap Data

Allows the retrieval of swap data for a given currency pair and amount.

Parameters:

NameTypeDescriptionRequired

tickerIn

String

The ticker symbol of the input currency.

Yes

tickerOut

String

The ticker symbol of the output currency.

Yes

amountIn

String

The amount of the input currency.

Yes

Response:

{
  "swapData": {
    "tickerIn": "string",
    "tickerOut": "string",
    "amountIn": "string",
    "rate": "string",
    "expectedOut": "string"
  }
}

Error Handling:

Error NameDescription

Invalid Parameters

Required parameters are missing.

Failed to Fetch Swap Data

The swap data could not be retrieved.

Example Code:

const fetch = require('node-fetch');

const BASE_URL = 'https://api.whirlprivacy.io/';
const API_KEY = 'your_api_key';

const retrieveSwapData = async (tickerIn, tickerOut, amountIn) => {
  try {
    const url = new URL(`${BASE_URL}swap/data`);
    url.search = new URLSearchParams({ tickerIn, tickerOut, amountIn }).toString();

    const response = await fetch(url, {
      headers: {
        'X-API-key': API_KEY
      }
    });

    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error retrieving swap data:', error);
  }
};

retrieveSwapData('tickerA', 'tickerB', 'amountIn');

POST /swap/initiate - Initiate a Swap

Initiates a currency swap operation for a logged-in user.

Parameters:

NameTypeDescriptionRequired

sender

String

The UUID or the label of the sender.

No

tickerIn

String

The ticker symbol of the currency to swap from.

Yes

tickerOut

String

The ticker symbol of the currency to swap to.

Yes

amountIn

String

The amount of currency to swap.

Yes

slippage

Integer

The slippage percentage in basis points.

Yes

Response:

{
  "message": "Swap initiated"
}

Error Handling:

Error NameDescription

Unauthorized

User is not logged in or session has expired.

Invalid Parameters

One or more parameters are invalid.

Invalid Ticker

The provided ticker symbol is not supported.

Unsupported Swap

The swap operation is not supported.

Invalid Amount

The provided amount is invalid.

Balance Too Low

The user's balance is too low for the swap.

Error Initiating Swap

There was an error initiating the swap.

Example Code:

const fetch = require('node-fetch');

const BASE_URL = 'https://api.whirlprivacy.io/';
const API_KEY = 'your_api_key';

const initiateSwap = async (sender, tickerIn, tickerOut, amountIn, slippage) => {
  try {
    const response = await fetch(`${BASE_URL}swap/initiate`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-key': API_KEY
      },
      body: JSON.stringify({ sender, tickerIn, tickerOut, amountIn, slippage })
    });

    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error initiating swap:', error);
  }
};

initiateSwap('uuid', 'tickerA', 'tickerB', 'amountIn', 100);

GET /swap/history - Retrieve Swap History

Retrieves the swap history for a logged-in user.

Parameters:

NameTypeDescriptionRequired

uuid or label

String

The UUID or the label of the sender.

Yes

page

Integer

The page number for paginated history data.

Yes

Response:

{
  "data": [
    {
      "tickerIn": "string",
      "tickerOut": "string",
      "status": "string",
      "createdAt": "string",
      "formattedIn": "string",
      "formattedOut": "string"
    }
  ],
  "meta": {
    "totalPages": "integer",
    "currentPage": "integer",
    "perPage": "integer",
    "totalItems": "integer"
  }
}

Error Handling:

Error NameDescription

Unauthorized

User is not logged in or session has expired.

Example Code:

const fetch = require('node-fetch');

const BASE_URL = 'https://api.whirlprivacy.io/';
const API_KEY = 'your_api_key';

const retrieveSwapHistory = async (uuid, page) => {
  try {
    const response = await fetch(`${BASE_URL}swap/history?uuid=${uuid}&page=${page}`, {
      method: 'GET',
      headers: {
        'X-API-key': API_KEY
      }
    });

    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error retrieving swap history:', error);
  }
};

// Example usage with page number 1
retrieveSwapHistory("uuid", 1);

Last updated