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);
}
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);
}
Aggregations