Skip to content

Commit

Permalink
Bitfinex: Send individual WS trades down the DataHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jan 11, 2025
1 parent 82eb2c0 commit e28ee04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
6 changes: 2 additions & 4 deletions engine/websocketroutine_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data int
}
m.syncer.PrintTickerSummary(&d[x], "websocket", err)
}
case order.Detail,
ticker.Price,
orderbook.Depth:
case order.Detail, ticker.Price, orderbook.Depth:
return errUseAPointer
case stream.KlineData:
if m.verbose {
Expand Down Expand Up @@ -347,7 +345,7 @@ func (m *WebsocketRoutineManager) websocketDataHandler(exchName string, data int
m.printAccountHoldingsChangeSummary(d[x])
}
}
case []trade.Data:
case []trade.Data, trade.Data:
if m.verbose {
log.Infof(log.Trade, "%+v", d)
}
Expand Down
6 changes: 3 additions & 3 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,13 +1393,13 @@ func TestWSAllTrades(t *testing.T) {
require.Len(t, b.Websocket.DataHandler, len(expJSON), "Must see correct number of trades")
for resp := range b.Websocket.DataHandler {
switch v := resp.(type) {
case *trade.Data:
case trade.Data:
i := 6 - len(b.Websocket.DataHandler)
exp := &trade.Data{
exp := trade.Data{
Exchange: b.Name,
CurrencyPair: btcusdPair,
}
require.NoErrorf(t, json.Unmarshal([]byte(expJSON[i]), exp), "Must not error unmarshalling json %d: %s", i, expJSON[i])
require.NoErrorf(t, json.Unmarshal([]byte(expJSON[i]), &exp), "Must not error unmarshalling json %d: %s", i, expJSON[i])
require.Equalf(t, exp, v, "Trade [%d] should be correct", i)
case error:
t.Error(v)
Expand Down
9 changes: 4 additions & 5 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func (b *Bitfinex) handleWSAllTrades(s *subscription.Subscription, respRaw []byt
return fmt.Errorf("%w `tradesUpdate[1]`: %w `%s`", errParsingWSField, jsonparser.UnknownValueTypeError, valueType)
}
trades := make([]trade.Data, len(wsTrades))
for i, w := range wsTrades {
for _, w := range wsTrades {
t := trade.Data{
Exchange: b.Name,
AssetType: s.Asset,
Expand All @@ -979,10 +979,9 @@ func (b *Bitfinex) handleWSAllTrades(s *subscription.Subscription, respRaw []byt
t.Side = order.Sell
t.Amount = math.Abs(t.Amount)
}
trades[i] = t
}
if feedEnabled {
b.Websocket.DataHandler <- trades
if feedEnabled {
b.Websocket.DataHandler <- t
}
}
if b.IsSaveTradeDataEnabled() {
err = trade.AddTradesToBuffer(b.GetName(), trades...)
Expand Down

0 comments on commit e28ee04

Please sign in to comment.