-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
41 lines (35 loc) · 1.43 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
package main
import (
"fmt"
"github.com/neshcheretal/ffparser/dividends"
"github.com/neshcheretal/ffparser/excel"
"github.com/neshcheretal/ffparser/jsonreport"
"github.com/neshcheretal/ffparser/trading"
"github.com/neshcheretal/ffparser/validator"
)
func main() {
// Get user input and convert it to a proper format
inputValues, err := validator.InputParse()
if err != nil {
fmt.Printf("Error while parsing cli arguments: %v", err)
return
}
// Parse the broker report JSON file
jsonParsedReport, err := jsonreport.ParseJsonReport(inputValues.FileName)
if err != nil {
fmt.Printf("Error while parsing broker report json file: %v", err)
return
}
// Define channels for concurrent trade and divident calculation
divCh := make(chan []dividends.CashFlow)
tradeCh := make(chan map[string][]trading.Trade)
go dividends.DividendsPreparationWrapper(jsonParsedReport.Cash_flows.Detailed, inputValues.StartDate, inputValues.EndDate, divCh)
go trading.StockTradePreparationWrapper(jsonParsedReport, inputValues.StartDate, inputValues.EndDate, tradeCh)
// Pass channels with results of calculation to excel report prep function
tax_report := excel.ExelCreate(tradeCh, divCh, inputValues.ReportLang)
if err := tax_report.SaveAs(inputValues.OutputFile); err != nil {
fmt.Printf("Failed to save report file %v: %v", inputValues.OutputFile, err)
} else {
fmt.Printf("Report file %v has been successfully generated", inputValues.OutputFile)
}
}