@Test(expected = ExchangeNetworkException.class) public void testGettingYourOpenOrdersHandlesExchangeNetworkException() throws Exception { final ItBitExchangeAdapter exchangeAdapter = PowerMock.createPartialMock( ItBitExchangeAdapter.class, MOCKED_SEND_AUTHENTICATED_REQUEST_TO_EXCHANGE_METHOD); PowerMock.expectPrivate( exchangeAdapter, MOCKED_SEND_AUTHENTICATED_REQUEST_TO_EXCHANGE_METHOD, eq("GET"), eq(OPEN_ORDERS), anyObject(Map.class)) .andThrow( new ExchangeNetworkException( "I'm afraid. I'm afraid, Dave. Dave, my mind is " + "going. I can feel it. I can feel it. My mind is going. There is no " + "question about it. I can feel it. I can feel it. I can feel it. " + "I'm a... fraid. Good afternoon, gentlemen. I am a HAL 9000 computer. " + "I became operational at the H.A.L. plant in Urbana, Illinois on the 12th " + "of January 1992. My instructor was Mr. Langley, and he taught me to sing " + "a song. If you'd like to hear it I can sing it for you.")); PowerMock.replayAll(); Whitebox.setInternalState(exchangeAdapter, MOCKED_WALLET_ID_FIELD_NAME, WALLET_ID); exchangeAdapter.getYourOpenOrders(MARKET_ID); PowerMock.verifyAll(); }
@Override public List<OpenOrder> getYourOpenOrders(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { if (walletId == null) { getBalanceInfo(); } final Map<String, String> params = createRequestParamMap(); params.put("status", "open"); response = sendAuthenticatedRequestToExchange( "GET", WALLETS_RESOURCE + "/" + walletId + "/orders", params); if (LOG.isDebugEnabled()) { LOG.debug("Open Orders response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitYourOrder[] itBitOpenOrders = gson.fromJson(response.getPayload(), ItBitYourOrder[].class); return adaptItBitOpenOrders(itBitOpenOrders, marketId); } else { final String errorMsg = "Failed to get your open orders from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } }
ItBitExchangeAdapter extends AbstractExchangeAdapter implements ExchangeAdapter { @Override public List<OpenOrder> getYourOpenOrders(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { if (walletId == null) { getBalanceInfo(); } final Map<String, String> params = createRequestParamMap(); params.put("status", "open"); response = sendAuthenticatedRequestToExchange( "GET", WALLETS_RESOURCE + "/" + walletId + "/orders", params); if (LOG.isDebugEnabled()) { LOG.debug("Open Orders response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitYourOrder[] itBitOpenOrders = gson.fromJson(response.getPayload(), ItBitYourOrder[].class); return adaptItBitOpenOrders(itBitOpenOrders, marketId); } else { final String errorMsg = "Failed to get your open orders from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } } }
ItBitExchangeAdapter extends AbstractExchangeAdapter implements ExchangeAdapter { @Override public List<OpenOrder> getYourOpenOrders(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { if (walletId == null) { getBalanceInfo(); } final Map<String, String> params = createRequestParamMap(); params.put("status", "open"); response = sendAuthenticatedRequestToExchange( "GET", WALLETS_RESOURCE + "/" + walletId + "/orders", params); if (LOG.isDebugEnabled()) { LOG.debug("Open Orders response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitYourOrder[] itBitOpenOrders = gson.fromJson(response.getPayload(), ItBitYourOrder[].class); return adaptItBitOpenOrders(itBitOpenOrders, marketId); } else { final String errorMsg = "Failed to get your open orders from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } }  }
ItBitExchangeAdapter extends AbstractExchangeAdapter implements ExchangeAdapter { @Override public List<OpenOrder> getYourOpenOrders(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { if (walletId == null) { getBalanceInfo(); } final Map<String, String> params = createRequestParamMap(); params.put("status", "open"); response = sendAuthenticatedRequestToExchange( "GET", WALLETS_RESOURCE + "/" + walletId + "/orders", params); if (LOG.isDebugEnabled()) { LOG.debug("Open Orders response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitYourOrder[] itBitOpenOrders = gson.fromJson(response.getPayload(), ItBitYourOrder[].class); return adaptItBitOpenOrders(itBitOpenOrders, marketId); } else { final String errorMsg = "Failed to get your open orders from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } }  @Override void init(ExchangeConfig config); @Override String createOrder(
      String marketId, OrderType orderType, BigDecimal quantity, BigDecimal price); @Override boolean cancelOrder(String orderId, String marketIdNotNeeded); @Override List<OpenOrder> getYourOpenOrders(String marketId); @Override MarketOrderBook getMarketOrders(String marketId); @Override BigDecimal getLatestMarketPrice(String marketId); @Override BalanceInfo getBalanceInfo(); @Override BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId); @Override BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId); @Override String getImplName(); @Override Ticker getTicker(String marketId); }
ItBitExchangeAdapter extends AbstractExchangeAdapter implements ExchangeAdapter { @Override public List<OpenOrder> getYourOpenOrders(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { if (walletId == null) { getBalanceInfo(); } final Map<String, String> params = createRequestParamMap(); params.put("status", "open"); response = sendAuthenticatedRequestToExchange( "GET", WALLETS_RESOURCE + "/" + walletId + "/orders", params); if (LOG.isDebugEnabled()) { LOG.debug("Open Orders response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitYourOrder[] itBitOpenOrders = gson.fromJson(response.getPayload(), ItBitYourOrder[].class); return adaptItBitOpenOrders(itBitOpenOrders, marketId); } else { final String errorMsg = "Failed to get your open orders from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } }  @Override void init(ExchangeConfig config); @Override String createOrder(
      String marketId, OrderType orderType, BigDecimal quantity, BigDecimal price); @Override boolean cancelOrder(String orderId, String marketIdNotNeeded); @Override List<OpenOrder> getYourOpenOrders(String marketId); @Override MarketOrderBook getMarketOrders(String marketId); @Override BigDecimal getLatestMarketPrice(String marketId); @Override BalanceInfo getBalanceInfo(); @Override BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId); @Override BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId); @Override String getImplName(); @Override Ticker getTicker(String marketId);  }