6 "git.immae.eu/Cryptoportfolio/Front.git/db"
7 "github.com/shopspring/decimal"
10 type GetAllPortfoliosQuery struct {
15 Portfolios map[string]Portfolio `json:"portfolios"`
16 TotalBTCValue decimal.Decimal `json:"totalBtcValue"`
17 TotalBTCVariation decimal.Decimal `json:"totalBtcVariation"`
21 func (q GetAllPortfoliosQuery) ValidateParams() *Error {
22 if q.In.Market != "poloniex" {
23 return &Error{BadRequest, "invalid market name", fmt.Errorf("'%v' is not a valid market name", q.In.Market)}
29 func (q GetAllPortfoliosQuery) Run() (interface{}, *Error) {
30 u, err := db.GetActiveUsers()
32 return nil, NewInternalError(err)
35 q.Out.Portfolios = make(map[string]Portfolio)
37 for _, marketConfig := range u {
38 report, err := GetWeekPortfolio(marketConfig)
39 if ErrorIs(err, NotFound) {
44 return nil, NewInternalError(err)
47 q.Out.Portfolios[marketConfig.User.Email] = report.Round()
48 q.Out.TotalBTCValue = q.Out.TotalBTCValue.Add(report.Performance.Value)
49 q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Add(report.Performance.Variation)
52 q.Out.TotalBTCValue = q.Out.TotalBTCValue.Round(3)
53 q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Round(3)