mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
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:
parent
d200232c13
commit
a83335817e
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user