This repository has been archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (65 loc) · 1.78 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"github.com/fho/cryptotax/accounting"
"github.com/fho/cryptotax/import/coinbase"
"github.com/fho/cryptotax/import/kraken"
"github.com/fho/cryptotax/transaction"
)
func errCheck(err error) {
if err == nil {
return
}
log.Fatalln(err)
}
/*
TODO:
- if a currency is bought in a cryptocurrency, the owned amount of it has to be reduced
- add testcases
- review big float use
*/
func main() {
var coinbaseFileFlag string
var krakenFileFlag string
var taxYear uint
flag.StringVar(&coinbaseFileFlag, "coinbase-csv", "", "path to a coinbase taxhistory csv file")
flag.StringVar(&krakenFileFlag, "kraken-csv", "", "path to a kraken trades csv file")
flag.UintVar(&taxYear, "tax-year", uint(time.Now().Year())-1, "year for that the report is created")
flag.Parse()
if len(coinbaseFileFlag) == 0 && len(krakenFileFlag) == 0 {
fmt.Printf("Error: You have to specify the path to at least 1 csv file\n\n")
flag.Usage()
os.Exit(1)
}
var records []*transaction.Tx
if len(coinbaseFileFlag) != 0 {
log.Printf("reading %s", coinbaseFileFlag)
cp := coinbase.Import{}
coinbaseRecords, err := cp.FromCSV(coinbaseFileFlag)
errCheck(err)
records = append(records, coinbaseRecords...)
}
if len(krakenFileFlag) != 0 {
log.Printf("reading %s", krakenFileFlag)
cp := kraken.Import{}
krakenRecords, err := cp.FromCSV(krakenFileFlag)
errCheck(err)
records = append(records, krakenRecords...)
}
book, err := accounting.NewBook(records, int(taxYear))
errCheck(err)
err = book.Calculate()
errCheck(err)
fmt.Println(book)
fmt.Println()
fmt.Println("TAX REPORT Full")
fmt.Println(book.TaxReport(true))
fmt.Println("================")
fmt.Printf("TAX REPORT %v\n", taxYear)
fmt.Println(book.TaxReport(false))
fmt.Println()
}