OandaTradeManagementProvider implements TradeManagementProvider<Long, String, Long> { @Override public boolean modifyTrade(Long accountId, Long tradeId, double stopLoss, double takeProfit) { CloseableHttpClient httpClient = getHttpClient(); try { HttpPatch httpPatch = createPatchCommand(accountId, tradeId, stopLoss, takeProfit); LOG.info(TradingUtils.executingRequestMsg(httpPatch)); HttpResponse resp = httpClient.execute(httpPatch); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (resp.getEntity() != null) { LOG.info("Trade Modified->" + TradingUtils.responseToString(resp)); } else { LOG.warn(String.format("trade %d could not be modified with stop loss %3.5f", tradeId, stopLoss)); } return true; } else { LOG.warn(String.format( "trade %d could not be modified with stop loss %3.5f and take profit %3.5f. http code=%d", tradeId, stopLoss, takeProfit, resp.getStatusLine().getStatusCode())); } } catch (Exception e) { LOG.error( String.format("error while modifying trade %d to stop loss %3.5f, take profit %3.5f for account %d", tradeId, stopLoss, takeProfit, accountId), e); } finally { TradingUtils.closeSilently(httpClient); } return false; } OandaTradeManagementProvider(String url, String accessToken); @Override Collection<Trade<Long, String, Long>> getTradesForAccount(Long accountId); @Override Trade<Long, String, Long> getTradeForAccount(Long tradeId, Long accountId); @Override boolean modifyTrade(Long accountId, Long tradeId, double stopLoss, double takeProfit); @Override boolean closeTrade(Long tradeId, Long accountId);  }
@Test public void modifyTradeTest() throws Exception { OandaTradeManagementProvider service = new OandaTradeManagementProvider(OandaTestConstants.url, OandaTestConstants.accessToken); final long tradeId = OandaTestConstants.tradeId; assertEquals("https: .getTradeForAccountUrl(tradeId, OandaTestConstants.accountId)); OandaTradeManagementProvider spy = doMockStuff("src/test/resources/tradesForAccount123456.txt", service); final double stopLoss = 150.0; final double takeProfit = 110.0; spy.modifyTrade(OandaTestConstants.accountId, tradeId, stopLoss, takeProfit); verify(spy, times(1)).createPatchCommand(OandaTestConstants.accountId, tradeId, stopLoss, takeProfit); }