Exemplo n.º 1
0
  @Test
  public void shouldGetOpenOrders() throws IOException {
    // given
    final LimitOrder[] expectedOrders = expectedOrders();

    BitMarketOrdersResponse response =
        new BitMarketOrdersResponse(
            true, createOpenOrdersData(), new BitMarketAPILimit(3, 100, 12345000L), 0, null);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.orders(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class)))
        .thenReturn(response);
    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    OpenOrders orders = tradeService.getOpenOrders();
    List<LimitOrder> openOrders = orders.getOpenOrders();

    // then
    assertThat(openOrders).hasSize(2);
    for (int i = 0; i < openOrders.size(); i++) {
      BitMarketAssert.assertEquals(openOrders.get(i), expectedOrders[i]);
      assertThat(orders.toString()).contains(expectedOrders[i].toString());
    }
  }
Exemplo n.º 2
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]);
    }
  }
Exemplo n.º 3
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);
  }
  @Test
  public void shouldGetTicker() throws IOException {
    // given
    BitMarketTicker response = parse("marketdata/example-ticker-data", BitMarketTicker.class);

    BitMarket bitMarket = mock(BitMarket.class);
    PowerMockito.when(bitMarket.getTicker("BTCAUD")).thenReturn(response);
    Whitebox.setInternalState(dataService, "bitMarket", bitMarket);

    // when
    Ticker ticker = dataService.getTicker(CurrencyPair.BTC_AUD);

    // then
    BitMarketAssert.assertEquals(ticker, TICKER);
  }
  @Test
  public void shouldGetOrderBook() throws IOException {
    // given
    BitMarketOrderBook response =
        parse("marketdata/example-order-book-data", BitMarketOrderBook.class);

    BitMarket bitMarket = mock(BitMarket.class);
    PowerMockito.when(bitMarket.getOrderBook("BTCAUD")).thenReturn(response);
    Whitebox.setInternalState(dataService, "bitMarket", bitMarket);

    // when
    OrderBook orderBook = dataService.getOrderBook(CurrencyPair.BTC_AUD);

    // then
    BitMarketAssert.assertEquals(orderBook, ORDER_BOOK);
  }
  @Test
  public void shouldGetTrades() throws IOException {
    // given
    final Trade[] expectedTrades = expectedTrades();
    BitMarketTrade[] response = parse("marketdata/example-trades-data", BitMarketTrade[].class);

    BitMarket bitMarket = mock(BitMarket.class);
    PowerMockito.when(bitMarket.getTrades("BTCAUD")).thenReturn(response);
    Whitebox.setInternalState(dataService, "bitMarket", bitMarket);

    // when
    Trades trades = dataService.getTrades(CurrencyPair.BTC_AUD);
    List<Trade> tradeList = trades.getTrades();

    // then
    assertThat(tradeList).hasSize(3);
    for (int i = 0; i < tradeList.size(); i++) {
      BitMarketAssert.assertEquals(tradeList.get(i), expectedTrades[i]);
    }
  }