-
-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: support binance futures #333
Conversation
[Binance future api] MarkPriceUpdateEvent
[Binance future api] ContinuousKlineEvent
ebdec74
to
7a6499e
Compare
return stream | ||
} | ||
|
||
func NewFuturesStream(client *futures.Client) *Stream { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge this function into NewStream(), like this,
stream := NewStream(e.Client, e.futuresClient)
// the following code locates at binance/exchange.go
stream.MarginSettings = e.MarginSettings
stream.FuturesSettings = e.FuturesSettings
@@ -270,6 +519,20 @@ func toGlobalSideType(side binance.SideType) types.SideType { | |||
} | |||
} | |||
|
|||
func toGlobalFuturesSideType(side futures.SideType) types.SideType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -292,6 +555,27 @@ func toGlobalOrderType(orderType binance.OrderType) types.OrderType { | |||
} | |||
} | |||
|
|||
func toGlobalFuturesOrderType(orderType futures.OrderType) types.OrderType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -313,10 +597,31 @@ func toGlobalOrderStatus(orderStatus binance.OrderStatusType) types.OrderStatus | |||
return types.OrderStatus(orderStatus) | |||
} | |||
|
|||
func toGlobalFuturesOrderStatus(orderStatus futures.OrderStatusType) types.OrderStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
// ConvertTrades converts the binance v3 trade into the global trade type | ||
func ConvertTrades(remoteTrades []*binance.TradeV3) (trades []types.Trade, err error) { | ||
for _, t := range remoteTrades { | ||
trade, err := ToGlobalTrade(*t, false) | ||
trade, err := toGlobalTrade(*t, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -163,6 +299,28 @@ func toLocalOrderType(orderType types.OrderType) (binance.OrderType, error) { | |||
return "", fmt.Errorf("can not convert to local order, order type %s not supported", orderType) | |||
} | |||
|
|||
func toLocalFuturesOrderType(orderType types.OrderType) (futures.OrderType, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -176,6 +334,19 @@ func toGlobalOrders(binanceOrders []*binance.Order) (orders []types.Order, err e | |||
return orders, err | |||
} | |||
|
|||
func toGlobalFuturesOrders(futuresOrders []*futures.Order) (orders []types.Order, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -199,11 +370,36 @@ func toGlobalOrder(binanceOrder *binance.Order, isMargin bool) (*types.Order, er | |||
}, nil | |||
} | |||
|
|||
func toGlobalFuturesOrder(futuresOrder *futures.Order, isMargin bool) (*types.Order, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
func millisecondTime(t int64) time.Time { | ||
return time.Unix(0, t*int64(time.Millisecond)) | ||
} | ||
|
||
func ToGlobalTrade(t binance.TradeV3, isMargin bool) (*types.Trade, error) { | ||
func toGlobalTrade(t binance.TradeV3, isMargin bool) (*types.Trade, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Client *binance.Client | ||
key, secret string | ||
Client *binance.Client // Spot & Margin | ||
futuresClient *futures.Client // USDT-M Futures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
||
Client: client, | ||
var futuresClient = binance.NewFuturesClient(key, secret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
stream := NewStream(e.Client) | ||
stream.MarginSettings = e.MarginSettings | ||
return stream | ||
} else if e.IsFutures { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored!
@@ -582,6 +874,95 @@ func (e *Exchange) submitMarginOrder(ctx context.Context, order types.SubmitOrde | |||
return createdOrder, err | |||
} | |||
|
|||
func (e *Exchange) submitFuturesOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
log.WithError(err).Errorf("order rate limiter wait error") | ||
} | ||
|
||
var createdOrder *types.Order | ||
if e.IsMargin { | ||
createdOrder, err = e.submitMarginOrder(ctx, order) | ||
} else if e.IsFutures { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
||
stream.OnAccountUpdateEvent(func(e *AccountUpdateEvent) { | ||
// TODO | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP
} | ||
|
||
stream.EmitPositionSnapshot(snapshot) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not modify position leverage.
update account config leverage only.
No description provided.