add broker id on max

This commit is contained in:
c9s 2021-04-28 19:24:07 +08:00
parent 5d2296eddd
commit e87c2e271f

View File

@ -309,10 +309,7 @@ func toMaxSubmitOrder(o types.SubmitOrder) (*maxapi.Order, error) {
return nil, err
}
clientOrderID := o.ClientOrderID
if len(clientOrderID) == 0 {
clientOrderID = uuid.New().String()
}
clientOrderID := newSpotClientOrderID(o.ClientOrderID)
volumeInString := o.QuantityString
if len(volumeInString) == 0 {
@ -818,3 +815,30 @@ 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
}