diff --git a/container/src/hledger-flow/accounts/gemini/gemini-exchange-shared.rules b/container/src/hledger-flow/accounts/gemini/gemini-exchange-shared.rules index 7645fa0..6fc31db 100644 --- a/container/src/hledger-flow/accounts/gemini/gemini-exchange-shared.rules +++ b/container/src/hledger-flow/accounts/gemini/gemini-exchange-shared.rules @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -fields code_,date,type,order_type,currency_one,currency_two,amount_,cost,fees,destination,txid,direction,subaccount +fields code_,date,type,order_type,currency_one,currency_two,amount_,cost,fees,cost_basis,destination,txid,direction,subaccount date-format %Y-%m-%d %H:%M:%S description %date +0000 @@ -92,12 +92,24 @@ if %type ^TRADE$ if %order_type ^Buy$ amount %amount_ %currency_one @@ %cost %currency_two comment type:%type, order_type:%order_type, order_id:%txid, tid:%code_, taxed_as:BUY - comment2 %date +0000,BUY,gemini,%currency_one,%amount_,%currency_two,%cost,%currency_two,%fees + comment2 %date +0000,BUY,gemini,%currency_one,%amount_,%currency_two,%cost_basis,%currency_two,%fees +# TODO: HACK: re: #51, FeeCurrency and Fee are added even though cost_basis is calculated (for non-fiat fee disposal, see lib_taxes) + +# TODO: HACK: see #51 and respective lib_taxes work-around +if %order_type ^Buy$ +& %currency_two ^USD$ + comment2 %date +0000,BUY,gemini,%currency_one,%amount_,%currency_two,%cost_basis,, if %order_type ^Sell$ amount -%amount_ %currency_one @@ %cost %currency_two comment type:%type, order_type:%order_type, order_id:%txid, tid:%code_, taxed_as:SELL - comment2 %date +0000,SELL,gemini,%currency_one,%amount_,%currency_two,%cost,%currency_two,%fees + comment2 %date +0000,SELL,gemini,%currency_one,%amount_,%currency_two,%cost_basis,%currency_two,%fees +# TODO: HACK: re: #51, FeeCurrency and Fee are added even though cost_basis is calculated (for non-fiat fee disposal, see lib_taxes) + +# TODO: HACK: see #51 and respective lib_taxes work-around +if %order_type ^Sell$ +& %currency_two ^USD$ + comment2 %date +0000,SELL,gemini,%currency_one,%amount_,%currency_two,%cost_basis,, # GUSD/USD workaround (see preprocess) if %type ^TRADE$ diff --git a/container/src/hledger-flow/accounts/gemini/gemini-shared.bash b/container/src/hledger-flow/accounts/gemini/gemini-shared.bash index 1340634..df3c0f5 100755 --- a/container/src/hledger-flow/accounts/gemini/gemini-shared.bash +++ b/container/src/hledger-flow/accounts/gemini/gemini-shared.bash @@ -111,6 +111,7 @@ function parse_transfers() } printf info_feeAmount OFS + printf OFS # Cost-basis (N/A) printf $8 OFS # Destination (info_destination) printf $9 OFS # TXID (info_txHash) @@ -176,6 +177,7 @@ function parse_transfers() printf OFS # Price (N/A) printf OFS # Fees (N/A) + printf OFS # Cost-basis (N/A) printf $6 OFS # Destination (info_destination) printf $7 OFS # TXID (info_txHash) @@ -250,6 +252,23 @@ function parse_trades() } printf fee_amount OFS # Fees + # TODO: HACK: see #51 and respective lib_taxes work-around + # Calculate cost-basis + switch ($5) + { + case "Buy": + cost_basis=sprintf("%.8f", cost + fee_amount) + break + case "Sell": + cost_basis=sprintf("%.8f", cost - fee_amount) + break + default: + printf "FATAL: unsupported order type: " $5 + print $0 + exit + } + printf cost_basis OFS + printf OFS # Destination (N/A) printf $10 OFS # TXID (tid) @@ -309,6 +328,7 @@ function parse_earn() printf priceAmount OFS printf OFS # Fees + printf OFS # Cost-basis printf OFS # Destination printf OFS # TXID