mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +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
|
}, 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 {
|
type AccountUpdate struct {
|
||||||
EventReasonType string `json:"m"`
|
EventReasonType string `json:"m"`
|
||||||
Balances []*futures.Balance `json:"B,omitempty"`
|
Balances []*futures.Balance `json:"B,omitempty"`
|
||||||
|
|
|
@ -247,33 +247,21 @@ func (s *Stream) handleOrderTradeUpdateEvent(e *OrderTradeUpdateEvent) {
|
||||||
case "NEW", "CANCELED", "EXPIRED":
|
case "NEW", "CANCELED", "EXPIRED":
|
||||||
order, err := e.OrderFutures()
|
order, err := e.OrderFutures()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("order convert error")
|
log.WithError(err).Error("futures order convert error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.EmitOrderUpdate(*order)
|
s.EmitOrderUpdate(*order)
|
||||||
|
|
||||||
case "TRADE":
|
case "TRADE":
|
||||||
// TODO
|
trade, err := e.TradeFutures()
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("futures trade convert error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// trade, err := e.Trade()
|
s.EmitTradeUpdate(*trade)
|
||||||
// if err != nil {
|
|
||||||
// log.WithError(err).Error("trade convert error")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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":
|
case "CALCULATED - Liquidation Execution":
|
||||||
log.Infof("CALCULATED - Liquidation Execution not support yet.")
|
log.Infof("CALCULATED - Liquidation Execution not support yet.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user