Skip to content

Commit

Permalink
bollgrid: submit orders on connect
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 12, 2020
1 parent 8cc1c58 commit 1a6f5b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/bollgrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ riskControls:
minQuoteBalance: 100.0
maxBaseAssetBalance: 3.0
minBaseAssetBalance: 0.0
maxOrderAmount: 1000.0
maxOrderAmount: 2000.0

backtest:
# for testing max draw down (MDD) at 03-12
Expand Down
12 changes: 10 additions & 2 deletions pkg/strategy/bollgrid/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,17 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se

s.Graceful.OnShutdown(func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()

log.Infof("canceling active orders...")

if err := session.Exchange.CancelOrders(ctx, s.activeOrders.Orders()...); err != nil {
log.WithError(err).Errorf("cancel order error")
}
})

session.Stream.OnConnect(func() {
s.updateOrders(orderExecutor, session)
})

// avoid using time ticker since we will need back testing here
session.Stream.OnKLineClosed(func(kline types.KLine) {
// skip kline events that does not belong to this symbol
Expand All @@ -337,8 +340,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
return
}

if (s.RepostInterval != "" && (s.RepostInterval == kline.Interval)) || s.Interval == kline.Interval {
if s.RepostInterval != "" {
// see if we have enough balances and then we create limit orders on the up band and the down band.
if s.RepostInterval == kline.Interval {
s.updateOrders(orderExecutor, session)
}

} else if s.Interval == kline.Interval {
s.updateOrders(orderExecutor, session)
}
})
Expand Down

0 comments on commit 1a6f5b9

Please sign in to comment.