From e3d1fc4925af38c75c4dbd2d822c94a00a27c11b Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Fri, 21 Jun 2024 19:39:21 -0700 Subject: [PATCH] hledger-flow: coinbase: preprocess: fix Advanced Trade divide by zero --- .../accounts/coinbase/coinbase-shared.bash | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/container/src/hledger-flow/accounts/coinbase/coinbase-shared.bash b/container/src/hledger-flow/accounts/coinbase/coinbase-shared.bash index 38cf308..4c6c2d6 100755 --- a/container/src/hledger-flow/accounts/coinbase/coinbase-shared.bash +++ b/container/src/hledger-flow/accounts/coinbase/coinbase-shared.bash @@ -144,12 +144,26 @@ function __parse() # # Add new columns to calculate fees against native currency price # - # - 0 is used because Coinbase does not accurately display fiat amount, - # if satoshi is small (valued less than $0.00) + # WARNING: + # + # - `amount_amount` and/or `native_amount_amount` may be given as 0 + # because Coinbase does not display the full value of either column + # for token values (satoshi, gwei, etc.) valued less than a $0.00. + # + # Quite literally, the only value information that Coinbase will + # provide for these transactions is 0 or equivalent; so, an accurate + # calculation cannot be made nor inferred because the only other + # usable information is the fee. But, since it is unknown what + # percentage the fee-tier is for these transactions, no further + # calculations can be made. + # + # With that said, any 0-value transactions should skip the following + # calculations as to avoid a divide by zero error and, instead, be + # managed within the rules file. # - if ($7 > 0) {printf("%.8f", $7 / $5)}; printf OFS # native_amount_price - if ($7 > 0) {printf("%.8f", ($7 / $5) * $16)}; printf OFS # native_network_transaction_fee_amount + if ($7 > 0 && $5 > 0) {printf("%.8f", $7 / $5)}; printf OFS # native_amount_price + if ($7 > 0 && $5 > 0) {printf("%.8f", ($7 / $5) * $16)}; printf OFS # native_network_transaction_fee_amount # # Add new column to calculate the difference between amount and network fee,