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