diff --git a/README.md b/README.md index 9b16dba..38fa799 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.gradle.kts b/build.gradle.kts index c33f969..9fb82c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { } group = "net.djvk" -version = "1.3.2" +version = "1.3.3" java.sourceCompatibility = JavaVersion.VERSION_17 repositories { diff --git a/src/main/kotlin/net/djvk/fireflyPlaidConnector2/constants/Typealiases.kt b/src/main/kotlin/net/djvk/fireflyPlaidConnector2/constants/Typealiases.kt index b963b2c..936b284 100644 --- a/src/main/kotlin/net/djvk/fireflyPlaidConnector2/constants/Typealiases.kt +++ b/src/main/kotlin/net/djvk/fireflyPlaidConnector2/constants/Typealiases.kt @@ -1,3 +1,4 @@ package net.djvk.fireflyPlaidConnector2.constants -typealias TimestampSeconds = Long \ No newline at end of file +typealias TimestampSeconds = Long +typealias IntervalSeconds = Long diff --git a/src/main/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunner.kt b/src/main/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunner.kt index 9163c84..2fee364 100644 --- a/src/main/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunner.kt +++ b/src/main/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunner.kt @@ -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 @@ -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, @@ -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) ) ) }, diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8328cd7..db57f3f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -39,6 +39,8 @@ 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. @@ -46,6 +48,12 @@ fireflyPlaidConnector2: # 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 diff --git a/src/test/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunnerTest.kt b/src/test/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunnerTest.kt index c382344..c588293 100644 --- a/src/test/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunnerTest.kt +++ b/src/test/kotlin/net/djvk/fireflyPlaidConnector2/sync/BatchSyncRunnerTest.kt @@ -45,6 +45,7 @@ internal class BatchSyncRunnerTest { return BatchSyncRunner( syncDays, setInitialBalance, + null, plaidBatchSize, plaid.wrapper, syncHelper ?: defaultSyncHelper,