Sabong API v1.0

Get Balance API

Overview

The Get Balance API retrieves the current wallet balance for a user identified by their clientId. This endpoint returns the available balance in the default currency (USD) along with the timestamp of the last balance update.

Endpoint

MethodEndpointAuthentication
GET/api/v1/get-balanceSignature Required

Authentication

This endpoint requires Signature-based Authentication. You must include the following headers:

HeaderDescription
x-signatureHMAC-SHA256 signature of the request
x-timestampUnix timestamp (seconds) when the request was generated

Note: See Overview for detailed information on how signature authentication works and how to generate signatures.

Query Parameters

ParameterTypeRequiredDescription
clientIdstringYesThe unique client identifier

Request Example

GET /api/v1/get-balance?clientId=CLIENT_001

Response

Success Response (200 OK)

{
  "status": "success",
  "message": "Balance retrieved successfully",
  "data": {
    "userId": 123,
    "clientId": "CLIENT_001",
    "balance": 1500.50,
    "updatedAt": "2026-02-01T14:30:00.000Z"
  }
}

Response Fields

FieldTypeDescription
statusstringAlways "success" for successful requests
messagestringHuman-readable success message
data.userIdintegerInternal user ID
data.clientIdstringClient identifier
data.balancenumberCurrent wallet balance (as float)
data.updatedAtstring | nullISO 8601 timestamp of last balance update, or null if unavailable

Error Responses

Validation Error (400 Bad Request)

{
  "status": "failed",
  "message": "Validation failed",
  "data": {
    "errors": {
      "clientId": ["The clientId field is required."]
    }
  }
}

User Not Found (404 Not Found)

{
  "status": "failed",
  "message": "User not found",
  "data": null
}

Authentication Error (401 Unauthorized)

{
  "status": "error",
  "message": "Invalid signature",
  "data": null
}

Server Error (500 Internal Server Error)

{
  "status": "failed",
  "message": "Failed to get balance",
  "data": {
    "error": "Database connection failed"
  }
}

Usage Example

cURL

curl -X GET "https://wdcf.xerve.online/api/v1/get-balance?clientId=CLIENT_001" \
  -H "x-signature: YOUR_SIGNATURE" \
  -H "x-timestamp: 1706802000"

Note: To generate the signature, refer to the Overview documentation.

JavaScript/TypeScript (with Axios)

import axios from 'axios';
// Import your signature generation function (see Overview)
import { generateSignature } from './signature-utils';

const API_BASE_URL = 'https://wdcf.xerve.online';
const CLIENT_SECRET = 'your-secret-key';

async function getBalance(clientId: string) {
  const timestamp = Math.floor(Date.now() / 1000);
  const payload = { clientId };

  // Generate signature (see Overview for implementation)
  const signature = generateSignature({
    method: 'GET',
    path: '/api/v1/get-balance',
    payload,
    secret: CLIENT_SECRET,
    timestamp
  });

  try {
    const response = await axios.get(
      `${API_BASE_URL}/api/v1/get-balance`,
      {
        params: payload,
        headers: {
          'x-signature': signature,
          'x-timestamp': timestamp.toString()
        }
      }
    );

    console.log('Balance:', response.data.data.balance);
    console.log('Updated at:', response.data.data.updatedAt);
    return response.data;
  } catch (error: any) {
    console.error('Error:', error.response?.data || error.message);
    throw error;
  }
}

// Usage
getBalance('CLIENT_001');

Python

import requests
# Import your signature generation function (see Overview)
from signature_utils import generate_signature
import time

API_BASE_URL = 'https://wdcf.xerve.online'
CLIENT_SECRET = 'your-secret-key'

def get_balance(client_id: str):
    timestamp = int(time.time())
    payload = {"clientId": client_id}

    # Generate signature (see Overview for implementation)
    signature = generate_signature(
        method="GET",
        path="/api/v1/get-balance",
        payload=payload,
        secret=CLIENT_SECRET,
        timestamp=timestamp
    )

    headers = {
        "x-signature": signature,
        "x-timestamp": str(timestamp)
    }

    response = requests.get(
        f"{API_BASE_URL}/api/v1/get-balance",
        params=payload,
        headers=headers
    )

    response.raise_for_status()
    data = response.json()
    print(f"Balance: {data['data']['balance']}")
    print(f"Updated at: {data['data']['updatedAt']}")
    return data

# Usage
if __name__ == "__main__":
    get_balance("CLIENT_001")

Important Notes

  1. Default Currency: The balance is returned in the default currency (USD). Multi-currency support may be added in future versions.
  2. Wallet Auto-Creation: If the user exists but doesn't have a wallet, the system will automatically create one when calling endpoints that require wallet operations (like credit/debit).
  3. Real-time Balance: The balance reflects the current state at the time of the request. For high-frequency trading applications, consider implementing caching strategies.
  4. Precision: The balance is returned as a float. For financial calculations, consider using decimal types to avoid floating-point precision issues.

Error Handling

Error CodePossible CausesResolution
400Missing or invalid clientIdEnsure clientId is provided and valid
401Invalid signature or expired timestampVerify signature generation and ensure timestamp is current
404User not foundCheck that the clientId exists; may need to call generate-auth-token first
500Database error or wallet service failureCheck server logs and retry