A csv file containing stock trades with number of shares, price and cost.
I would like hledger verify all the numbers.
2022-12-12,name1,10,123.45,1234.50
2022-12-14,name2,20,11.11,222.20
The simple rule file
date %1
amount-in %3 "%2" @ %4 EUR
amount-out -%5 EUR
produces the following error:
hledger: Error: in CSV rules:
While processing CSV record: "2022-12-12","name1","10","123.45","1234.50"
while calculating amount for posting 1
rule "amount-in %3 "%2" @ %4 EUR" assigned value "10 "name1" @ 123.45 EUR"
rule "amount-out -%5 EUR" assigned value "-1234.50 EUR"
Multiple non-zero amounts were assigned for an amount field.
Please ensure just one non-zero amount is assigned, perhaps with an if rule.
See also: https://hledger.org/hledger.html#setting-amounts
(hledger manual -> CSV format -> Tips -> Setting amounts)
In the manual under point 3 I find Assign to amount (or to amount-in and amount-out).
I interpret this as "it should work".
But a issue search found this statement
1. in is NOT empty , out in NOT empty. Impossible to interpret, and we will error out
This I don't understand. If both are set hledger csv import should (and does! - see below) test the generated statement.
Also for statements with taxes and costs I generated entries with 3 and more accounts. And this simple test worked.
rules:
date %1
amount1 %3 "%2" @ %4 EUR
amount2 0
amount3 -%5 EUR
result:
2022-12-12
expenses:unknown 10 "name1" @ 123.45 EUR
expenses:unknown 0
income:unknown -1234.50 EUR
2022-12-14
expenses:unknown 20 "name2" @ 11.11 EUR
expenses:unknown 0
income:unknown -222.20 EUR
Optimising the rules to
amount1 %3 "%2" @ %4 EUR
amount2 -%5 EUR
or
amount1-in %3 "%2" @ %4 EUR
amount2-out %5 EUR
generates the desired result:
2022-12-12
expenses:unknown 10 "name1" @ 123.45 EUR
income:unknown -1234.50 EUR
2022-12-14
expenses:unknown 20 "name2" @ 11.11 EUR
income:unknown -222.20 EUR
Changing the cost to 1234.56 will produce the desired error.
hledger: Error: /Users/markus/repos/finance/test.csv:1-0:
1 | 2022-12-12
| expenses:unknown 10 "name1" @ 123.45 EUR
| income:unknown -1234.56 EUR
This multi-commodity transaction is unbalanced.
The real postings' sum should be 0 but is: -0.06 EUR
Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.
long story short
I'm using: hledger 1.28
Except for amount-in and amount-out all works as expected.
In my point of view the documentation is correct and the unexpected behaviour is due the wrong first point of this statement.
A csv file containing stock trades with number of shares, price and cost.
I would like hledger verify all the numbers.
The simple rule file
produces the following error:
In the manual under point 3 I find Assign to amount (or to amount-in and amount-out).
I interpret this as "it should work".
But a issue search found this statement
This I don't understand. If both are set hledger csv import should (and does! - see below) test the generated statement.
Also for statements with taxes and costs I generated entries with 3 and more accounts. And this simple test worked.
rules:
result:
Optimising the rules to
or
generates the desired result:
Changing the cost to 1234.56 will produce the desired error.
long story short
I'm using: hledger 1.28
Except for amount-in and amount-out all works as expected.
In my point of view the documentation is correct and the unexpected behaviour is due the wrong first point of this statement.