Пример #1
0
  @Test
  public void shouldGetCurrencyPairTradeHistory() throws IOException {
    // given
    final UserTrade[] expectedCpUserTrades = expectedCpUserTrades();

    BitMarketHistoryTradesResponse historyTradesCPResponse =
        parse("trade/example-history-trades-cp-data", BitMarketHistoryTradesResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsEurResponse =
        parse(
            "trade/example-history-operations-eur-data", BitMarketHistoryOperationsResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsBtcResponse =
        parse(
            "trade/example-history-operations-btc-data", BitMarketHistoryOperationsResponse.class);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trades(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCEUR"),
                Mockito.eq(1000),
                Mockito.eq(0L)))
        .thenReturn(historyTradesCPResponse);

    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.EUR.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsEurResponse);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.BTC.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsBtcResponse);

    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    UserTrades tradesCP =
        tradeService.getTradeHistory(
            new DefaultTradeHistoryParamCurrencyPair(CurrencyPair.BTC_EUR));
    List<UserTrade> userTrades = tradesCP.getUserTrades();

    // then
    assertThat(userTrades).hasSize(2);
    for (int i = 0; i < userTrades.size(); i++) {
      BitMarketAssert.assertEquals(userTrades.get(i), expectedCpUserTrades[i]);
    }
  }
Пример #2
0
  @Test
  public void shouldGetTradeHistory() throws IOException {
    // given
    BitMarketHistoryTradesResponse historyTradesBMResponse =
        parse("trade/example-history-trades-bm-data", BitMarketHistoryTradesResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsEurResponse =
        parse(
            "trade/example-history-operations-eur-data", BitMarketHistoryOperationsResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsBtcResponse =
        parse(
            "trade/example-history-operations-btc-data", BitMarketHistoryOperationsResponse.class);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trades(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCEUR"),
                Mockito.eq(3500),
                Mockito.eq(500L)))
        .thenReturn(historyTradesBMResponse);

    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.EUR.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsEurResponse);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.BTC.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsBtcResponse);

    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    UserTrades tradesBM =
        tradeService.getTradeHistory(new BitMarketHistoryParams(CurrencyPair.BTC_EUR, 500L, 3500));
    List<UserTrade> userTrades = tradesBM.getUserTrades();

    // then
    assertThat(userTrades).hasSize(1);
    BitMarketAssert.assertEquals(userTrades.get(0), EXPECTED_BM_USER_TRADES);
  }