use interval [1m/3m/5m/15m/30m/1H/2H/4H] and [/6Hutc/12Hutc/1Dutc/2Dutc/3Dutc/1Wutc/1Mutc] and add unit test

This commit is contained in:
Alan.sung 2023-10-03 16:59:46 +08:00
parent d200232c13
commit a83335817e
3 changed files with 38 additions and 18 deletions

View File

@ -215,11 +215,24 @@ func toLocalInterval(interval types.Interval) (string, error) {
case strings.HasSuffix(i, "m"):
return i, nil
case strings.HasSuffix(i, "mo"):
return "1M", nil
return "1Mutc", nil
default:
hdwRegex := regexp.MustCompile("\\d+[hdw]$")
hdwRegex := regexp.MustCompile("\\d+[dw]$")
if hdwRegex.Match([]byte(i)) {
return strings.ToUpper(i), nil
return strings.ToUpper(i) + "utc", nil
}
hdwRegex = regexp.MustCompile("(\\d+)[h]$")
if fs := hdwRegex.FindStringSubmatch(i); 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(i) + "utc", nil
} else {
return strings.ToUpper(i), nil
}
}
}
return "", fmt.Errorf("interval %s is not supported", interval)

View File

@ -30,13 +30,20 @@ func Test_QueryKlines(t *testing.T) {
if assert.NoError(t, err) {
assert.NotEmpty(t, klineDetail)
}
// test supported interval - hour
// test supported interval - hour - 1 hour
klineDetail, err = e.QueryKLines(context.Background(), queryOrder.Symbol, types.Interval1h, types.KLineQueryOptions{
Limit: 50,
EndTime: &now})
if assert.NoError(t, err) {
assert.NotEmpty(t, klineDetail)
}
// test supported interval - hour - 6 hour to test UTC time
klineDetail, err = e.QueryKLines(context.Background(), queryOrder.Symbol, types.Interval6h, types.KLineQueryOptions{
Limit: 50,
EndTime: &now})
if assert.NoError(t, err) {
assert.NotEmpty(t, klineDetail)
}
// test supported interval - day
klineDetail, err = e.QueryKLines(context.Background(), queryOrder.Symbol, types.Interval1d, types.KLineQueryOptions{
Limit: 50,

View File

@ -22,19 +22,19 @@ var (
}
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,
"6H": types.Interval6h,
"12H": types.Interval12h,
"1D": types.Interval1d,
"3D": types.Interval3d,
"1W": types.Interval1w,
"1M": types.Interval1mo,
"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,
}
)