A Ledger Entry Group is a collection of related Ledger Entries that occur at different points in time. Each Group tracks the net change to each Ledger Account balance it affects.
Use Ledger Entry Groups to tie together Ledger Entries that are part of the same funds flow, such as a deposit, settlement or invoice. To store metadata, use tags instead.
Groups for a Ledger Entry Type are defined as a list of key/value pairs in the Schema:
{
"type": "user_initiates_withdrawal",
"description": "{{user_id}} initiates withdrawal",
"lines": [
{
"account": {
"path": "liabilities/users:{{user_id}}/available"
},
"key": "decrease_user_balance",
"amount": "-{{withdraw_amount}}"
},
{...other line}
],
"groups": [
{
"key": "withdrawal",
"value": "{{withdrawal_id}}"
}
]
}
Ledger Entry Groups have the following limitations:
value
of a Group, but not the key
.Use the ledgerEntryGroup.balances
expansion to get the net change per Ledger Account balance from all Ledger Entries in a Group. Group balances are eventually consistent.
query GetLedgerEntryGroupBalances(
$ledger: LedgerMatchInput!
$entryGroup: EntryGroupMatchInput!,
) {
ledger(ledger: $ledger) {
ledgerEntryGroup(ledgerEntryGroup: $entryGroup) {
balances {
nodes {
account {
path
}
ownBalance
}
}
}
}
}
{
"entryGroup": {
"key": "withdrawal",
"value": "some-withdrawal-id"
},
"ledger": {
"ik": "quickstart-ledger"
}
}
The response for a Ledger Entry Group with a settled withdrawal:
{
"data": {
"ledger": {
"ledgerEntryGroup": {
"balances": {
"nodes": [
{
"account": {
"path": "asset-root/bank"
},
"ownBalance": "-50000"
},
{
"account": {
"path": "liability-root/user:user-id/available"
},
"ownBalance": "-50000"
},
{
"account": {
"path": "liability-root/user:user-id/pending"
},
"ownBalance": "0"
}
]
}
}
}
}
}
Ledger Entry Groups support strongly-consistent reads for the ownBalance field. See Consistent Ledger Entry Group balances for more information on how to configure this in your Schema. See Query Consistent Groups for how to query strongly consistent Ledger Entry Group balances.
Balances in a Group may be filtered by account, currency, and ownBalance.
query QueryLedgerEntryGroupBalances(
$ledger: LedgerMatchInput!
$entryGroup: EntryGroupMatchInput!,
$filter: LedgerEntryGroupBalanceFilterSet,
) {
ledger(ledger: $ledger) {
ledgerEntryGroup(ledgerEntryGroup: $entryGroup) {
balances(filter: $filter) {
nodes {
account {
path
}
ownBalance
currency {
code
}
}
}
}
}
}
{
"entryGroup": {
"key": "withdrawal",
"value": "12345"
},
"ledger": {
"ik": "quickstart-ledger"
},
"filter": {
"currency": {
"equalTo": { "code": "USD" }
},
"ownBalance": {
"gte": "-1000",
"lte": "1000"
},
"account": {
"path": {
"equalTo": "liability-root/user:user-id/pending"
}
}
}
}
The response is:
{
"data": {
"ledger": {
"ledgerEntryGroup": {
"balances": {
"nodes": [
{
"account": {
"path": "liability-root/user:user-id/pending"
},
"ownBalance": "0",
"currency": {
"code": "USD"
}
}
]
}
}
}
}
}
Group balances support filtering account paths using '*' in place of a template variable.
query QueryLedgerEntryGroupBalances(
$ledger: LedgerMatchInput!
$entryGroup: EntryGroupMatchInput!,
$filter: LedgerEntryGroupBalanceFilterSet,
) {
ledger(ledger: $ledger) {
ledgerEntryGroup(ledgerEntryGroup: $entryGroup) {
balances(filter: $filter) {
nodes {
account {
path
}
ownBalance
}
}
}
}
}
{
"entryGroup": {
"key": "withdrawal",
"value": "12345"
},
"ledger": {
"ik": "quickstart-ledger"
},
"filter": {
"account": {
"path": {
"matches": "liability-root/user:*/pending"
}
}
}
}
The response is:
{
"data": {
"ledger": {
"ledgerEntryGroup": {
"balances": {
"nodes": [
{
"account": {
"path": "liability-root/user:user-id/pending"
},
"ownBalance": "0"
},
{
"account": {
"path": "liability-root/user:another-user-id/pending"
},
"ownBalance": "2500"
}
]
}
}
}
}
}
In addition to Groups defined in your Schema, you can add a posted Ledger Entry to additional Groups.
mutation UpdateLedgerEntryGroups(
$ledgerEntry: LedgerEntryMatchInput!
$update: UpdateLedgerEntryInput!
) {
updateLedgerEntry(
ledgerEntry: $ledgerEntry,
update: $update
) {
__typename
... on UpdateLedgerEntryResult {
entry {
type
ik
groups {
key
value
}
lines {
nodes {
amount
description
account {
path
}
}
}
}
}
... on Error {
code
message
}
}
}
{
"ledgerEntry": {
"ik": "add-ledger-entry",
"ledger": {
"ik": "quickstart-ledger"
}
},
"update": {
"groups": [
{
"key": "withdrawal",
"value": "12345"
}
]
}
}
This is an additive operation:
You can only update a Ledger Entry a maximum of 10 times.