Modern Treasury Ledgers: a double-entry ledger for your own
accounting. A ledger holds ledger accounts (each with a currency and a
normal_balance of "credit" or "debit"); a ledger transaction is
a set of ledger entries whose credits and debits balance. Balances
come back as pending_balance, posted_balance and
available_balance, each {credits, debits, amount, currency}.
Functions
create-ledger
fn (params: Map): Map
fn (params: Map, opts: Map): Map
POST /api/ledgers: create a ledger. params needs name; optional
description, metadata.
Example
ledger ::modern-treasury::ledgers/create-ledger({name: "Wallets", metadata: {team: "payments"}})
ledger.id
create-ledger-account
fn (params: Map): Map
fn (params: Map, opts: Map): Map
POST /api/ledger_accounts: create a ledger account. params needs
ledger_id, name, currency and normal_balance ("credit" for
liabilities and revenue, "debit" for assets and expenses); optional
currency_exponent, description, external_id, metadata,
ledger_account_category_ids, ledgerable_id, ledgerable_type.
Example
::modern-treasury::ledgers/create-ledger-account({
ledger_id: "89c8bd30-e06a-4a79-b396-e6c7e13e7a12",
name: "User 42 wallet",
currency: "USD",
normal_balance: "credit"
}, {idempotency-key: "wallet-user-42"})
create-ledger-transaction
fn (params: Map): Map
fn (params: Map, opts: Map): Map
POST /api/ledger_transactions: record a ledger transaction.
params needs ledger_entries: [{ledger_account_id, direction, amount}] (at least two, balanced per currency); optional
description, status ("pending", "posted"; default pending),
effective_at, effective_date, external_id (unique; a second
create with the same one fails), metadata, ledgerable_type and
ledgerable_id. Each entry may set available_balance_amount,
pending_balance_amount or posted_balance_amount conditions for
balance locking. Entries missing an account, direction or amount err
locally.
Example
::modern-treasury::ledgers/create-ledger-transaction({
description: "User 42 top-up",
status: "posted",
external_id: "topup-42-1",
ledger_entries: [
{ledger_account_id: "f1c7e474-e6d5-4741-9f76-04510c8b6d7a", direction: "debit", amount: 1000},
{ledger_account_id: "0e0e0e0e-1111-2222-3333-444444444444", direction: "credit", amount: 1000}
]
}, {idempotency-key: "topup-42-1"})
get-ledger
fn (ledger-id: Str): Map
fn (ledger-id: Str, opts: Map): Map
GET /api/ledgers/{id}: retrieve a ledger.
Example
ledger ::modern-treasury::ledgers/get-ledger("89c8bd30-e06a-4a79-b396-e6c7e13e7a12")
ledger.name
get-ledger-account
fn (ledger-account-id: Str): Map
fn (ledger-account-id: Str, balances: Map): Map
fn (ledger-account-id: Str, balances: Map, opts: Map): Map
GET /api/ledger_accounts/{id}: retrieve a ledger account (by id or
external_id) with its balances. balances options: as_of_date,
effective_at, effective_at_lower_bound, effective_at_upper_bound,
as_of_lock_version.
Example
account ::modern-treasury::ledgers/get-ledger-account("f1c7e474-e6d5-4741-9f76-04510c8b6d7a")
account.balances.posted_balance.amount
// Balances at a point in time
::modern-treasury::ledgers/get-ledger-account("f1c7e474-e6d5-4741-9f76-04510c8b6d7a", {effective_at: "2026-11-01T00:00:00Z"})
get-ledger-account-balances
fn (ledger-account-id: Str, as-of: Map): Map
fn (ledger-account-id: Str, as-of: Map, opts: Map): Map
Just the balances of a ledger account: {pending_balance, posted_balance, available_balance}. as-of options as for
get-ledger-account (e.g. {effective_at: "2026-11-01T00:00:00Z"}).
Example
b ::modern-treasury::ledgers/get-ledger-account-balances("f1c7e474-e6d5-4741-9f76-04510c8b6d7a", {})
b.posted_balance.amount
get-ledger-transaction
fn (ledger-transaction-id: Str): Map
fn (ledger-transaction-id: Str, opts: Map): Map
GET /api/ledger_transactions/{id}: retrieve a ledger transaction with its entries.
Example
transaction ::modern-treasury::ledgers/get-ledger-transaction("3e9a1f60-7c2b-4d18-a4f3-92b6d0e1c847")
map(transaction.ledger_entries, %.amount)
invalid-entries
fn (entries: Vec): Vec<Int>
The positions of ledger_entries that lack ledger_account_id,
direction ("credit" or "debit") or an amount/amount_string.
Exposed for testing.
Example
::modern-treasury::ledgers/invalid-entries([
{ledger_account_id: "a", direction: "debit", amount: 1000},
{ledger_account_id: "b", direction: "sideways", amount: 1000}
]) // [1]
is-balanced
fn (entries: Vec): Bool
True when the Int amounts of the credit entries equal those of the
debit entries. A pre-check for single-currency transactions (Modern
Treasury checks each currency itself). Exposed for testing.
Example
::modern-treasury::ledgers/is-balanced([{direction: "debit", amount: 1000}, {direction: "credit", amount: 1000}]) // true
::modern-treasury::ledgers/is-balanced([{direction: "debit", amount: 1000}]) // false
list-ledger-accounts
fn (): Map
fn (params: Map): Map
fn (params: Map, opts: Map): Map
GET /api/ledger_accounts: one page. Filters: ledger_id, currency,
normal_balance, name: [...], id: [...], external_id,
ledger_account_category_id, metadata, balances: {...},
posted_balance_amount: {gt, lt, eq}, per_page, after_cursor.
Example
page ::modern-treasury::ledgers/list-ledger-accounts({ledger_id: "89c8bd30-e06a-4a79-b396-e6c7e13e7a12", currency: "USD"})
map(page.items, %.name)
list-ledger-entries
fn (): Map
fn (params: Map): Map
fn (params: Map, opts: Map): Map
GET /api/ledger_entries: one page of ledger entries. Filters:
ledger_account_id, ledger_transaction_id, direction, status,
effective_at: {...}, show_balances (Bool, adds resulting balances),
order_by: {created_at: "asc"}, per_page, after_cursor.
Example
page ::modern-treasury::ledgers/list-ledger-entries({ledger_account_id: "f1c7e474-e6d5-4741-9f76-04510c8b6d7a", show_balances: true})
map(page.items, %.amount)
list-ledger-transactions
fn (): Map
fn (params: Map): Map
fn (params: Map, opts: Map): Map
GET /api/ledger_transactions: one page. Filters: ledger_id,
ledger_account_id, status, external_id, ledgerable_type,
ledgerable_id, effective_at: {gte, lte}, posted_at: {...},
updated_at: {...}, order_by: {created_at: "asc"}, metadata,
per_page, after_cursor.
Example
page ::modern-treasury::ledgers/list-ledger-transactions({ledger_account_id: "f1c7e474-e6d5-4741-9f76-04510c8b6d7a", status: "posted"})
map(page.items, %.description)
list-ledgers
fn (): Map
fn (params: Map): Map
fn (params: Map, opts: Map): Map
GET /api/ledgers: one page. Filters: id: [...] (sent as id[]),
metadata, updated_at: {gte, lte}, per_page, after_cursor.
Example
page ::modern-treasury::ledgers/list-ledgers({per_page: 25})
map(page.items, %.name)
reverse-ledger-transaction
fn (ledger-transaction-id: Str, params: Map): Map
fn (ledger-transaction-id: Str, params: Map, opts: Map): Map
POST /api/ledger_transactions/{id}/reversal: post a new ledger
transaction that undoes a posted one. params: description, status,
effective_at, external_id, metadata.
Example
reversal ::modern-treasury::ledgers/reverse-ledger-transaction("3e9a1f60-7c2b-4d18-a4f3-92b6d0e1c847", {description: "Refund top-up", status: "posted"})
reversal.id
update-ledger
fn (ledger-id: Str, params: Map): Map
fn (ledger-id: Str, params: Map, opts: Map): Map
PATCH /api/ledgers/{id}: change name, description or metadata.
Example
::modern-treasury::ledgers/update-ledger("89c8bd30-e06a-4a79-b396-e6c7e13e7a12", {description: "Customer wallets"})
update-ledger-account
fn (ledger-account-id: Str, params: Map): Map
fn (ledger-account-id: Str, params: Map, opts: Map): Map
PATCH /api/ledger_accounts/{id}: change name, description,
external_id or metadata.
Example
::modern-treasury::ledgers/update-ledger-account("f1c7e474-e6d5-4741-9f76-04510c8b6d7a", {name: "User 42 main wallet"})
update-ledger-transaction
fn (ledger-transaction-id: Str, params: Map): Map
fn (ledger-transaction-id: Str, params: Map, opts: Map): Map
PATCH /api/ledger_transactions/{id}: change a pending ledger
transaction: status ("posted" or "archived"), description,
metadata, effective_at, or its ledger_entries. Posted transactions
are immutable; reverse them instead.
Example
transaction ::modern-treasury::ledgers/update-ledger-transaction("3e9a1f60-7c2b-4d18-a4f3-92b6d0e1c847", {status: "posted"})
transaction.status