mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Binance: Add order side to trade data (#1782)
* Add the initiating side to Binance trades * Update TradeStream type, move trades declaraction * Make side declaration in Binance trades consistent
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user