mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
binance: add TradeFutures
This commit is contained in:
parent
8130ef78c1
commit
32c2f128f5
|
@ -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"`
|
||||
|
|
|
@ -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.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user