If a specific bank doesn't provide balanceAfterTransaction
in their response, here's how you can derive it yourself.
1. Get the account's balance by making GET /api/v2/accounts/{id}/balances/
API call. The retrieved balance value is your end balance.
- If there is a
referenceDate
in the response, this means that the balance received is shown as of the indicatedreferenceDate
. - If there is no
referenceDate
in the response, this means that the balance received is shown as of now (as of the time the API call was made).
2. Get the account's transactions for a specific period, e.g. last 90 days by making GET /api/v2/accounts/{id}/transactions/?date_from=YYYY-MM-DD&date_to=YYYY-MM-DD
API call.
3. Derive the start balance at the beginning of the period by making calculations with retrieved transactions in reverse order by bookingDate
.
Here's an example. Let's say the account's current balance (as of 2022-11-01) is 100 EUR (end balance) and in the last 5 days there are the following transactions:
- 2022-10-31: 5 EUR spent on bus tickets
- 2022-10-30: 10 EUR received from a relative
- 2022-10-28: 20 EUR spent on groceries
Then by doing simple math we get 100 + 5 - 10 + 20 = 115 EUR - balance as of 5 days ago (start balance).
When implementing this logic in your application, please be mindful and account for the difference in banks' outputs (in terms of data points they provide and the way they use these data points).
Comments
0 comments
Article is closed for comments.