FIX: [grid2] specify client order id explicitly

This commit is contained in:
gx578007 2023-03-10 15:47:42 +08:00
parent 31e299baf2
commit 16b30960cc

View File

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/cenkalti/backoff/v4" "github.com/cenkalti/backoff/v4"
"github.com/google/uuid"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -485,15 +486,16 @@ func (s *Strategy) processFilledOrder(o types.Order) {
} }
orderForm := types.SubmitOrder{ orderForm := types.SubmitOrder{
Symbol: s.Symbol, Symbol: s.Symbol,
Market: s.Market, Market: s.Market,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Price: newPrice, Price: newPrice,
Side: newSide, Side: newSide,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
Quantity: newQuantity, Quantity: newQuantity,
Tag: orderTag, Tag: orderTag,
GroupID: s.OrderGroupID, GroupID: s.OrderGroupID,
ClientOrderID: uuid.New().String(),
} }
s.logger.Infof("SUBMIT GRID REVERSE ORDER: %s", orderForm.String()) s.logger.Infof("SUBMIT GRID REVERSE ORDER: %s", orderForm.String())
@ -1242,15 +1244,16 @@ func (s *Strategy) generateGridOrders(totalQuote, totalBase, lastPrice fixedpoin
if usedBase.Add(quantity).Compare(totalBase) < 0 { if usedBase.Add(quantity).Compare(totalBase) < 0 {
submitOrders = append(submitOrders, types.SubmitOrder{ submitOrders = append(submitOrders, types.SubmitOrder{
Symbol: s.Symbol, Symbol: s.Symbol,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Side: types.SideTypeSell, Side: types.SideTypeSell,
Price: sellPrice, Price: sellPrice,
Quantity: quantity, Quantity: quantity,
Market: s.Market, Market: s.Market,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
Tag: orderTag, Tag: orderTag,
GroupID: s.OrderGroupID, GroupID: s.OrderGroupID,
ClientOrderID: uuid.New().String(),
}) })
usedBase = usedBase.Add(quantity) usedBase = usedBase.Add(quantity)
} else { } else {
@ -1259,15 +1262,16 @@ func (s *Strategy) generateGridOrders(totalQuote, totalBase, lastPrice fixedpoin
nextPin := pins[i-1] nextPin := pins[i-1]
nextPrice := fixedpoint.Value(nextPin) nextPrice := fixedpoint.Value(nextPin)
submitOrders = append(submitOrders, types.SubmitOrder{ submitOrders = append(submitOrders, types.SubmitOrder{
Symbol: s.Symbol, Symbol: s.Symbol,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Price: nextPrice, Price: nextPrice,
Quantity: quantity, Quantity: quantity,
Market: s.Market, Market: s.Market,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
Tag: orderTag, Tag: orderTag,
GroupID: s.OrderGroupID, GroupID: s.OrderGroupID,
ClientOrderID: uuid.New().String(),
}) })
quoteQuantity := quantity.Mul(nextPrice) quoteQuantity := quantity.Mul(nextPrice)
usedQuote = usedQuote.Add(quoteQuantity) usedQuote = usedQuote.Add(quoteQuantity)
@ -1292,15 +1296,16 @@ func (s *Strategy) generateGridOrders(totalQuote, totalBase, lastPrice fixedpoin
} }
submitOrders = append(submitOrders, types.SubmitOrder{ submitOrders = append(submitOrders, types.SubmitOrder{
Symbol: s.Symbol, Symbol: s.Symbol,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Price: price, Price: price,
Quantity: quantity, Quantity: quantity,
Market: s.Market, Market: s.Market,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
Tag: orderTag, Tag: orderTag,
GroupID: s.OrderGroupID, GroupID: s.OrderGroupID,
ClientOrderID: uuid.New().String(),
}) })
usedQuote = usedQuote.Add(quoteQuantity) usedQuote = usedQuote.Add(quoteQuantity)
} }
@ -2140,4 +2145,4 @@ func queryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symb
err = generalBackoff(ctx, op) err = generalBackoff(ctx, op)
return openOrders, err return openOrders, err
} }