make max client order id factory public

This commit is contained in:
c9s 2021-05-18 09:10:43 +08:00
parent e23932f99c
commit c4ccd8094f
2 changed files with 35 additions and 27 deletions

View File

@ -0,0 +1,34 @@
package max
import "github.com/google/uuid"
// BBGO is a broker on MAX
const spotBrokerID = "bbgo"
func NewClientOrderID(originalID string, tags ...string) (clientOrderID string) {
prefix := "x-" + spotBrokerID + "-"
for _, tag := range tags {
prefix += tag + "-"
}
prefixLen := len(prefix)
if originalID != "" {
// try to keep the whole original client order ID if user specifies it.
if prefixLen+len(originalID) > 32 {
return originalID
}
clientOrderID = prefix + originalID
return clientOrderID
}
clientOrderID = uuid.New().String()
clientOrderID = prefix + clientOrderID
if len(clientOrderID) > 32 {
return clientOrderID[0:32]
}
return clientOrderID
}

View File

@ -9,7 +9,6 @@ import (
"strconv"
"time"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
@ -309,7 +308,7 @@ func toMaxSubmitOrder(o types.SubmitOrder) (*maxapi.Order, error) {
return nil, err
}
clientOrderID := newSpotClientOrderID(o.ClientOrderID)
clientOrderID := NewClientOrderID(o.ClientOrderID)
volumeInString := o.QuantityString
if len(volumeInString) == 0 {
@ -868,28 +867,3 @@ func (e *Exchange) QueryAveragePrice(ctx context.Context, symbol string) (float6
return (util.MustParseFloat(ticker.Sell) + util.MustParseFloat(ticker.Buy)) / 2, nil
}
// BBGO is a broker on MAX
const spotBrokerID = "bbgo-"
func newSpotClientOrderID(originalID string) (clientOrderID string) {
prefix := "x-" + spotBrokerID
prefixLen := len(prefix)
if originalID != "" {
// try to keep the whole original client order ID if user specifies it.
if prefixLen+len(originalID) > 32 {
return originalID
}
clientOrderID = prefix + originalID
return clientOrderID
}
clientOrderID = uuid.New().String()
clientOrderID = prefix + clientOrderID
if len(clientOrderID) > 32 {
return clientOrderID[0:32]
}
return clientOrderID
}