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