From 020e7c8604622f1de05fe8357ff8aab175d0f220 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 24 Nov 2022 16:35:31 +0800 Subject: [PATCH] grid2: handle grid orders submission --- pkg/strategy/grid2/strategy.go | 49 +++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 6a28059c2..fbbbed77c 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -369,11 +369,14 @@ func (s *Strategy) setupGridOrders(ctx context.Context, session *bbgo.ExchangeSe if price.Compare(lastPrice) >= 0 { if usedBase.Add(quantity).Compare(totalBase) < 0 { submitOrders = append(submitOrders, types.SubmitOrder{ - Symbol: s.Symbol, - Type: types.OrderTypeLimitMaker, - Side: types.SideTypeSell, - Price: price, - Quantity: quantity, + Symbol: s.Symbol, + Type: types.OrderTypeLimitMaker, + Side: types.SideTypeSell, + Price: price, + Quantity: quantity, + Market: s.Market, + TimeInForce: types.TimeInForceGTC, + Tag: "grid", }) usedBase = usedBase.Add(quantity) } else if i > 0 { @@ -381,35 +384,43 @@ func (s *Strategy) setupGridOrders(ctx context.Context, session *bbgo.ExchangeSe nextPin := pins[i-1] nextPrice := fixedpoint.Value(nextPin) submitOrders = append(submitOrders, types.SubmitOrder{ - Symbol: s.Symbol, - Type: types.OrderTypeLimitMaker, - Side: types.SideTypeBuy, - Price: nextPrice, - Quantity: quantity, + Symbol: s.Symbol, + Type: types.OrderTypeLimitMaker, + Side: types.SideTypeBuy, + Price: nextPrice, + Quantity: quantity, + Market: s.Market, + TimeInForce: types.TimeInForceGTC, + Tag: "grid", }) quoteQuantity := quantity.Mul(price) usedQuote = usedQuote.Add(quoteQuantity) buyPlacedPrice = nextPrice } } else { - } + if price.Compare(buyPlacedPrice) >= 0 { + continue + } - /* - createdOrders, err2 := s.orderExecutor.SubmitOrders(ctx, types.SubmitOrder{ + submitOrders = append(submitOrders, types.SubmitOrder{ Symbol: s.Symbol, + Type: types.OrderTypeLimitMaker, Side: types.SideTypeBuy, - Type: types.OrderTypeLimit, - Quantity: quantity, Price: price, + Quantity: quantity, Market: s.Market, TimeInForce: types.TimeInForceGTC, Tag: "grid", }) + quoteQuantity := quantity.Mul(price) + usedQuote = usedQuote.Add(quoteQuantity) + } - if err2 != nil { - return err2 - } - */ + createdOrders, err2 := s.orderExecutor.SubmitOrders(ctx, submitOrders...) + if err2 != nil { + return err + } + _ = createdOrders } return nil