rebalance: validate symbols

This commit is contained in:
なるみ 2022-06-16 03:24:39 +08:00
parent 3d0ad010eb
commit 8d9faff859
2 changed files with 9 additions and 3 deletions

View File

@ -18,5 +18,4 @@ exchangeStrategies:
threshold: 2%
# max amount to buy or sell per order
maxAmount: 10_000
verbose: true
dryRun: false

View File

@ -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)
})