add more checks for bollgrid

related to #93
This commit is contained in:
c9s 2021-02-13 16:03:11 +08:00
parent de195b3c17
commit f8378957ee
3 changed files with 23 additions and 7 deletions

View File

@ -24,7 +24,7 @@ sessions:
max:
exchange: max
envVarPrefix: max
envVarPrefix: MAX
riskControls:
# This is the session-based risk controller, which let you configure different risk controller by session.
@ -62,7 +62,7 @@ exchangeStrategies:
- on: max
bollgrid:
symbol: BTCUSDT
interval: 1h
gridNumber: 100
quantity: 0.002
profitSpread: 10.0
interval: 5m
gridNumber: 2
quantity: 0.001
profitSpread: 100.0

View File

@ -347,7 +347,15 @@ func (session *ExchangeSession) InitSymbol(ctx context.Context, environ *Environ
usedKLineIntervals[types.Interval1m] = struct{}{}
for _, sub := range session.Subscriptions {
if sub.Symbol == symbol && sub.Channel == types.KLineChannel {
if sub.Channel != types.KLineChannel {
continue
}
if sub.Options.Interval == "" {
continue
}
if sub.Symbol == symbol {
usedKLineIntervals[types.Interval(sub.Options.Interval)] = struct{}{}
}
}
@ -445,6 +453,10 @@ func (session *ExchangeSession) OrderStores() map[string]*OrderStore {
// Subscribe save the subscription info, later it will be assigned to the stream
func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession {
if channel == types.KLineChannel && len(options.Interval) == 0 {
panic("subscription interval for kline can not be empty")
}
sub := types.Subscription{
Channel: channel,
Symbol: symbol,

View File

@ -89,10 +89,14 @@ func (s *Strategy) ID() string {
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
if s.Interval == "" {
panic("bollgrid interval can not be empty")
}
// currently we need the 1m kline to update the last close price and indicators
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval.String()})
if s.Interval != s.RepostInterval {
if len(s.RepostInterval) > 0 && s.Interval != s.RepostInterval {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.RepostInterval.String()})
}
}