mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
interval: finalize 1s support
interval: finalize 1s support interval: finalize 1s support
This commit is contained in:
parent
905c1f25ee
commit
18acd668a7
|
@ -381,7 +381,7 @@ func (e *Exchange) ConsumeKLine(k types.KLine, requiredInterval types.Interval)
|
|||
|
||||
requiredKline, ok := matching.klineCache[k.Interval]
|
||||
if ok { // pop out all the old
|
||||
if requiredKline.Interval.Seconds() < requiredInterval.Seconds() {
|
||||
if requiredKline.Interval != requiredInterval {
|
||||
panic(fmt.Sprintf("expect required kline interval %s, got interval %s", requiredInterval.String(), requiredKline.Interval.String()))
|
||||
}
|
||||
e.currentTime = requiredKline.EndTime.Time()
|
||||
|
|
|
@ -603,10 +603,10 @@ func collectSubscriptionIntervals(environ *bbgo.Environment) (allKLineIntervals
|
|||
for _, session := range environ.Sessions() {
|
||||
for _, sub := range session.Subscriptions {
|
||||
if sub.Channel == types.KLineChannel {
|
||||
if sub.Options.Interval == types.Interval1s {
|
||||
// if any subscription is 1s, then we will use 1s for back-testing
|
||||
requiredInterval = sub.Options.Interval
|
||||
log.Warnf("found 1s kline subscription, modify default backtest interval to 1s")
|
||||
if sub.Options.Interval.Seconds()%60 > 0 {
|
||||
// if any subscription interval is less than 60s, then we will use 1s for back-testing
|
||||
requiredInterval = types.Interval1s
|
||||
log.Warnf("found kline subscription interval less than 60s, modify default backtest interval to 1s")
|
||||
}
|
||||
allKLineIntervals[sub.Options.Interval] = struct{}{}
|
||||
}
|
||||
|
|
|
@ -233,13 +233,13 @@ func (e *Exchange) SetModifyOrderAmountForFee(feeRate types.ExchangeFee) {
|
|||
// resolution field in api
|
||||
// window length in seconds. options: 15, 60, 300, 900, 3600, 14400, 86400, or any multiple of 86400 up to 30*86400
|
||||
var supportedIntervals = map[types.Interval]int{
|
||||
types.Interval1m: 1,
|
||||
types.Interval5m: 5,
|
||||
types.Interval15m: 15,
|
||||
types.Interval1h: 60,
|
||||
types.Interval4h: 60 * 4,
|
||||
types.Interval1d: 60 * 24,
|
||||
types.Interval3d: 60 * 24 * 3,
|
||||
types.Interval1m: 1 * 60,
|
||||
types.Interval5m: 5 * 60,
|
||||
types.Interval15m: 15 * 60,
|
||||
types.Interval1h: 60 * 60,
|
||||
types.Interval4h: 60 * 60 * 4,
|
||||
types.Interval1d: 60 * 60 * 24,
|
||||
types.Interval3d: 60 * 60 * 24 * 3,
|
||||
}
|
||||
|
||||
func (e *Exchange) SupportedInterval() map[types.Interval]int {
|
||||
|
|
|
@ -139,10 +139,10 @@ func (e *Exchange) QueryTickers(ctx context.Context, symbols ...string) (map[str
|
|||
// From the doc
|
||||
// Type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 8hour, 12hour, 1day, 1week
|
||||
var supportedIntervals = map[types.Interval]int{
|
||||
types.Interval1m: 60,
|
||||
types.Interval5m: 60 * 5,
|
||||
types.Interval15m: 60 * 15,
|
||||
types.Interval30m: 60 * 30,
|
||||
types.Interval1m: 1 * 60,
|
||||
types.Interval5m: 5 * 60,
|
||||
types.Interval15m: 15 * 60,
|
||||
types.Interval30m: 30 * 60,
|
||||
types.Interval1h: 60 * 60,
|
||||
types.Interval2h: 60 * 60 * 2,
|
||||
types.Interval4h: 60 * 60 * 4,
|
||||
|
|
|
@ -1009,17 +1009,17 @@ func (e *Exchange) DefaultFeeRates() types.ExchangeFee {
|
|||
}
|
||||
|
||||
var SupportedIntervals = map[types.Interval]int{
|
||||
types.Interval1m: 1,
|
||||
types.Interval5m: 5,
|
||||
types.Interval15m: 15,
|
||||
types.Interval30m: 30,
|
||||
types.Interval1h: 60,
|
||||
types.Interval2h: 60 * 2,
|
||||
types.Interval4h: 60 * 4,
|
||||
types.Interval6h: 60 * 6,
|
||||
types.Interval12h: 60 * 12,
|
||||
types.Interval1d: 60 * 24,
|
||||
types.Interval3d: 60 * 24 * 3,
|
||||
types.Interval1m: 1 * 60,
|
||||
types.Interval5m: 5 * 60,
|
||||
types.Interval15m: 15 * 60,
|
||||
types.Interval30m: 30 * 60,
|
||||
types.Interval1h: 60 * 60,
|
||||
types.Interval2h: 60 * 60 * 2,
|
||||
types.Interval4h: 60 * 60 * 4,
|
||||
types.Interval6h: 60 * 60 * 6,
|
||||
types.Interval12h: 60 * 60 * 12,
|
||||
types.Interval1d: 60 * 60 * 24,
|
||||
types.Interval3d: 60 * 60 * 24 * 3,
|
||||
}
|
||||
|
||||
func (e *Exchange) SupportedInterval() map[types.Interval]int {
|
||||
|
|
|
@ -12,9 +12,9 @@ type Interval string
|
|||
func (i Interval) Minutes() int {
|
||||
m, ok := SupportedIntervals[i]
|
||||
if !ok {
|
||||
return int(ParseInterval(i) / 60.)
|
||||
return ParseInterval(i) / 60
|
||||
}
|
||||
return m
|
||||
return m / 60
|
||||
}
|
||||
|
||||
func (i Interval) Seconds() int {
|
||||
|
@ -87,13 +87,13 @@ func ParseInterval(input Interval) int {
|
|||
case "m":
|
||||
t *= 60
|
||||
case "h":
|
||||
t *= 60
|
||||
t *= 60 * 60
|
||||
case "d":
|
||||
t *= 60 * 24
|
||||
t *= 60 * 60 * 24
|
||||
case "w":
|
||||
t *= 60 * 24 * 7
|
||||
t *= 60 * 60 * 24 * 7
|
||||
case "mo":
|
||||
t *= 60 * 24 * 30
|
||||
t *= 60 * 60 * 24 * 30
|
||||
default:
|
||||
panic("unknown interval input: " + input)
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
)
|
||||
|
||||
func TestParseInterval(t *testing.T) {
|
||||
assert.Equal(t, ParseIntervalSeconds("1s"), 1)
|
||||
assert.Equal(t, ParseInterval("3m"), 3)
|
||||
assert.Equal(t, ParseInterval("15h"), 15*60)
|
||||
assert.Equal(t, ParseInterval("72d"), 72*24*60)
|
||||
assert.Equal(t, ParseInterval("3Mo"), 3*30*24*60)
|
||||
assert.Equal(t, ParseInterval("1s"), 1)
|
||||
assert.Equal(t, ParseInterval("3m"), 3*60)
|
||||
assert.Equal(t, ParseInterval("15h"), 15*60*60)
|
||||
assert.Equal(t, ParseInterval("72d"), 72*24*60*60)
|
||||
assert.Equal(t, ParseInterval("3Mo"), 3*30*24*60*60)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user