From 8baafdf329b619b60445ee96b4da537863056622 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 8 Jun 2023 23:15:26 +0800 Subject: [PATCH] xalign: add DryRun and fix quote amount calculation --- pkg/strategy/xalign/strategy.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 5c4457203..a0721afcc 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -32,6 +32,7 @@ type Strategy struct { PreferredQuoteCurrencies *QuoteCurrencyPreference `json:"quoteCurrencies"` ExpectedBalances map[string]fixedpoint.Value `json:"expectedBalances"` UseTakerOrder bool `json:"useTakerOrder"` + DryRun bool `json:"dryRun"` orderBook map[string]*bbgo.ActiveOrderBook } @@ -92,7 +93,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st for _, sessionName := range s.PreferredSessions { session := sessions[sessionName] - var taker bool = s.UseTakerOrder + var taker = s.UseTakerOrder var side types.SideType var quoteCurrencies []string if changeQuantity.Sign() > 0 { @@ -137,7 +138,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st price = ticker.Buy } - requiredQuoteAmount := q.Div(price) + requiredQuoteAmount := q.Mul(price) if requiredQuoteAmount.Compare(quoteBalance.Available) < 0 { log.Warnf("required quote amount %f < quote balance %v", requiredQuoteAmount.Float64(), quoteBalance) continue @@ -250,9 +251,12 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange selectedSession, submitOrder := s.selectSessionForCurrency(ctx, sessions, currency, q) if selectedSession != nil && submitOrder != nil { - log.Infof("placing order on %s: %#v", selectedSession.Name, submitOrder) + if s.DryRun { + return + } + createdOrder, err := selectedSession.Exchange.SubmitOrder(ctx, *submitOrder) if err != nil { log.WithError(err).Errorf("can not place order")