diff --git a/pkg/exchange/binance/parse.go b/pkg/exchange/binance/parse.go index e18020a40..76bf82c28 100644 --- a/pkg/exchange/binance/parse.go +++ b/pkg/exchange/binance/parse.go @@ -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"` diff --git a/pkg/exchange/binance/stream.go b/pkg/exchange/binance/stream.go index dd774fbfa..17769ae5a 100644 --- a/pkg/exchange/binance/stream.go +++ b/pkg/exchange/binance/stream.go @@ -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.") }