Skip to main content
All API endpoints require authentication through three custom headers. These headers ensure secure communication between your application and our API.
Ensure you have your API credentials (API Key and API Secret) before proceeding.
Contact our support team if you need assistance obtaining these credentials.
Use distinct API credentials for Sandbox and Production environments.
Production API keys are not valid in the Sandbox environment and vice versa.

Required Headers

X-API-KEY
string
required
Your unique API key provided by DollarPe. This key identifies your application.
X-TIMESTAMP
integer
required
The current Unix timestamp in seconds. This helps prevent replay attacks.
X-SIGNATURE
string
required
An HMAC SHA256 signature of the request, encoded in Base64. This signature verifies the integrity and authenticity of the request.

Generating the Signature

The signature is a critical component of the authentication process. Follow these steps to generate it:
1

Create Message String

Concatenate the API key, timestamp, and a sorted JSON string of the request body using a pipe (|) separator.
import time
import json

api_key = "your-api-key"
timestamp = int(time.time())
request_body = { # your request body }
sorted_body = json.dumps(request_body, sort_keys=True)
message = f"{api_key}|{timestamp}|{sorted_body}"
2

Generate Hash

Use your API secret to create an HMAC SHA256 hash of the message string.
import hmac
import hashlib

api_secret = "your-api-secret"
hash = hmac.new(api_secret.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).digest()
3

Encode

Convert the resulting hash to Base64 format. This encoded string is your signature.
import base64

signature = base64.b64encode(hash).decode('utf-8')

Code Examples

Below are examples in various programming languages to generate the required headers:
const crypto = require('crypto');

/**
 * Generates authentication headers for API requests.
 * @param {string} apiKey - Your API key.
 * @param {string} apiSecret - Your API secret.
 * @param {Object} [body={}] - The request body.
 * @returns {Object} - The headers object containing authentication details.
 */
const generateHeaders = (apiKey, apiSecret, body = {}) => {
  // Get current timestamp
  const timestamp = Math.floor(Date.now() / 1000);

  // Sort and stringify the body
  const sortedBody = JSON.stringify(body, Object.keys(body).sort());

  // Create message string
  const message = `${apiKey}|${timestamp}|${sortedBody}`;

  // Generate signature
  const signature = crypto
    .createHmac('sha256', apiSecret)
    .update(message)
    .digest('base64');

  return {
    'X-API-KEY': apiKey,
    'X-TIMESTAMP': timestamp.toString(),
    'X-SIGNATURE': signature
  };
};

Example Usage

Here’s how to use the generated headers in an API request:
const apiKey = "your-api-key";
const apiSecret = "your-api-secret";

const requestBody = {
  asset: "USDT",
  network: "BSC",
  amount: 100.5,
};

const headers = generateHeaders(apiKey, apiSecret, requestBody);

// Make API request
fetch("https://sandbox.dollarpe.xyz/pos/api/v1/payout/fetch-rate", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    ...headers,
  },
  body: JSON.stringify(requestBody),
});