private void ohlcRequestSample() { final Ohlc ohlc = iexTradingClient.executeRequest(new OhlcRequestBuilder() .withSymbol("aapl") .build()); System.out.println(ohlc); }
@Override public RestRequest<Ohlc> build() { return RestRequestBuilder.<Ohlc>builder() .withPath("/stock/{symbol}/ohlc") .addPathParam("symbol", getSymbol()).get() .withResponse(Ohlc.class) .build(); } }
@Test public void ohlcAcceptanceTest() { final Ohlc ohlc = iexTradingClient.executeRequest(new OhlcRequestBuilder() .withSymbol("aapl") .build()); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<Ohlc> request = new OhlcRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/ohlc"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Ohlc>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
@Test public void ohlcServiceTest() { stubFor(get(urlEqualTo("/stock/aapl/ohlc")) .withHeader("Accept", equalTo("application/json")) .willReturn(aResponse() .withStatus(200) .withHeader("Accept", "application/json") .withHeader("Content-Type", "application/json") .withBodyFile("rest/stock/OhlcResponse.json"))); final Ohlc ohlc = iexTradingClient.executeRequest(new OhlcRequestBuilder() .withSymbol("aapl") .build()); assertThat(ohlc.getOpen().getPrice()).isEqualByComparingTo(BigDecimal.valueOf(154)); assertThat(ohlc.getOpen().getTime()).isEqualTo(1506605400394L); assertThat(ohlc.getClose().getPrice()).isEqualByComparingTo(BigDecimal.valueOf(153.28)); assertThat(ohlc.getClose().getTime()).isEqualTo(1506605400394L); assertThat(ohlc.getHigh()).isEqualByComparingTo(BigDecimal.valueOf(154.80)); assertThat(ohlc.getLow()).isEqualByComparingTo(BigDecimal.valueOf(153.25)); }