info.bitrich.xchangestream.gemini.GeminiStreamingExchange Maven / Gradle / Ivy
The newest version!
package info.bitrich.xchangestream.gemini;
import info.bitrich.xchangestream.core.ProductSubscription;
import info.bitrich.xchangestream.core.StreamingExchange;
import info.bitrich.xchangestream.core.StreamingMarketDataService;
import info.bitrich.xchangestream.service.netty.ConnectionStateModel.State;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Observable;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import org.knowm.xchange.gemini.v1.GeminiExchange;
/** Adapted from V1 by Max Gao on 01-09-2021 */
public class GeminiStreamingExchange extends GeminiExchange implements StreamingExchange {
private static final String API_V2_URI = "wss://api.gemini.com/v2/marketdata/";
private GeminiStreamingService streamingService;
private GeminiStreamingMarketDataService streamingMarketDataService;
public GeminiStreamingExchange() {}
@Override
protected void initServices() {
super.initServices();
}
@Override
public Completable connect(ProductSubscription... args) {
if (args == null || args.length == 0)
throw new UnsupportedOperationException("The ProductSubscription must be defined!");
ExchangeSpecification exchangeSpec = getExchangeSpecification();
this.streamingService = new GeminiStreamingService(API_V2_URI);
applyStreamingSpecification(exchangeSpec, this.streamingService);
this.streamingMarketDataService = new GeminiStreamingMarketDataService(streamingService);
streamingService.subscribeMultipleCurrencyPairs(args);
return streamingService.connect();
}
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
ExchangeSpecification spec = super.getDefaultExchangeSpecification();
spec.setShouldLoadRemoteMetaData(false);
return spec;
}
@Override
public Completable disconnect() {
GeminiStreamingService service = streamingService;
streamingService = null;
streamingMarketDataService = null;
return service.disconnect();
}
@Override
public StreamingMarketDataService getStreamingMarketDataService() {
return streamingMarketDataService;
}
@Override
public Observable connectionStateObservable() {
return streamingService.subscribeConnectionState();
}
@Override
public boolean isAlive() {
return streamingService != null && streamingService.isSocketOpen();
}
@Override
public void useCompressedMessages(boolean compressedMessages) {
throw new NotYetImplementedForExchangeException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy