mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +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"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"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)
|
exCustom, ok := ex.(types.CustomIntervalProvider)
|
||||||
if ok {
|
if ok {
|
||||||
return exCustom.SupportedInterval()
|
return exCustom.SupportedInterval()
|
||||||
|
@ -705,13 +704,6 @@ func getExchangeIntervals(ex types.Exchange) map[types.Interval]int {
|
||||||
return types.SupportedIntervals
|
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 {
|
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 _, symbol := range userConfig.Backtest.Symbols {
|
||||||
for _, sourceExchange := range sourceExchanges {
|
for _, sourceExchange := range sourceExchanges {
|
||||||
|
@ -722,11 +714,7 @@ func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort intervals
|
// sort intervals
|
||||||
var intervals types.IntervalSlice
|
var intervals = supportIntervals.Slice()
|
||||||
for interval := range supportIntervals {
|
|
||||||
intervals = append(intervals, interval)
|
|
||||||
}
|
|
||||||
|
|
||||||
intervals.Sort()
|
intervals.Sort()
|
||||||
|
|
||||||
for _, interval := range intervals {
|
for _, interval := range intervals {
|
||||||
|
|
|
@ -142,7 +142,17 @@ func ParseInterval(input Interval) int {
|
||||||
return t
|
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,
|
Interval1s: 1,
|
||||||
Interval1m: 1 * 60,
|
Interval1m: 1 * 60,
|
||||||
Interval3m: 3 * 60,
|
Interval3m: 3 * 60,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user