mirror of
https://github.com/miguelmota/cointop
synced 2024-11-10 13:10:26 +00:00
Allow negative holdings balance input. #87
This commit is contained in:
parent
faabbfc8a6
commit
3aed9846fe
@ -415,7 +415,7 @@ func (ct *Cointop) SetPortfolioHoldings() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
value := normalizeFloatString(string(b))
|
value := normalizeFloatString(string(b), true)
|
||||||
shouldDelete := value == ""
|
shouldDelete := value == ""
|
||||||
var holdings float64
|
var holdings float64
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ func (ct *Cointop) ParsePriceAlertInput(value string) (string, float64, error) {
|
|||||||
operator = matches[1]
|
operator = matches[1]
|
||||||
amountValue = matches[2]
|
amountValue = matches[2]
|
||||||
}
|
}
|
||||||
amountValue = normalizeFloatString(amountValue)
|
amountValue = normalizeFloatString(amountValue, false)
|
||||||
targetPrice, err := strconv.ParseFloat(amountValue, 64)
|
targetPrice, err := strconv.ParseFloat(amountValue, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
|
@ -53,8 +53,11 @@ func (ct *Cointop) ClearSyncMap(syncMap sync.Map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NormalizeFloatString normalizes a float as a string
|
// 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+)`)
|
re := regexp.MustCompile(`(\d+\.\d+|\.\d+|\d+)`)
|
||||||
|
if allowNegative {
|
||||||
|
re = regexp.MustCompile(`-?(\d+\.\d+|\.\d+|\d+)`)
|
||||||
|
}
|
||||||
result := re.FindStringSubmatch(input)
|
result := re.FindStringSubmatch(input)
|
||||||
if len(result) > 0 {
|
if len(result) > 0 {
|
||||||
return result[0]
|
return result[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user