Search in sources :

Example 1 with CurrencyMetaData

use of org.knowm.xchange.dto.meta.CurrencyMetaData in project XChange by knowm.

the class BitstampAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(List<BitstampPairInfo> rawSymbols, ExchangeMetaData metaData) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = adaptCurrencyPairs(rawSymbols);
    Map<CurrencyPair, CurrencyPairMetaData> pairsMap = metaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currenciesMap = metaData.getCurrencies();
    for (Map.Entry<CurrencyPair, CurrencyPairMetaData> entry : currencyPairs.entrySet()) {
        CurrencyPair c = entry.getKey();
        CurrencyPairMetaData cmeta = entry.getValue();
        if (!pairsMap.containsKey(c)) {
            pairsMap.put(c, cmeta);
        } else {
            pairsMap.replace(c, cmeta);
        }
        if (!currenciesMap.containsKey(c.base)) {
            currenciesMap.put(c.base, null);
        }
        if (!currenciesMap.containsKey(c.counter)) {
            currenciesMap.put(c.counter, null);
        }
    }
    return metaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Currency(org.knowm.xchange.currency.Currency) HashMap(java.util.HashMap) Map(java.util.Map) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CurrencyMetaData

use of org.knowm.xchange.dto.meta.CurrencyMetaData in project XChange by knowm.

the class LgoAdapters method adaptMetadata.

public static ExchangeMetaData adaptMetadata(ExchangeMetaData metaData, LgoProducts products, LgoCurrencies currencies) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = metaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currency = metaData.getCurrencies();
    for (LgoCurrency lgoCurrency : currencies.getCurrencies()) {
        currency.put(Currency.getInstance(lgoCurrency.getCode()), new CurrencyMetaData(lgoCurrency.getDecimals(), null));
    }
    for (LgoProduct product : products.getProducts()) {
        BigDecimal minAmount = product.getBase().getLimits().getMin();
        BigDecimal maxAmount = product.getBase().getLimits().getMax();
        Integer baseScale = currency.get(Currency.getInstance(product.getBase().getId())).getScale();
        BigDecimal increment = product.getQuote().getIncrement().stripTrailingZeros();
        currencyPairs.put(toPair(product), new CurrencyPairMetaData(null, minAmount, maxAmount, null, null, baseScale, increment.scale(), null, new FeeTier[0], increment, Currency.USD, true));
    }
    return metaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) LgoCurrency(org.knowm.xchange.lgo.dto.currency.LgoCurrency) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) LgoProduct(org.knowm.xchange.lgo.dto.product.LgoProduct) Currency(org.knowm.xchange.currency.Currency) LgoCurrency(org.knowm.xchange.lgo.dto.currency.LgoCurrency) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with CurrencyMetaData

use of org.knowm.xchange.dto.meta.CurrencyMetaData in project XChange by knowm.

the class LatokenExchange method remoteInit.

@Override
public void remoteInit() {
    try {
        // Load the static meta-data and override with the dynamic one
        Map<Currency, CurrencyMetaData> currenciesMetaData = exchangeMetaData.getCurrencies();
        Map<CurrencyPair, CurrencyPairMetaData> pairsMetaData = exchangeMetaData.getCurrencyPairs();
        List<LatokenPair> allPairs = latoken.getAllPairs();
        List<LatokenCurrency> allCurrencies = latoken.getAllCurrencies();
        // Save pairs map on the exchange
        this.exchangeSpecification.setExchangeSpecificParametersItem("pairs", allPairs);
        // Update Currency meta-data
        for (LatokenCurrency latokenCurrency : allCurrencies) {
            Currency currency = LatokenAdapters.adaptCurrency(latokenCurrency);
            addCurrencyMetadata(currenciesMetaData, currency, PRECISION);
        }
        // Update CurrencyPair meta-data
        for (LatokenPair latokenPair : allPairs) {
            CurrencyPair pair = LatokenAdapters.adaptCurrencyPair(latokenPair);
            CurrencyPairMetaData pairMetadata = LatokenAdapters.adaptPairMetaData(latokenPair);
            addCurrencyPairMetadata(pairsMetaData, pair, pairMetadata);
        }
    } catch (Exception e) {
        throw new ExchangeException("Failed to initialize: " + e.getMessage(), e);
    }
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) Currency(org.knowm.xchange.currency.Currency) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenPair(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 4 with CurrencyMetaData

use of org.knowm.xchange.dto.meta.CurrencyMetaData in project XChange by knowm.

the class LatokenExchange method addCurrencyMetadata.

/**
 * Updates the meta-data entry of a given {@link Currency}. <br>
 * Used for overriding the static meta-data with dynamic one received from the exchange.
 *
 * @param currencies
 * @param currency
 * @param precision
 */
private void addCurrencyMetadata(Map<Currency, CurrencyMetaData> currencies, Currency currency, int precision) {
    CurrencyMetaData baseMetaData = currencies.get(currency);
    // Preserve withdrawal-fee if exists
    BigDecimal withdrawalFee = baseMetaData == null ? null : baseMetaData.getWithdrawalFee();
    // Override static meta-data
    currencies.put(currency, new CurrencyMetaData(precision, withdrawalFee));
}
Also used : CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) BigDecimal(java.math.BigDecimal)

Example 5 with CurrencyMetaData

use of org.knowm.xchange.dto.meta.CurrencyMetaData in project XChange by knowm.

the class AccountServiceIntegration method testMetaData.

@Test
public void testMetaData() throws Exception {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchange.getExchangeMetaData().getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = exchange.getExchangeMetaData().getCurrencies();
    CurrencyPair currPair;
    Currency curr;
    currPair = currencyPairs.keySet().stream().filter(cp -> "ETH/BTC".equals(cp.toString())).collect(StreamUtils.singletonCollector());
    Assert.assertNotNull(currPair);
    curr = currencies.keySet().stream().filter(c -> Currency.BTC.equals(c)).collect(StreamUtils.singletonCollector());
    Assert.assertNotNull(curr);
    Assert.assertNotNull(curr);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Aggregations

CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)42 Currency (org.knowm.xchange.currency.Currency)34 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)32 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)32 BigDecimal (java.math.BigDecimal)19 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)17 HashMap (java.util.HashMap)14 FeeTier (org.knowm.xchange.dto.meta.FeeTier)7 WalletHealth (org.knowm.xchange.dto.meta.WalletHealth)7 Map (java.util.Map)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 Fee (org.knowm.xchange.dto.account.Fee)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 InputStream (java.io.InputStream)2 Field (java.lang.reflect.Field)2 Modifier (java.lang.reflect.Modifier)2 HttpURLConnection (java.net.HttpURLConnection)2