simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
2.97k stars 317 forks source link

The daedalus transactions example is wrong. #2171

Closed locallycompact closed 7 months ago

locallycompact commented 7 months ago

When using the daedalus transactions csv rules example as is, I get the following error.

hledger: Error: error: could not parse "2023-04-13T18:23:15.000Z" as a date using date format "%Y-%m-%dT%s%Q%Z"
simonmichael commented 7 months ago

Thanks for the report, it looks like the format changed in the last 3 years; it should now be %Y-%m-%dT%T%Q%Z. If you confirm, I'll update the example.

simonmichael commented 7 months ago

(Or if you find other issues, a PR is welcome.)

locallycompact commented 7 months ago

That does work! Thanks. If I find any more I will PR.

simonmichael commented 7 months ago

Actually the transactions CSV is more detailed now:

# 2021
# ID,Type,Amount,Date & time,Status,Addresses from,Addresses to,Withdrawals
fields id,type,amount,date,status_,addressesfrom,addressesto,withdrawals
# 2024 (5.3)
# ID,Type,TOTAL (ADA),Sent amount (ADA),Deposit amount (ADA),Fee (ADA),Tokens (unformatted amounts),Date & time,Status,Addresses from,Addresses to,Withdrawals
fields id, type, total_ada, sent_amount_ada, deposit_amount_ada, fee_ada, tokens, datetime, status, addresses_from, addresses_to, withdrawals

Let us know if you come up with a decent set of rules; I'll do the same.

simonmichael commented 7 months ago

I got sucked in to the puzzle. Here's my attempt:

# hledger CSV conversion rules for Daedalus's transactions export. Tested with daedalus 5.3.

# ID,Type,TOTAL (ADA),Sent amount (ADA),Deposit amount (ADA),Fee (ADA),Tokens (unformatted amounts),Date & time,Status,Addresses from,Addresses to,Withdrawals
fields id, type, total_ada, sent_ada, deposit_ada, fee_ada, tokens, datetime, status_, addresses_from, addresses_to, withdrawals
skip 1
date %datetime
date-format %Y-%m-%dT%T%Q%Z
newest-first
if ! %status_ Confirmed
 status !
description %type %tokens

account1 assets:cc:cardano:wallet1:YYYY-MM-DD

# Received
# posting 1 is for the wallet
# posting 2 is for the source

if %type Received
 comment \nfrom: %addresses_from\nto: %addresses_to\nwithdrawals: %withdrawals\ndatetime: %datetime\nstatus: %status_\ncc-ada-acquire:
 amount %total_ada ADA
 comment1 TODO: add lot date & cost

# Sent
# posting 1 is for the wallet
# posting 2 is for deposits
# posting 3 is for fees
# posting 4 is for the destination

if %type Sent
 comment \nfrom: %addresses_from\nto: %addresses_to\nwithdrawals: %withdrawals\ndatetime: %datetime\nstatus: %status_\ncc-ada-dispose:\nTODO: select source lots; add costs & prices & gain/loss
 amount1 %total_ada ADA

if %type Sent
& %deposit_ada [1-9]
 amount2  %deposit_ada ADA
 account2 assets:cc:cardano:wallet1:deposit
 description %type deposit

if %type Sent
& %fee_ada [1-9]
 amount3  %fee_ada ADA
 account3 expenses:fees:cardano

# The CSV duplicates the amount in sent deposit transactions so we need to avoid those here.
# &! is not yet supported, work around with regexp.
if %type Sent
& %sent_ada [1-9]
& %deposit_ada ^[^1-9]*$
 amount4  %sent_ada ADA
 account4 expenses:unknown

# Categorise manually, or add categorising rules below.

if %addresses_to addr1alksjdflkjsadfff098234lkjlkjasfd09234jlljkasdf09234jl
 account4 assets:cc:cardano:wallet2:YYYY-MM-DD
 comment4 TODO: add lot date & cost

Manual fixups are required, but the result is pretty useful I think.