diff --git a/exchanges/binance/binance_types.go b/exchanges/binance/binance_types.go index a70ad4c5d1b..215d7ece9d8 100644 --- a/exchanges/binance/binance_types.go +++ b/exchanges/binance/binance_types.go @@ -198,7 +198,7 @@ type TradeStream struct { BuyerOrderID int64 `json:"b"` SellerOrderID int64 `json:"a"` TimeStamp time.Time `json:"T"` - Maker bool `json:"m"` + IsBuyerMaker bool `json:"m"` BestMatchPrice bool `json:"M"` } @@ -288,7 +288,7 @@ type AggregatedTrade struct { FirstTradeID int64 `json:"f"` LastTradeID int64 `json:"l"` TimeStamp time.Time `json:"T"` - Maker bool `json:"m"` + IsBuyerMaker bool `json:"m"` BestMatchPrice bool `json:"M"` } diff --git a/exchanges/binance/binance_websocket.go b/exchanges/binance/binance_websocket.go index 91b68a11ded..89b00ee4a20 100644 --- a/exchanges/binance/binance_websocket.go +++ b/exchanges/binance/binance_websocket.go @@ -337,16 +337,21 @@ func (b *Binance) wsHandleData(respRaw []byte) error { b.Name, err) } - return b.Websocket.Trade.Update(saveTradeData, - trade.Data{ - CurrencyPair: pair, - Timestamp: t.TimeStamp, - Price: t.Price.Float64(), - Amount: t.Quantity.Float64(), - Exchange: b.Name, - AssetType: asset.Spot, - TID: strconv.FormatInt(t.TradeID, 10), - }) + td := trade.Data{ + CurrencyPair: pair, + Timestamp: t.TimeStamp, + Price: t.Price.Float64(), + Amount: t.Quantity.Float64(), + Exchange: b.Name, + AssetType: asset.Spot, + TID: strconv.FormatInt(t.TradeID, 10)} + + if t.IsBuyerMaker { // Seller is Taker + td.Side = order.Sell + } else { // Buyer is Taker + td.Side = order.Buy + } + return b.Websocket.Trade.Update(saveTradeData, td) case "ticker": var t TickerStream err = json.Unmarshal(jsonData, &t) diff --git a/exchanges/binance/binance_wrapper.go b/exchanges/binance/binance_wrapper.go index 475f274814d..7c17c44dcab 100644 --- a/exchanges/binance/binance_wrapper.go +++ b/exchanges/binance/binance_wrapper.go @@ -783,7 +783,7 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. } for i := range tradeData { - resp = append(resp, trade.Data{ + td := trade.Data{ TID: strconv.FormatInt(tradeData[i].ID, 10), Exchange: b.Name, CurrencyPair: p, @@ -791,7 +791,13 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. Price: tradeData[i].Price, Amount: tradeData[i].Quantity, Timestamp: tradeData[i].Time, - }) + } + if tradeData[i].IsBuyerMaker { // Seller is Taker + td.Side = order.Sell + } else { // Buyer is Taker + td.Side = order.Buy + } + resp = append(resp, td) } case asset.USDTMarginedFutures: tradeData, err := b.URecentTrades(ctx, pFmt, "", limit) @@ -800,7 +806,7 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. } for i := range tradeData { - resp = append(resp, trade.Data{ + td := trade.Data{ TID: strconv.FormatInt(tradeData[i].ID, 10), Exchange: b.Name, CurrencyPair: p, @@ -808,7 +814,13 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. Price: tradeData[i].Price, Amount: tradeData[i].Qty, Timestamp: tradeData[i].Time.Time(), - }) + } + if tradeData[i].IsBuyerMaker { // Seller is Taker + td.Side = order.Sell + } else { // Buyer is Taker + td.Side = order.Buy + } + resp = append(resp, td) } case asset.CoinMarginedFutures: tradeData, err := b.GetFuturesPublicTrades(ctx, pFmt, limit) @@ -817,7 +829,7 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. } for i := range tradeData { - resp = append(resp, trade.Data{ + td := trade.Data{ TID: strconv.FormatInt(tradeData[i].ID, 10), Exchange: b.Name, CurrencyPair: p, @@ -825,7 +837,13 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset. Price: tradeData[i].Price, Amount: tradeData[i].Qty, Timestamp: tradeData[i].Time.Time(), - }) + } + if tradeData[i].IsBuyerMaker { // Seller is Taker + td.Side = order.Sell + } else { // Buyer is Taker + td.Side = order.Buy + } + resp = append(resp, td) } } @@ -864,7 +882,7 @@ func (b *Binance) GetHistoricTrades(ctx context.Context, p currency.Pair, a asse } result := make([]trade.Data, len(trades)) for i := range trades { - result[i] = trade.Data{ + td := trade.Data{ CurrencyPair: p, TID: strconv.FormatInt(trades[i].ATradeID, 10), Amount: trades[i].Quantity, @@ -872,8 +890,13 @@ func (b *Binance) GetHistoricTrades(ctx context.Context, p currency.Pair, a asse Price: trades[i].Price, Timestamp: trades[i].TimeStamp, AssetType: a, - Side: order.AnySide, } + if trades[i].IsBuyerMaker { // Seller is Taker + td.Side = order.Sell + } else { // Buyer is Taker + td.Side = order.Buy + } + result[i] = td } return result, nil }