Merge pull request #443 from austin362667/refactor/futures-account

binance: add futures broker
This commit is contained in:
Yo-An Lin 2022-01-26 14:11:48 +08:00 committed by GitHub
commit d79cce30e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -807,7 +807,7 @@ func (e *Exchange) submitFuturesOrder(ctx context.Context, order types.SubmitOrd
Type(orderType).
Side(futures.SideType(order.Side))
clientOrderID := newSpotClientOrderID(order.ClientOrderID)
clientOrderID := newFuturesClientOrderID(order.ClientOrderID)
if len(clientOrderID) > 0 {
req.NewClientOrderID(clientOrderID)
}
@ -906,6 +906,36 @@ func newSpotClientOrderID(originalID string) (clientOrderID string) {
return clientOrderID
}
// BBGO is a futures broker on Binance
const futuresBrokerID = "gBhMvywy"
func newFuturesClientOrderID(originalID string) (clientOrderID string) {
if originalID == types.NoClientOrderID {
return ""
}
prefix := "x-" + futuresBrokerID
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 (e *Exchange) submitSpotOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
orderType, err := toLocalOrderType(order.Type)
if err != nil {