diff --git a/cmd/http/router.go b/cmd/http/router.go index aa6ce18..fdf56b0 100644 --- a/cmd/http/router.go +++ b/cmd/http/router.go @@ -297,6 +297,11 @@ func (router Router) APIReg(w http.ResponseWriter, r *http.Request) { register := deltas.Register() predicted := make(ledger.Register) + bpis, err := router.bpis() + if err != nil { + panic(err) + } + if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 16); err == nil && predictionMonths > 0 { window := time.Hour * 24.0 * 365.0 / 12.0 * time.Duration(predictionMonths) // TODO whatif @@ -334,10 +339,6 @@ func (router Router) APIReg(w http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } - bpis, err := router.bpis() - if err != nil { - panic(err) - } bpis, err = ana.BPIsWithFixedGrowthPrediction(bpis, window, currency, rate) if err != nil { panic(err) @@ -346,10 +347,6 @@ func (router Router) APIReg(w http.ResponseWriter, r *http.Request) { } if r.URL.Query().Get("bpi") == "true" { - bpis, err := router.bpis() - if err != nil { - panic(err) - } register = register.WithBPIs(bpis) predicted = predicted.WithBPIs(bpis) }