From e282a8a917e3b85c6e5877ce27b2c4161c6da655 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 17 Dec 2020 17:54:48 +0800 Subject: [PATCH] improve order submit loop --- pkg/strategy/grid/strategy.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/strategy/grid/strategy.go b/pkg/strategy/grid/strategy.go index fd57bd777..1e565332a 100644 --- a/pkg/strategy/grid/strategy.go +++ b/pkg/strategy/grid/strategy.go @@ -33,7 +33,6 @@ type Strategy struct { // This field will be injected automatically since it's a single exchange strategy. bbgo.OrderExecutor - orderStore *bbgo.OrderStore // Market stores the configuration of the market, for example, VolumePrecision, PricePrecision, MinLotSize... etc @@ -83,27 +82,30 @@ func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bb priceRange := s.UpperPrice - s.LowerPrice gridSize := priceRange.Div(fixedpoint.NewFromInt(s.GridNum)) - log.Infof("current price: %f", currentPrice) - var orders []types.SubmitOrder - for price := s.LowerPrice; price <= s.UpperPrice; price += gridSize { - var side types.SideType - if price > currentPriceF { - side = types.SideTypeSell - } else { - side = types.SideTypeBuy - } - + for price := currentPriceF + gridSize; price <= s.UpperPrice; price += gridSize { order := types.SubmitOrder{ Symbol: s.Symbol, - Side: side, + Side: types.SideTypeSell, + Type: types.OrderTypeLimit, + Market: s.Market, + Quantity: s.Quantity, + Price: price.Float64(), + TimeInForce: "GTC", + } + orders = append(orders, order) + } + + for price := currentPriceF - gridSize; price <= s.LowerPrice; price -= gridSize { + order := types.SubmitOrder{ + Symbol: s.Symbol, + Side: types.SideTypeBuy, Type: types.OrderTypeLimit, Market: s.Market, Quantity: s.Quantity, Price: price.Float64(), TimeInForce: "GTC", } - log.Infof("submitting order: %s", order.String()) orders = append(orders, order) } @@ -166,7 +168,6 @@ func (s *Strategy) submitReverseOrder(order types.Order) { s.activeOrders.Add(createdOrders...) } - func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) }