mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-11 09:33:50 +00:00
35 lines
693 B
Go
35 lines
693 B
Go
|
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
|
||
|
}
|