Ejemplo n.º 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]);
    }
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 3
0
  @Test(expected = ExchangeException.class)
  public void shouldFailOnUnsuccessfulTradeHistory() throws IOException {
    // given
    BitMarketHistoryTradesResponse response =
        new BitMarketHistoryTradesResponse(
            false, null, new BitMarketAPILimit(3, 100, 12345000L), 502, "Invalid message hash");

    BitMarketHistoryOperationsResponse marketHistoryOperationsPlnResponse =
        parse("trade/example-history-operations-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("BTCPLN"),
                Mockito.eq(1000),
                Mockito.eq(0L)))
        .thenReturn(response);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.PLN.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsPlnResponse);
    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
    tradeService.getTradeHistory(new DefaultTradeHistoryParamPaging(150));

    // then
    fail(
        "BitMarketTradeService should throw ExchangeException when open orders request was unsuccessful");
  }