Search in sources :

Example 1 with BiboxResponse

use of org.knowm.xchange.bibox.dto.BiboxResponse in project XChange by knowm.

the class BiboxMarketDataServiceRaw method getBiboxOrderBooks.

public List<BiboxOrderBook> getBiboxOrderBooks(Integer depth, Collection<CurrencyPair> currencyPairs) {
    try {
        List<BiboxCommand<?>> allCommands = currencyPairs.stream().distinct().filter(Objects::nonNull).map(BiboxAdapters::toBiboxPair).map(pair -> new BiboxOrderBookCommand(pair, depth)).collect(Collectors.toList());
        BiboxMultipleResponses<BiboxOrderBook> response = bibox.orderBooks(BiboxCommands.of(allCommands).json());
        throwErrors(response);
        return response.getResult().stream().map(BiboxResponse::getResult).collect(Collectors.toList());
    } catch (BiboxException e) {
        throw new ExchangeException(e.getMessage());
    }
}
Also used : BiboxOrderBookCommand(org.knowm.xchange.bibox.dto.marketdata.BiboxOrderBookCommand) BiboxOrderBook(org.knowm.xchange.bibox.dto.trade.BiboxOrderBook) BiboxAdapters(org.knowm.xchange.bibox.dto.BiboxAdapters) Collection(java.util.Collection) IOException(java.io.IOException) BiboxMarket(org.knowm.xchange.bibox.dto.marketdata.BiboxMarket) Exchange(org.knowm.xchange.Exchange) BiboxCommand(org.knowm.xchange.bibox.dto.BiboxCommand) Collectors(java.util.stream.Collectors) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BiboxException(org.knowm.xchange.bibox.BiboxException) BiboxDeals(org.knowm.xchange.bibox.dto.trade.BiboxDeals) Objects(java.util.Objects) List(java.util.List) BiboxCommands(org.knowm.xchange.bibox.dto.BiboxCommands) BiboxResponse(org.knowm.xchange.bibox.dto.BiboxResponse) BiboxAdapters.toBiboxPair(org.knowm.xchange.bibox.dto.BiboxAdapters.toBiboxPair) BiboxMultipleResponses(org.knowm.xchange.bibox.dto.BiboxMultipleResponses) BiboxTicker(org.knowm.xchange.bibox.dto.marketdata.BiboxTicker) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BiboxOrderBookCommand(org.knowm.xchange.bibox.dto.marketdata.BiboxOrderBookCommand) BiboxOrderBook(org.knowm.xchange.bibox.dto.trade.BiboxOrderBook) BiboxAdapters(org.knowm.xchange.bibox.dto.BiboxAdapters) BiboxCommand(org.knowm.xchange.bibox.dto.BiboxCommand) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BiboxException(org.knowm.xchange.bibox.BiboxException)

Example 2 with BiboxResponse

use of org.knowm.xchange.bibox.dto.BiboxResponse in project XChange by knowm.

the class BiboxMarketdataUnmarshalTest method testTickerUnmarshal.

@Test
public void testTickerUnmarshal() throws IOException {
    BiboxResponse<BiboxTicker> response = BiboxTestUtils.getResponse(new TypeReference<BiboxResponse<BiboxTicker>>() {
    }, "/org/knowm/xchange/bibox/dto/marketdata/example-ticker.json");
    assertThat(response.getCmd()).isEqualTo("ticker");
    BiboxTicker ticker = response.getResult();
    assertThat(ticker.getBuy()).isEqualTo(new BigDecimal("0.00009284"));
    assertThat(ticker.getHigh()).isEqualTo(new BigDecimal("0.00010000"));
    assertThat(ticker.getLast()).isEqualTo(new BigDecimal("0.00009293"));
    assertThat(ticker.getLow()).isEqualTo(new BigDecimal("0.00008892"));
    assertThat(ticker.getSell()).isEqualTo(new BigDecimal("0.00009293"));
    assertThat(ticker.getTimestamp()).isEqualTo(1518037192690L);
    assertThat(ticker.getVol()).isEqualTo(new BigDecimal("5691444"));
    assertThat(ticker.getLastCny()).isEqualTo(new BigDecimal("4.77"));
    assertThat(ticker.getLastUsd()).isEqualTo(new BigDecimal("0.76"));
    assertThat(ticker.getPercent()).isEqualTo("-3.62%");
}
Also used : BiboxResponse(org.knowm.xchange.bibox.dto.BiboxResponse) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BiboxResponse

use of org.knowm.xchange.bibox.dto.BiboxResponse in project XChange by knowm.

the class BiboxMarketdataUnmarshalTest method testAllMarketsUnmarshal.

@Test
public void testAllMarketsUnmarshal() throws IOException {
    BiboxResponse<List<BiboxMarket>> response = BiboxTestUtils.getResponse(new TypeReference<BiboxResponse<List<BiboxMarket>>>() {
    }, "/org/knowm/xchange/bibox/dto/marketdata/example-all-markets.json");
    assertThat(response.getCmd()).isEqualTo("marketAll");
    List<BiboxMarket> markets = response.getResult();
    assertThat(markets).hasSize(2);
    BiboxMarket first = markets.get(0);
    assertThat(first.getId()).isEqualTo(1);
    assertThat(first.getCoinSymbol()).isEqualTo("BIX");
    assertThat(first.getCurrencySymbol()).isEqualTo("BTC");
    assertThat(first.getLast()).isEqualTo(new BigDecimal("0.00010186"));
    assertThat(first.getHigh()).isEqualTo(new BigDecimal("0.00012146"));
    assertThat(first.getLow()).isEqualTo(new BigDecimal("0.00009950"));
    assertThat(first.getChange()).isEqualTo(new BigDecimal("-0.00001812"));
    assertThat(first.getVol24H()).isEqualTo(new BigDecimal("6511185"));
    assertThat(first.getAmount()).isEqualTo(new BigDecimal("706.60"));
    assertThat(first.getLastCny()).isEqualTo(new BigDecimal("5.25"));
    assertThat(first.getHighCny()).isEqualTo(new BigDecimal("6.26"));
    assertThat(first.getLowCny()).isEqualTo(new BigDecimal("5.13"));
    assertThat(first.getLastUsd()).isEqualTo(new BigDecimal("0.83"));
    assertThat(first.getHighUsd()).isEqualTo(new BigDecimal("0.99"));
    assertThat(first.getLowUsd()).isEqualTo(new BigDecimal("0.81"));
    BiboxMarket second = markets.get(1);
    assertThat(second.getId()).isEqualTo(2);
    assertThat(second.getCoinSymbol()).isEqualTo("BIX");
    assertThat(second.getCurrencySymbol()).isEqualTo("ETH");
    assertThat(second.getLast()).isEqualTo(new BigDecimal("0.00100755"));
    assertThat(second.getHigh()).isEqualTo(new BigDecimal("0.00124305"));
    assertThat(second.getLow()).isEqualTo(new BigDecimal("0.00095500"));
    assertThat(second.getChange()).isEqualTo(new BigDecimal("-0.00019295"));
    assertThat(second.getVol24H()).isEqualTo(new BigDecimal("6359569"));
    assertThat(second.getAmount()).isEqualTo(new BigDecimal("6835.14"));
    assertThat(second.getLastCny()).isEqualTo(new BigDecimal("5.25"));
    assertThat(second.getHighCny()).isEqualTo(new BigDecimal("6.48"));
    assertThat(second.getLowCny()).isEqualTo(new BigDecimal("4.98"));
    assertThat(second.getLastUsd()).isEqualTo(new BigDecimal("0.83"));
    assertThat(second.getHighUsd()).isEqualTo(new BigDecimal("1.03"));
    assertThat(second.getLowUsd()).isEqualTo(new BigDecimal("0.79"));
}
Also used : List(java.util.List) BiboxResponse(org.knowm.xchange.bibox.dto.BiboxResponse) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with BiboxResponse

use of org.knowm.xchange.bibox.dto.BiboxResponse in project XChange by knowm.

the class BiboxMarketdataUnmarshalTest method testOrderBookUnmarshal.

@Test
public void testOrderBookUnmarshal() throws IOException {
    BiboxResponse<BiboxOrderBook> response = BiboxTestUtils.getResponse(new TypeReference<BiboxResponse<BiboxOrderBook>>() {
    }, "/org/knowm/xchange/bibox/dto/marketdata/example-order-book.json");
    assertThat(response.getCmd()).isEqualTo("depth");
    BiboxOrderBook orderBook = response.getResult();
    assertThat(orderBook.getPair()).isEqualTo("BIX_BTC");
    assertThat(orderBook.getUpdateTime()).isEqualTo(1518133407425L);
    assertThat(orderBook.getAsks()).hasSize(2);
    assertThat(orderBook.getBids()).hasSize(2);
    assertThat(orderBook.getAsks().get(0).getPrice()).isEqualTo(BigDecimal.valueOf(0.00010202));
    assertThat(orderBook.getAsks().get(0).getVolume()).isEqualTo(BigDecimal.valueOf(100));
    assertThat(orderBook.getBids().get(0).getPrice()).isEqualTo(BigDecimal.valueOf(0.00010179));
    assertThat(orderBook.getBids().get(0).getVolume()).isEqualTo(BigDecimal.valueOf(127.7667));
}
Also used : BiboxOrderBook(org.knowm.xchange.bibox.dto.trade.BiboxOrderBook) BiboxResponse(org.knowm.xchange.bibox.dto.BiboxResponse) Test(org.junit.Test)

Aggregations

BiboxResponse (org.knowm.xchange.bibox.dto.BiboxResponse)4 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 BiboxOrderBook (org.knowm.xchange.bibox.dto.trade.BiboxOrderBook)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Exchange (org.knowm.xchange.Exchange)1 BiboxException (org.knowm.xchange.bibox.BiboxException)1 BiboxAdapters (org.knowm.xchange.bibox.dto.BiboxAdapters)1 BiboxAdapters.toBiboxPair (org.knowm.xchange.bibox.dto.BiboxAdapters.toBiboxPair)1 BiboxCommand (org.knowm.xchange.bibox.dto.BiboxCommand)1 BiboxCommands (org.knowm.xchange.bibox.dto.BiboxCommands)1 BiboxMultipleResponses (org.knowm.xchange.bibox.dto.BiboxMultipleResponses)1 BiboxMarket (org.knowm.xchange.bibox.dto.marketdata.BiboxMarket)1 BiboxOrderBookCommand (org.knowm.xchange.bibox.dto.marketdata.BiboxOrderBookCommand)1 BiboxTicker (org.knowm.xchange.bibox.dto.marketdata.BiboxTicker)1 BiboxDeals (org.knowm.xchange.bibox.dto.trade.BiboxDeals)1