mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
Merge pull request #248 from jnlin/fix/ftx-orderid
fix(ftx): use generated order id if not specified
This commit is contained in:
commit
343f184252
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
@ -29,6 +30,32 @@ type Exchange struct {
|
||||||
restEndpoint *url.URL
|
restEndpoint *url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FTX does not have broker ID
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func NewExchange(key, secret string, subAccount string) *Exchange {
|
func NewExchange(key, secret string, subAccount string) *Exchange {
|
||||||
u, err := url.Parse(restEndpoint)
|
u, err := url.Parse(restEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -313,7 +340,7 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
|
||||||
ReduceOnly: false,
|
ReduceOnly: false,
|
||||||
IOC: false,
|
IOC: false,
|
||||||
PostOnly: false,
|
PostOnly: false,
|
||||||
ClientID: so.ClientOrderID,
|
ClientID: newSpotClientOrderID(so.ClientOrderID),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return createdOrders, fmt.Errorf("failed to place order %+v: %w", so, err)
|
return createdOrders, fmt.Errorf("failed to place order %+v: %w", so, err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user