xchange-stream icon indicating copy to clipboard operation
xchange-stream copied to clipboard

Gemini doesn't shut down properly

Open bryantharris opened this issue 6 years ago • 0 comments

I think this has been a common theme with gdax as well, but I put together a sample program to demonstrate the issue.

Steps To Reproduce:

  1. Build the provided code using Java 1.8 or higher
  2. Run the application (no arguments required)

Expected Results

  1. The program connects to the Gemini web socket and the main thread blocks for 20 seconds.
  2. Once the 20 seconds is completed the program should properly shutdown the web socket and exit

Actual Results

  1. Although the clean up/disconnect code is called, the program hangs and does not exit

``

import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.currency.CurrencyPair;

import info.bitrich.xchangestream.core.StreamingExchange;
import info.bitrich.xchangestream.core.StreamingExchangeFactory;
import info.bitrich.xchangestream.gemini.GeminiStreamingExchange;
import io.reactivex.disposables.Disposable;

public class Application {
     public static void main(String[] args) {
		ExchangeSpecification exSpec = new GeminiStreamingExchange().getDefaultExchangeSpecification();
		StreamingExchange ex = StreamingExchangeFactory.INSTANCE.createExchange( exSpec );
		ex.connect().blockingAwait();

		Disposable sub = ex.getStreamingMarketDataService()
							.getOrderBook(CurrencyPair.ETH_USD)
							.subscribe(orderBook -> {
                                System.out.println(orderBook);
							}, throwable -> {
								System.err.println("Error in subscribing to order book " + throwable);
                    });
		
		synchronized (Application.class) {
			try { Application.class.wait(20000); } catch (Exception e) {}
		}
		
		System.out.println("Starting Shutdown");
		
    	sub.dispose();
    	ex.disconnect().subscribe(() -> System.out.println("Disconnected from the Exchange {}"));
    }
}

bryantharris avatar Mar 16 '18 18:03 bryantharris