Search in sources :

Example 1 with CoinbaseProProduct

use of org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct in project XChange by knowm.

the class CoinbaseProAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(ExchangeMetaData exchangeMetaData, CoinbaseProProduct[] products, CoinbaseProCurrency[] cbCurrencies) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData == null ? new HashMap<>() : exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData == null ? new HashMap<>() : exchangeMetaData.getCurrencies();
    for (CoinbaseProProduct product : products) {
        if (!"online".equals(product.getStatus())) {
            continue;
        }
        CurrencyPair pair = adaptCurrencyPair(product);
        CurrencyPairMetaData staticMetaData = currencyPairs.get(pair);
        int baseScale = numberOfDecimals(product.getBaseIncrement());
        int priceScale = numberOfDecimals(product.getQuoteIncrement());
        boolean marketOrderAllowed = !product.isLimitOnly();
        currencyPairs.put(pair, new CurrencyPairMetaData(// Trading fee at Coinbase is 0.5 %
        new BigDecimal("0.50"), product.getBaseMinSize(), product.getBaseMaxSize(), product.getMinMarketFunds(), product.getMaxMarketFunds(), baseScale, priceScale, null, staticMetaData != null ? staticMetaData.getFeeTiers() : null, null, pair.counter, marketOrderAllowed));
    }
    Arrays.stream(cbCurrencies).forEach(currency -> currencies.put(adaptCurrency(currency), new CurrencyMetaData(numberOfDecimals(currency.getMaxPrecision()), BigDecimal.ZERO, currency.getDetails().getMinWithdrawalAmount(), "online".equals(currency.getStatus()) ? WalletHealth.ONLINE : WalletHealth.OFFLINE)));
    return new ExchangeMetaData(currencyPairs, currencies, exchangeMetaData == null ? null : exchangeMetaData.getPublicRateLimits(), exchangeMetaData == null ? null : exchangeMetaData.getPrivateRateLimits(), true);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) CoinbaseProCurrency(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) CoinbaseProProduct(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct)

Example 2 with CoinbaseProProduct

use of org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct in project XChange by knowm.

the class CoinbaseProMetadataTest method unmarshalTest.

// @Test
public void unmarshalTest() throws IOException {
    JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    ObjectMapper mapper = factory.createObjectMapper();
    InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/products.json");
    CoinbaseProProduct[] products = mapper.readValue(is, CoinbaseProProduct[].class);
    assertThat(products).hasSize(10);
    ExchangeSpecification specification = new ExchangeSpecification(CoinbaseProExchange.class);
    specification.setShouldLoadRemoteMetaData(false);
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
    ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
    exchangeMetaData = CoinbaseProAdapters.adaptToExchangeMetaData(exchangeMetaData, products, new CoinbaseProCurrency[] {});
    assertThat(exchangeMetaData.getCurrencyPairs().get(CurrencyPair.ETC_BTC).getPriceScale()).isEqualTo(5);
}
Also used : Exchange(org.knowm.xchange.Exchange) CoinbaseProExchange(org.knowm.xchange.coinbasepro.CoinbaseProExchange) InputStream(java.io.InputStream) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) CoinbaseProCurrency(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) JacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CoinbaseProProduct(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct)

Aggregations

CoinbaseProCurrency (org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency)2 CoinbaseProProduct (org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct)2 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 CoinbaseProExchange (org.knowm.xchange.coinbasepro.CoinbaseProExchange)1 Currency (org.knowm.xchange.currency.Currency)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)1 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)1 DefaultJacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory)1 JacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory)1