From 8d9faff8595489c4a1521ef9b34fa7404fb59c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=81=BF?= Date: Thu, 16 Jun 2022 03:24:39 +0800 Subject: [PATCH] rebalance: validate symbols --- config/rebalance.yaml | 1 - pkg/strategy/rebalance/strategy.go | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config/rebalance.yaml b/config/rebalance.yaml index cc4744662..6780da1d3 100644 --- a/config/rebalance.yaml +++ b/config/rebalance.yaml @@ -18,5 +18,4 @@ exchangeStrategies: threshold: 2% # max amount to buy or sell per order maxAmount: 10_000 - verbose: true dryRun: false diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 97d4ec7e5..4c318a97b 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -26,9 +26,9 @@ type Strategy struct { BaseCurrency string `json:"baseCurrency"` TargetWeights fixedpoint.ValueMap `json:"targetWeights"` Threshold fixedpoint.Value `json:"threshold"` - Verbose bool `json:"verbose"` DryRun bool `json:"dryRun"` - MaxAmount fixedpoint.Value `json:"maxAmount"` // max amount to buy or sell per order + // max amount to buy or sell per order + MaxAmount fixedpoint.Value `json:"maxAmount"` activeOrderBook *bbgo.ActiveOrderBook } @@ -75,6 +75,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.activeOrderBook = bbgo.NewActiveOrderBook("") s.activeOrderBook.BindStream(session.UserDataStream) + markets := session.Markets() + for _, symbol := range s.symbols() { + if _, ok := markets[symbol]; !ok { + return fmt.Errorf("exchange: %s does not supoort matket: %s", session.Exchange.Name(), symbol) + } + } + session.MarketDataStream.OnKLineClosed(func(kline types.KLine) { s.rebalance(ctx, orderExecutor, session) })