Allow negative holdings balance input. #87

pull/94/head
Miguel Mota 3 years ago
parent faabbfc8a6
commit 3aed9846fe

@ -415,7 +415,7 @@ func (ct *Cointop) SetPortfolioHoldings() error {
return nil
}
value := normalizeFloatString(string(b))
value := normalizeFloatString(string(b), true)
shouldDelete := value == ""
var holdings float64

@ -403,7 +403,7 @@ func (ct *Cointop) ParsePriceAlertInput(value string) (string, float64, error) {
operator = matches[1]
amountValue = matches[2]
}
amountValue = normalizeFloatString(amountValue)
amountValue = normalizeFloatString(amountValue, false)
targetPrice, err := strconv.ParseFloat(amountValue, 64)
if err != nil {
return "", 0, err

@ -53,8 +53,11 @@ func (ct *Cointop) ClearSyncMap(syncMap sync.Map) {
}
// NormalizeFloatString normalizes a float as a string
func normalizeFloatString(input string) string {
func normalizeFloatString(input string, allowNegative bool) string {
re := regexp.MustCompile(`(\d+\.\d+|\.\d+|\d+)`)
if allowNegative {
re = regexp.MustCompile(`-?(\d+\.\d+|\.\d+|\d+)`)
}
result := re.FindStringSubmatch(input)
if len(result) > 0 {
return result[0]

Loading…
Cancel
Save