@dozd
Please consider the following proposal for subscribing process:
Now the subscription of the product(s)/symbol(s)/pair(s) is related with the methods like getOrderBook, getTrade and getTicker.
But for example the Gdax exchange allows only one subscription per multiple products. Another example is the Gemini exchange, where each product has own wss connection. In The bitfinex scenario, the channel request contains name of the product, but the server sends its channel id in the response and then the server sends the market update/snapshot events with the channel id. In summary, each implementation has "tricky" code how to cover all of these cases.
In my opinion, it should be more standardize way how to subscribe the channles/product(s) without the "tricky" code. Therefore I propose the subscriptions of all product(s) and kind of market events have to be defined before connection to the exchange. For example:
In the interface StreamingExchange extends the method connect with one subscription argument:
public interface StreamingExchange<T extends StreamingSubscription> ... {
...
Completable connect(T streamingSubscription);
...
}
Each exchange has to be implemented the own class (ExchangeName)StreamingSubscription (that implements interface StreamingSubscription). Consider the example with Gdax and Gemini cases:
class GdaxStreamingSubscription implements StreamingSubscription {
private GdaxStreamingSubscription() {...}
public static createGdaxStreamingSubscription(GdaxProductSubscription[] subscriptions) {}
}
where the class GdaxProductSubscription can look like:
GdaxProductSubscription {
public GdaxProductSubscription(CurrencyPair pair, boolean orderbook, boolean ticker, boolean trade) {...}
}
and for Gemini case the StreamingSubscription class will be different:
class GeminiStreamingSubscription implements StreamingSubscription {
private GeminiStreamingSubscription() {...}
...
public static createGeminiStreamingSubscription(CurrencyPair[] pairs) {}
...
}
The GdaxExchange will look like:
public class GDAXStreamingExchange extends GDAXExchange implements StreamingExchange<GdaxStreamingSubscription> {
...
public Completable connect(GdaxStreamingSubscription streamingSubscription) {...}
...
}
It hides all needs for subscribing the market events for different exchanges, standardize the subscribing process, and the StreamingMarketDataService interface doesn't change.
What do you think guys?