binance: add TradeFutures

This commit is contained in:
austin362667 2022-01-13 19:28:12 +08:00
parent 8130ef78c1
commit 32c2f128f5
2 changed files with 30 additions and 19 deletions

View File

@ -719,6 +719,29 @@ func (e *OrderTradeUpdateEvent) OrderFutures() (*types.Order, error) {
}, nil
}
func (e *OrderTradeUpdateEvent) TradeFutures() (*types.Trade, error) {
if e.OrderTrade.CurrentExecutionType != "TRADE" {
return nil, errors.New("execution report is not a futures trade")
}
tt := time.Unix(0, e.OrderTrade.OrderTradeTime*int64(time.Millisecond))
return &types.Trade{
ID: uint64(e.OrderTrade.TradeId),
Exchange: types.ExchangeBinance,
Symbol: e.OrderTrade.Symbol,
OrderID: uint64(e.OrderTrade.OrderId),
Side: toGlobalSideType(binance.SideType(e.OrderTrade.Side)),
Price: util.MustParseFloat(e.OrderTrade.LastFilledPrice),
Quantity: util.MustParseFloat(e.OrderTrade.OrderLastFilledQuantity),
QuoteQuantity: util.MustParseFloat(e.OrderTrade.OrderFilledAccumulatedQuantity),
IsBuyer: e.OrderTrade.Side == "BUY",
IsMaker: e.OrderTrade.IsMaker,
Time: types.Time(tt),
Fee: util.MustParseFloat(e.OrderTrade.CommissionAmount),
FeeCurrency: e.OrderTrade.CommissionAsset,
}, nil
}
type AccountUpdate struct {
EventReasonType string `json:"m"`
Balances []*futures.Balance `json:"B,omitempty"`

View File

@ -247,33 +247,21 @@ func (s *Stream) handleOrderTradeUpdateEvent(e *OrderTradeUpdateEvent) {
case "NEW", "CANCELED", "EXPIRED":
order, err := e.OrderFutures()
if err != nil {
log.WithError(err).Error("order convert error")
log.WithError(err).Error("futures order convert error")
return
}
s.EmitOrderUpdate(*order)
case "TRADE":
// TODO
trade, err := e.TradeFutures()
if err != nil {
log.WithError(err).Error("futures trade convert error")
return
}
// trade, err := e.Trade()
// if err != nil {
// log.WithError(err).Error("trade convert error")
// return
// }
s.EmitTradeUpdate(*trade)
// stream.EmitTradeUpdate(*trade)
// order, err := e.OrderFutures()
// if err != nil {
// log.WithError(err).Error("order convert error")
// return
// }
// Update Order with FILLED event
// if order.Status == types.OrderStatusFilled {
// stream.EmitOrderUpdate(*order)
// }
case "CALCULATED - Liquidation Execution":
log.Infof("CALCULATED - Liquidation Execution not support yet.")
}