hledger-flow: coinbase: preprocess: fix Advanced Trade divide by zero

This commit is contained in:
2024-06-21 19:39:21 -07:00
parent 0d997eab5e
commit e3d1fc4925

View File

@@ -144,12 +144,26 @@ function __parse()
# #
# Add new columns to calculate fees against native currency price # Add new columns to calculate fees against native currency price
# #
# - 0 is used because Coinbase does not accurately display fiat amount, # WARNING:
# if satoshi is small (valued less than $0.00) #
# - `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 && $5 > 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) * $16)}; printf OFS # native_network_transaction_fee_amount
# #
# Add new column to calculate the difference between amount and network fee, # Add new column to calculate the difference between amount and network fee,