Closed JaxOfDiamonds closed 3 months ago
Hello,
I checked the official API, and it was a bit confusing to me because:
I created a patch for now on https://github.com/bvanelli/actualpy/pull/23 that uses an sqlalchemy property. I used the beta token from https://beta-bridge.simplefin.org/info/developers to create an account with lots of entries:
The result of the property:
from actual import Actual
from actual.queries import get_accounts
with Actual("http://localhost:5006", password="mypass", file="My Finances") as actual:
accounts = get_accounts(actual.session)
for acct in accounts:
print(f"Balance for {acct.name} is {acct.balance}")
Balance for SimpleFIN Savings is 115524.49
Balance for SimpleFIN Checking is 26134.41
In the general case, I think it would be nice to include the balance on categories, payees and group of transactions. The general query is:
def get_balance(transactions: list[Transactions]) -> decimal.Decimal:
running_balance = decimal.Decimal(0)
for t in transactions:
if t.is_parent == 0 and t.tombstone == 0: # skip the splits, as they already get counted
amount = t.get_amount()
running_balance = running_balance + amount
return running_balance
Let me know what you think of the PR, you will be able to install it from git or by cloning and checking out the PR.
The PR worked for me except for an edge case of accounts with zero transactions. I added a comment and a workaround in the PR - though there may be a more elegant solution.
The PR worked for me except for an edge case of accounts with zero transactions. I added a comment and a workaround in the PR - though there may be a more elegant solution.
Solved the issue, thanks for the correction!
The get_accounts function does not appear to be populating the balances. I have balances in Actual.
Code snippet:
Output: