mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
make max client order id factory public
This commit is contained in:
parent
e23932f99c
commit
c4ccd8094f
34
pkg/exchange/max/client_order_id.go
Normal file
34
pkg/exchange/max/client_order_id.go
Normal 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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user