mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
skip client order id when no client order is given
This commit is contained in:
parent
291fdbaf25
commit
5fd0ab4cd3
|
@ -522,19 +522,13 @@ func (e *Exchange) submitMarginOrder(ctx context.Context, order types.SubmitOrde
|
|||
return nil, err
|
||||
}
|
||||
|
||||
clientOrderID := uuid.New().String()
|
||||
if len(order.ClientOrderID) > 0 {
|
||||
clientOrderID = order.ClientOrderID
|
||||
}
|
||||
clientOrderID := newSpotClientOrderID(order.ClientOrderID)
|
||||
|
||||
req := e.Client.NewCreateMarginOrderService().
|
||||
Symbol(order.Symbol).
|
||||
Type(orderType).
|
||||
Side(binance.SideType(order.Side))
|
||||
|
||||
if len(clientOrderID) > 0 {
|
||||
req.NewClientOrderID(clientOrderID)
|
||||
}
|
||||
Side(binance.SideType(order.Side)).
|
||||
NewClientOrderID(clientOrderID)
|
||||
|
||||
// use response result format
|
||||
req.NewOrderRespType(binance.NewOrderRespTypeRESULT)
|
||||
|
@ -618,6 +612,10 @@ func (e *Exchange) submitMarginOrder(ctx context.Context, order types.SubmitOrde
|
|||
const spotBrokerID = "NSUYEBKM"
|
||||
|
||||
func newSpotClientOrderID(originalID string) (clientOrderID string) {
|
||||
if originalID == types.NoClientOrderID {
|
||||
return ""
|
||||
}
|
||||
|
||||
prefix := "x-" + spotBrokerID
|
||||
prefixLen := len(prefix)
|
||||
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
package max
|
||||
|
||||
import "github.com/google/uuid"
|
||||
import (
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// BBGO is a broker on MAX
|
||||
const spotBrokerID = "bbgo"
|
||||
|
||||
func NewClientOrderID(originalID string, tags ...string) (clientOrderID string) {
|
||||
// skip blank client order ID
|
||||
if originalID == types.NoClientOrderID {
|
||||
return ""
|
||||
}
|
||||
|
||||
prefix := "x-" + spotBrokerID + "-"
|
||||
|
||||
for _, tag := range tags {
|
||||
|
|
|
@ -286,7 +286,7 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
var req = e.client.OrderService.NewOrderCancelRequest()
|
||||
if o.OrderID > 0 {
|
||||
req.ID(o.OrderID)
|
||||
} else if len(o.ClientOrderID) > 0 {
|
||||
} else if len(o.ClientOrderID) > 0 && o.ClientOrderID != types.NoClientOrderID {
|
||||
req.ClientOrderID(o.ClientOrderID)
|
||||
} else {
|
||||
return fmt.Errorf("order id or client order id is not defined, order=%+v", o)
|
||||
|
@ -308,14 +308,12 @@ func toMaxSubmitOrder(o types.SubmitOrder) (*maxapi.Order, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
clientOrderID := NewClientOrderID(o.ClientOrderID)
|
||||
|
||||
volumeInString := o.QuantityString
|
||||
if len(volumeInString) == 0 {
|
||||
if o.Market.Symbol != "" {
|
||||
volumeInString = o.Market.FormatQuantity(o.Quantity)
|
||||
} else {
|
||||
volumeInString = strconv.FormatFloat(o.Quantity, 'f', 8, 64)
|
||||
volumeInString = strconv.FormatFloat(o.Quantity, 'f', -1, 64)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,9 +322,16 @@ func toMaxSubmitOrder(o types.SubmitOrder) (*maxapi.Order, error) {
|
|||
Side: toLocalSideType(o.Side),
|
||||
OrderType: orderType,
|
||||
// Price: priceInString,
|
||||
Volume: volumeInString,
|
||||
GroupID: o.GroupID,
|
||||
ClientOID: clientOrderID,
|
||||
Volume: volumeInString,
|
||||
}
|
||||
|
||||
if o.GroupID > 0 {
|
||||
maxOrder.GroupID = o.GroupID
|
||||
}
|
||||
|
||||
clientOrderID := NewClientOrderID(o.ClientOrderID)
|
||||
if len(clientOrderID) > 0 {
|
||||
maxOrder.ClientOID = clientOrderID
|
||||
}
|
||||
|
||||
switch o.Type {
|
||||
|
@ -336,7 +341,7 @@ func toMaxSubmitOrder(o types.SubmitOrder) (*maxapi.Order, error) {
|
|||
if o.Market.Symbol != "" {
|
||||
priceInString = o.Market.FormatPrice(o.Price)
|
||||
} else {
|
||||
priceInString = strconv.FormatFloat(o.Price, 'f', 8, 64)
|
||||
priceInString = strconv.FormatFloat(o.Price, 'f', -1, 64)
|
||||
}
|
||||
}
|
||||
maxOrder.Price = priceInString
|
||||
|
@ -451,12 +456,14 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
|
|||
return createdOrders, err
|
||||
}
|
||||
|
||||
// TODO: replace OrderType string type
|
||||
req := e.client.OrderService.NewCreateOrderRequest().
|
||||
Market(maxOrder.Market).
|
||||
Side(maxOrder.Side).
|
||||
OrderType(string(maxOrder.OrderType)).
|
||||
ClientOrderID(maxOrder.ClientOID)
|
||||
OrderType(string(maxOrder.OrderType))
|
||||
|
||||
if len(maxOrder.ClientOID) > 0 {
|
||||
req.ClientOrderID(maxOrder.ClientOID)
|
||||
}
|
||||
|
||||
if len(maxOrder.Volume) > 0 {
|
||||
req.Volume(maxOrder.Volume)
|
||||
|
|
|
@ -79,6 +79,8 @@ func (t *OrderType) Scan(v interface{}) error {
|
|||
}
|
||||
*/
|
||||
|
||||
const NoClientOrderID = "0"
|
||||
|
||||
type OrderStatus string
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in New Issue
Block a user