mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
types,cmd: add IntervalMap type to refactor the interval code
This commit is contained in:
parent
d60dbe5e0b
commit
ea130e434c
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
@ -697,7 +696,7 @@ func confirmation(s string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
func getExchangeIntervals(ex types.Exchange) map[types.Interval]int {
|
||||
func getExchangeIntervals(ex types.Exchange) types.IntervalMap {
|
||||
exCustom, ok := ex.(types.CustomIntervalProvider)
|
||||
if ok {
|
||||
return exCustom.SupportedInterval()
|
||||
|
@ -705,13 +704,6 @@ func getExchangeIntervals(ex types.Exchange) map[types.Interval]int {
|
|||
return types.SupportedIntervals
|
||||
}
|
||||
|
||||
func sortIntervals(intervals []types.Interval) types.IntervalSlice {
|
||||
sort.Slice(intervals, func(i, j int) bool {
|
||||
return intervals[i].Duration() < intervals[j].Duration()
|
||||
})
|
||||
return intervals
|
||||
}
|
||||
|
||||
func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service.BacktestService, sourceExchanges map[types.ExchangeName]types.Exchange, syncFrom, syncTo time.Time) error {
|
||||
for _, symbol := range userConfig.Backtest.Symbols {
|
||||
for _, sourceExchange := range sourceExchanges {
|
||||
|
@ -722,11 +714,7 @@ func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service
|
|||
}
|
||||
|
||||
// sort intervals
|
||||
var intervals types.IntervalSlice
|
||||
for interval := range supportIntervals {
|
||||
intervals = append(intervals, interval)
|
||||
}
|
||||
|
||||
var intervals = supportIntervals.Slice()
|
||||
intervals.Sort()
|
||||
|
||||
for _, interval := range intervals {
|
||||
|
|
|
@ -142,7 +142,17 @@ func ParseInterval(input Interval) int {
|
|||
return t
|
||||
}
|
||||
|
||||
var SupportedIntervals = map[Interval]int{
|
||||
type IntervalMap map[Interval]int
|
||||
|
||||
func (m IntervalMap) Slice() (slice IntervalSlice) {
|
||||
for interval := range m {
|
||||
slice = append(slice, interval)
|
||||
}
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
var SupportedIntervals = IntervalMap{
|
||||
Interval1s: 1,
|
||||
Interval1m: 1 * 60,
|
||||
Interval3m: 3 * 60,
|
||||
|
|
Loading…
Reference in New Issue
Block a user