turn ToGlobalInterval to ToLocalInterval, use Map to turn to local interval

This commit is contained in:
Alan.sung 2023-10-04 14:23:13 +08:00
parent 0b5ce231ff
commit 3b793b79b6
2 changed files with 17 additions and 38 deletions

View File

@ -2,7 +2,6 @@ package okex
import (
"fmt"
"regexp"
"strconv"
"strings"
@ -211,30 +210,10 @@ func toLocalInterval(interval types.Interval) (string, error) {
return "", fmt.Errorf("interval %s is not supported", interval)
}
switch in := interval.String(); {
case strings.HasSuffix(in, "m"):
if in, ok := ToLocalInterval[interval]; ok {
return in, nil
case strings.HasSuffix(in, "mo"):
return "1Mutc", nil
default:
hdwRegex := regexp.MustCompile(`\d+[dw]$`)
if hdwRegex.Match([]byte(in)) {
return strings.ToUpper(in) + "utc", nil
}
hdwRegex = regexp.MustCompile(`(\d+)[h]$`)
if fs := hdwRegex.FindStringSubmatch(in); len(fs) > 0 {
digits, err := strconv.ParseInt(string(fs[1]), 10, 64)
if err != nil {
return "", fmt.Errorf("interval %s is not supported", interval)
}
if digits >= 6 {
return strings.ToUpper(in) + "utc", nil
} else {
return strings.ToUpper(in), nil
}
}
}
return "", fmt.Errorf("interval %s is not supported", interval)
}

View File

@ -21,20 +21,20 @@ var (
types.Interval1mo: 60 * 60 * 24 * 30,
}
ToGlobalInterval = map[string]types.Interval{
"1m": types.Interval1m,
"3m": types.Interval3m,
"5m": types.Interval5m,
"15m": types.Interval15m,
"30m": types.Interval30m,
"1H": types.Interval1h,
"2H": types.Interval2h,
"4H": types.Interval4h,
"6Hutc": types.Interval6h,
"12Hutc": types.Interval12h,
"1Dutc": types.Interval1d,
"3Dutc": types.Interval3d,
"1Wutc": types.Interval1w,
"1Mutc": types.Interval1mo,
ToLocalInterval = map[types.Interval]string{
types.Interval1m: "1m",
types.Interval3m: "3m",
types.Interval5m: "5m",
types.Interval15m: "15m",
types.Interval30m: "30m",
types.Interval1h: "1H",
types.Interval2h: "2H",
types.Interval4h: "4H",
types.Interval6h: "6Hutc",
types.Interval12h: "12Hutc",
types.Interval1d: "1Dutc",
types.Interval3d: "3Dutc",
types.Interval1w: "1Wutc",
types.Interval1mo: "1Mutc",
}
)