Skip to content

Commit

Permalink
Make side declaration in Binance trades consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Beadko committed Jan 22, 2025
1 parent 90111db commit 39e4eec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion exchanges/binance/binance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
1 change: 0 additions & 1 deletion exchanges/binance/binance_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
Amount: t.Quantity.Float64(),
Exchange: b.Name,
AssetType: asset.Spot,
Side: order.Sell,
TID: strconv.FormatInt(t.TradeID, 10)}

if t.IsBuyerMaker { // Seller is Taker
Expand Down
62 changes: 31 additions & 31 deletions exchanges/binance/binance_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,21 +783,21 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.
}

for i := range tradeData {
// maker placed buy order, so taker market sell
side := order.Buy
if tradeData[i].IsBuyerMaker {
side = order.Sell
}
resp = append(resp, trade.Data{
td := trade.Data{
TID: strconv.FormatInt(tradeData[i].ID, 10),
Exchange: b.Name,
CurrencyPair: p,
AssetType: a,
Price: tradeData[i].Price,
Amount: tradeData[i].Quantity,
Side: side,
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)
Expand All @@ -806,21 +806,21 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.
}

for i := range tradeData {
// maker placed buy order, so taker market sell
side := order.Buy
if tradeData[i].IsBuyerMaker {
side = order.Sell
}
resp = append(resp, trade.Data{
td := trade.Data{
TID: strconv.FormatInt(tradeData[i].ID, 10),
Exchange: b.Name,
CurrencyPair: p,
AssetType: a,
Price: tradeData[i].Price,
Amount: tradeData[i].Qty,
Side: side,
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)
Expand All @@ -829,21 +829,21 @@ func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.
}

for i := range tradeData {
// maker placed buy order, so taker market sell
side := order.Buy
if tradeData[i].IsBuyerMaker {
side = order.Sell
}
resp = append(resp, trade.Data{
td := trade.Data{
TID: strconv.FormatInt(tradeData[i].ID, 10),
Exchange: b.Name,
CurrencyPair: p,
AssetType: a,
Price: tradeData[i].Price,
Amount: tradeData[i].Qty,
Side: side,
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)
}
}

Expand Down Expand Up @@ -882,21 +882,21 @@ func (b *Binance) GetHistoricTrades(ctx context.Context, p currency.Pair, a asse
}
result := make([]trade.Data, len(trades))
for i := range trades {
// maker placed buy order, so taker market sell
side := order.Buy
if trades[i].Maker {
side = order.Sell
}
result[i] = trade.Data{
td := trade.Data{
CurrencyPair: p,
TID: strconv.FormatInt(trades[i].ATradeID, 10),
Amount: trades[i].Quantity,
Exchange: b.Name,
Price: trades[i].Price,
Timestamp: trades[i].TimeStamp,
AssetType: a,
Side: side,
}
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
}
Expand Down

0 comments on commit 39e4eec

Please sign in to comment.