Skip to content
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

Closed
wants to merge 279 commits into from

Conversation

austin362667
Copy link
Collaborator

No description provided.

return stream
}

func NewFuturesStream(client *futures.Client) *Stream {
Copy link
Collaborator Author

@austin362667 austin362667 Dec 11, 2021

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 {
Copy link
Collaborator Author

@austin362667 austin362667 Dec 12, 2021

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 {
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

@austin362667 austin362667 Dec 14, 2021

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
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP

}

stream.EmitPositionSnapshot(snapshot)
})
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants