Skip to content

Commit

Permalink
use interval [1m/3m/5m/15m/30m/1H/2H/4H] and [/6Hutc/12Hutc/1Dutc/2Du…
Browse files Browse the repository at this point in the history
…tc/3Dutc/1Wutc/1Mutc] and add unit test
  • Loading branch information
Alan.sung authored and Alan.sung committed Oct 3, 2023
1 parent 23dd7b0 commit 5621082
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
19 changes: 16 additions & 3 deletions pkg/exchange/okex/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion pkg/exchange/okex/query_kline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions pkg/exchange/okex/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)

0 comments on commit 5621082

Please sign in to comment.