Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] API call for getting account balance #2189

Closed
1 of 2 tasks
MirariFang opened this issue Jan 7, 2024 · 3 comments · Fixed by #2930
Closed
1 of 2 tasks

[Feature] API call for getting account balance #2189

MirariFang opened this issue Jan 7, 2024 · 3 comments · Fixed by #2930
Labels
feature This issue is a feature request

Comments

@MirariFang
Copy link

Verified feature request does not already exist?

  • I have searched and found no existing issue

💻

  • Would you like to implement this feature?

Pitch: what problem are you trying to solve?

Hi there, I'm trying to implement my own tools to interact with the Actual, but I didn't find any API calls that could simply give me the total balance of an account. Although I probably could just get all transactions with a super early starting date and sum them up, it's a little bit more tedious than getting the value in one go.
Just curious, is this intentional by design? Why the Account object can't simply include a "balance" field? Or am I missing anything?
Thanks.

Describe your ideal solution to this problem

Add balance field to Account, which has the current balance value of that account.

Teaching and learning

No response

@MirariFang MirariFang added the feature This issue is a feature request label Jan 7, 2024
@github-actions github-actions bot added the needs votes Please upvote this feature request if you would like to see it implemented! label Jan 7, 2024

This comment has been minimized.

@github-actions github-actions bot closed this as completed Jan 7, 2024
@turt2live
Copy link
Contributor

turt2live commented Apr 7, 2024

In the meantime, developers can use the ActualQL feature:

// Get balances for all accounts as of a certain date
const balancesAllAccounts = (await runQuery(q('transactions')
    .filter({ date: { $lte: '2024-03-31' } })
    .groupBy('account.id')
    .select(['account.id', 'account.name', {balance: {$sum: "$amount"}}])
)).data;

// Get balance for a single account as of a certain date
const balanceMyAccount = (await runQuery(q('transactions')
    .filter({
        date: { $lte: '2024-03-31' },
        'account.id': 'YOUR-ACCOUNT-UUID-HERE',
    })
    .select(['account.id', 'account.name', {balance: {$sum: "$amount"}}])
)).data;

If you need the current balance as of 'today', either put that date into the filter or remove that condition entirely.

@github-actions github-actions bot removed the needs votes Please upvote this feature request if you would like to see it implemented! label Jul 10, 2024
Copy link
Contributor

🎉 This feature has been implemented in #2930 and will be released in the next version. Thanks for sharing your idea! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue is a feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants