mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
Merge pull request #443 from austin362667/refactor/futures-account
binance: add futures broker
This commit is contained in:
commit
d79cce30e3
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user