UnsupportedOperationException: The currency pair BTC/EUR is not subscribed for trades
actiondav opened this issue · 1 comments
Hello, I have an error when trying to subscribe a CurrencyPair trades. Could you help me please ?
**
java.lang.UnsupportedOperationException: The currency pair BTC/EUR is not subscribed for trades
**
package com.bot.cypro.api;
import java.io.IOException;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.coinbasepro.CoinbaseProExchange;
import org.knowm.xchange.coinbasepro.dto.CoinbaseProException;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProAccount;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder;
import org.knowm.xchange.coinbasepro.service.CoinbaseProAccountService;
import org.knowm.xchange.coinbasepro.service.CoinbaseProBaseService;
import org.knowm.xchange.coinbasepro.service.CoinbaseProMarketDataService;
import org.knowm.xchange.coinbasepro.service.CoinbaseProTradeService;
import org.knowm.xchange.currency.CurrencyPair;
import com.bot.cypro.Config;
import info.bitrich.xchangestream.coinbasepro.CoinbaseProStreamingExchange;
import info.bitrich.xchangestream.core.ProductSubscription;
import info.bitrich.xchangestream.core.ProductSubscription.ProductSubscriptionBuilder;
import info.bitrich.xchangestream.core.StreamingMarketDataService;
import io.reactivex.disposables.Disposable;
public class CoinbaseAccess {
private CoinbaseProStreamingExchange coinbase;
private CoinbaseProAccountService accountService;
private CoinbaseProMarketDataService marketDataService;
private CoinbaseProTradeService tradeService;
private CoinbaseProBaseService baseService;
private StreamingMarketDataService streamingService;
public StreamingMarketDataService getStreamingService() {
return streamingService;
}
public CoinbaseAccess() {
System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
ExchangeSpecification exSpec = new CoinbaseProExchange().getDefaultExchangeSpecification();
if (Config.SANDBOX) {
exSpec.setSslUri(Config.SANDBOX_URL);
exSpec.setExchangeSpecificParametersItem("passphrase", Config.SANDBOX_PASSPHRASE);
exSpec.setApiKey(Config.SANDBOX_API_KEY);
exSpec.setSecretKey(Config.SANDBOX_SECRET_KEY);
} else {
exSpec.setSslUri(Config.URL);
exSpec.setExchangeSpecificParametersItem("passphrase", Config.PASSPHRASE);
exSpec.setApiKey(Config.API_KEY);
exSpec.setSecretKey(Config.SECRET_KEY);
}
exSpec.setExchangeSpecificParametersItem("Use_Sandbox", Config.SANDBOX);
coinbase = new CoinbaseProStreamingExchange();
coinbase.applySpecification(exSpec);
// Services
accountService = new CoinbaseProAccountService(coinbase);
marketDataService = new CoinbaseProMarketDataService(coinbase);
tradeService = new CoinbaseProTradeService(coinbase);
CoinbaseProStreamingExchange streamingExchange = new CoinbaseProStreamingExchange();
streamingExchange.applySpecification(exSpec);
streamingService = streamingExchange.getStreamingMarketDataService();
try {
ProductSubscriptionBuilder ps = ProductSubscription.create();
ProductSubscription sus = ps.build();
coinbase.connect(sus).blockingAwait();
Disposable subscription = coinbase.getStreamingMarketDataService().getTrades(CurrencyPair.BTC_EUR)
.subscribe(trade -> {
System.out.println(trade);
}, throwable -> {
throwable.printStackTrace();
});
// subscription.dispose();
// exchange.disconnect();
// Disconnect from exchange (non-blocking)
} catch (Exception e) {
e.printStackTrace();
}
}
public CoinbaseProOrder[] getMyOrders() throws IOException {
return tradeService.getOrders("all");
}
public CoinbaseProOrder[] getMyOpenOrders() throws IOException {
return tradeService.getOrders("open");
}
public CoinbaseProOrder[] getMyDoneOrders() throws IOException {
return tradeService.getOrders("done");
}
public CoinbaseProAccount[] getAccounts() throws CoinbaseProException, IOException {
return accountService.getCoinbaseProAccountInfo();
}
public CoinbaseProExchange getCoinbase() {
return coinbase;
}
public CoinbaseProAccountService getAccountService() {
return accountService;
}
public CoinbaseProMarketDataService getMarketDataService() {
return marketDataService;
}
public CoinbaseProTradeService getTradeService() {
return tradeService;
}
public CoinbaseProBaseService getBaseService() {
return baseService;
}
}
java.lang.UnsupportedOperationException: The currency pair BTC/EUR is not subscribed for trades at info.bitrich.xchangestream.coinbasepro.CoinbaseProStreamingMarketDataService.getTrades(CoinbaseProStreamingMarketDataService.java:139) at com.bot.cypro.api.CoinbaseAccess.<init>(CoinbaseAccess.java:76) at com.bot.cypro.Config.<clinit>(Config.java:11) at com.bot.cypro.refresh.AccountsRefresher.<init>(AccountsRefresher.java:20) at com.bot.cypro.gui.MainController.initialize(MainController.java:41) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at com.bot.cypro.Launcher.start(Launcher.java:23) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) at java.lang.Thread.run(Thread.java:748)
Sorry, closed. Added this line and it works 👍
ps.addAll(CurrencyPair.BTC_EUR);