api icon indicating copy to clipboard operation
api copied to clipboard

Transfer verses Roundup inconsistency

Open opeik opened this issue 2 years ago • 0 comments

Hi there,

Context

I'm writing a Up to YNAB importer and I've noticed a strange edge case with round ups that has appeared about 6 times over my 2 year transaction history. For context, the YNAB API requires what I'm going to call "normalized" transfers. Normalized transfers aren't two regular transactions, but rather one special transaction where the transfer amount is added to the "from" account and deducted from the "to" account in one step.

Now, given either half of a transfer with the Up API, there doesn't seem to be any way to directly address the other half. In other words, if I have a "transfer from" transaction, it has no reference to the corresponding "transfer to" and vice-versa.

Workaround

To work around this, I match the halves together myself using some simple heuristics, namely:

  • Do the message prefixes match between both halves?
    • For example: "transfer to/transfer from" or "forward to/forward from"
  • Is the transaction amount the same for both halves with opposite signs in each?
    • The "transfer to" transaction is -5AUD and the "transfer from" transaction is 5AUD
  • Does each half occur within a short time period (I'm using <1m currently)

Once the transfers are matched, only the "transfer from" halves is used and the "transfer to" halves are ignored.

I'm losing my mind

I've had to special case this interaction and I'm utterly stumped as to why it's occurring in the data.

This is a normal transfer, it has a "to" and "from" transaction: transfer

This is a normal roundup: purchases are rounded up to the nearest dollar then transferred to a designated saver. Notice how there's no "to" transaction, only an expense and a "from" transaction. roundup

What is this then? wtf

Notice how "Transfer to Home loan deposit" is missing the matching "Transfer from Spending" after, but the roundup just so happens to fit the criteria bar the transaction message? I don't think this is an eventual consistency problem since I scanned the entire transaction history and the other half of the transfer never appears.

Update

I tried a naive approach first, namely: ignoring all transfer halves that had a negative amount—the "transfer to" transactions. At the time, the balances were completely wrong and I discounted it. After looking through my git history I realized the mismatch was caused by adding the round up amount to expenses. This caused round ups to be deducted twice. After fixing this, the naive approach actually works identically to matching the halves together as outlined above. Good to know!

opeik avatar Feb 06 '24 02:02 opeik