Ledger balances

Balance from Source

Compute a balance from its transactions.

The Balance from source endpoint allows you to compute a balance directly from its transactions instead of using the default running balance.

This is useful when you need to verify balance accuracy, perform audits, or ensure consistency by calculating balances independently from the stored balance values.

curl -X GET "http://YOUR_BLNK_INSTANCE_URL/balances/{balance_id}?from_source=true" \
  -H "X-blnk-key: <api-key>"
const response = await blnk.LedgerBalances.get(
  'bln_5ce86029-3c2e-4e2a-aae2-7fb931ca4c4f',
  {
    from_source: true,
  },
);
at, _ := time.Parse(time.RFC3339, "2024-04-22T15:28:03+00:00")
balance, _, _ := client.LedgerBalance.GetHistorical(
    "bln_5ce86029-3c2e-4e2a-aae2-7fb931ca4c4f",
    at,
    true,
)
response = blnk.ledger_balances.get(
  "bln_5ce86029-3c2e-4e2a-aae2-7fb931ca4c4f",
  {
    "from_source": True,
  },
)
ApiResponse<JsonNode> response = blnk.ledgerBalances().get(
    "bln_5ce86029-3c2e-4e2a-aae2-7fb931ca4c4f",
    GetBalanceRequest.create().fromSource(true));
{
  "balance": {
    "balance": 9620000,
    "balance_id": "bin_be16c4a1-b5a6-4b64-a733-de2f6b24813d",
    "credit_balance": 9620000,
    "currency": "USD",
    "debit_balance": 0,
    "ledger_id": ""
  }
}

How it works

When you call the balance from source endpoint, Blnk reconstructs the balance by:

  1. Getting all applied transactions: Blnk retrieves all applied transactions for the balance and aggregates them together. As a result, it may take longer to process for balances with extensive transaction history.

  2. Calculating credits and debits: It aggregates all credit transactions (money moving into the balance) and debit transactions (money moving out of the balance) to compute the total credit balance, debit balance, and net balance.

  3. Returning the computed balance: The final computed balance, reflecting the exact state based on transaction history, is returned in the response.