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, diff --git a/container/src/hledger-flow/accounts/coinbase/coinbase-shared.rules b/container/src/hledger-flow/accounts/coinbase/coinbase-shared.rules index eea2fb1..1eb8664 100644 --- a/container/src/hledger-flow/accounts/coinbase/coinbase-shared.rules +++ b/container/src/hledger-flow/accounts/coinbase/coinbase-shared.rules @@ -656,7 +656,6 @@ if %type ^advanced_trade_fill$ if %type ^advanced_trade_fill$ & %advanced_trade_fill_order_side (^buy$|^sell$) -& %advanced_trade_fill_real_value_amount [1-9] account1 assets:coinbase:%subaccount:%advanced_trade_fill_pair_lhs account2 assets:coinbase:%subaccount:%advanced_trade_fill_pair_rhs amount3 -%advanced_trade_fill_commission %advanced_trade_fill_pair_rhs @@ -664,6 +663,13 @@ if %type ^advanced_trade_fill$ amount4 %advanced_trade_fill_commission %advanced_trade_fill_pair_rhs account4 expenses:coinbase:%subaccount:fees:trading:%advanced_trade_fill_pair_rhs +# NOTE: see WARNING in preprocess about $0.00 Advanced Trade txs +if %type ^advanced_trade_fill$ +& %advanced_trade_fill_order_side (^buy$|^sell$) +& %advanced_trade_fill_real_value_amount ^[^1-9]*$ + account1 + account2 + # # BUY #