Skip to content

Commit

Permalink
Support specifying min_last_updated_datetime for balance requests; do…
Browse files Browse the repository at this point in the history
…cument that this is the last time I'm messing with the initial balance feature.
  • Loading branch information
dvankley committed Jan 3, 2025
1 parent c45c28a commit 381dc11
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ transaction to a Firefly transfer, the existing Firefly transaction will be dele
transaction will be created because the Firefly API does not support converting existing transaction types.

## Initial Balances
**Note**: Given that the balance endpoint is now $0.10 per call, this feature isn't really worth using anymore.
**Note**: Given that the balance endpoint is now $0.10 per call, this feature isn't really worth using anymore
and is no longer officially supported because it costs me money every time I want to QA a change to it.

If `fireflyPlaidConnector2.batch.setInitialBalance` is set to `true`, the connector will try to create "initial balance"
transactions for each Firefly account that result in the current Firefly balance for each account equalling the
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

group = "net.djvk"
version = "1.3.2"
version = "1.3.3"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package net.djvk.fireflyPlaidConnector2.constants

typealias TimestampSeconds = Long
typealias TimestampSeconds = Long
typealias IntervalSeconds = Long
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import net.djvk.fireflyPlaidConnector2.api.firefly.models.TransactionSplit
import net.djvk.fireflyPlaidConnector2.api.firefly.models.TransactionTypeProperty
import net.djvk.fireflyPlaidConnector2.api.plaid.PlaidApiWrapper
import net.djvk.fireflyPlaidConnector2.api.plaid.models.*
import net.djvk.fireflyPlaidConnector2.constants.IntervalSeconds
import net.djvk.fireflyPlaidConnector2.constants.TimestampSeconds
import net.djvk.fireflyPlaidConnector2.transactions.FireflyTransactionDto
import net.djvk.fireflyPlaidConnector2.transactions.TransactionConverter
import org.slf4j.LoggerFactory
Expand All @@ -33,6 +35,8 @@ class BatchSyncRunner(
private val syncDays: Int,
@Value("\${fireflyPlaidConnector2.batch.setInitialBalance:false}")
private val setInitialBalance: Boolean,
@Value("\${fireflyPlaidConnector2.batch.balanceMinLastUpdatedDatetimeSeconds:}")
private val balanceMinLastUpdatedDatetimeSeconds: IntervalSeconds? = null,
@Value("\${fireflyPlaidConnector2.plaid.batchSize}")
private val plaidBatchSize: Int,

Expand Down Expand Up @@ -151,13 +155,18 @@ class BatchSyncRunner(
val plaidTxs = allPlaidTxs[accessToken] ?: continue
// Request balance data for this item/access token
logger.debug("Requesting balances for access token $accessToken and account ids ${accountIds.joinToString()}")
// Calculate min last updated, if required
val minLastUpdated = balanceMinLastUpdatedDatetimeSeconds?.let {
logger.debug("Setting min_last_updated_datetime to $balanceMinLastUpdatedDatetimeSeconds seconds ago")
OffsetDateTime.now().minusSeconds(it)
}
val balances: AccountsGetResponse
try {
balances = plaidApiWrapper.executeRequest(
{ plaidApi ->
plaidApi.accountsBalanceGet(
AccountsBalanceGetRequest(
accessToken, null, null, AccountsBalanceGetRequestOptions(accountIds)
accessToken, null, null, AccountsBalanceGetRequestOptions(accountIds, minLastUpdated)
)
)
},
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ fireflyPlaidConnector2:
batch:
# The number of days in the past to pull data for.
maxSyncDays: 5
# NOTE: Given that the balance endpoint is now $0.10 per call, this feature isn't really worth using anymore
# and is no longer officially supported because it costs me money every time I want to QA a change to it.
# If set to true, we will insert an offsetting transaction at the beginning of the batch pull window so
# that the total amount of all transactions pulled plus the offsetting transaction equals the current
# balance in the account as reported by Plaid.
# This is useful for ensuring the current balance in your accounts is accurate even if you don't
# pull every transaction from the beginning of time.
# Defaults to false.
setInitialBalance: false
# The number of seconds in the past to use as min_last_updated_datetime in the Plaid /accounts/balance/get call
# https://plaid.com/docs/api/products/balance/#accounts-balance-get-request-options-min-last-updated-datetime
# Note that this field is only used for Capital One non-depository accounts.
# Every other account type can safely ignore this.
# Defaults to null
# balanceMinLastUpdatedDatetimeSeconds: 86400
firefly:
# url: https://firefly.yourdomain.com
# Can be created in Firefly in Options->Profile->Oauth->Personal Access Tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class BatchSyncRunnerTest {
return BatchSyncRunner(
syncDays,
setInitialBalance,
null,
plaidBatchSize,
plaid.wrapper,
syncHelper ?: defaultSyncHelper,
Expand Down

0 comments on commit 381dc11

Please sign in to comment.