JKorf / Bittrex.Net

A C# .Net wrapper for the Bittrex web API including all features easily accessible and usable
MIT License
141 stars 62 forks source link

v3 Socket Subscribe method can subscribe to multiple streams at once #170

Closed pwnzya closed 4 years ago

pwnzya commented 4 years ago

Another thing I noticed about Bittrex API v3 is that v3 socket's Subscribe method can subscribe to multiple streams at once by specifying multiple streams as its parameter.

From the Bittrex API document: "To subscribe to one or more streams, simply invoke the Subscribe method with an array of streams to which you wish to subscribe. For a list of stream names, refer to the Websocket Streams section. The Subscribe method may be invoked as many times as desired if not all desired streams are known initially."

public async Task<List<SocketResponse>> Subscribe(string[] channels)
{
    return await _hubProxy.Invoke<List<SocketResponse>>("Subscribe", (object)channels);
}

Last time I checked, to subscribe to 3 streams, it was faster to call subscribe method once with 3 streams as its input than to call subscribe method 3 times for each stream.

If I want to subscribe to Candle, OrderBook, and/or Trade stream for, say 10 markets, it might make noticeable difference.

JKorf commented 4 years ago

You're right, it can provide a performance improvement to subscribe multiple channels at once. I've added overloads for the subscribe methods which can take multiple symbols at once and use a single subscribe call, hope that helps you.

Subscribing to multiple different topics (Candle, orderbook, others) at the same time is a little awkward to model, but I think having the multiple symbol overloads should help a lot.

pwnzya commented 4 years ago

Awesome!