Search in sources :

Example 6 with CurrencyMetaData

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

the class CCEXAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(ExchangeMetaData exchangeMetaData, List<CCEXMarket> products) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = new HashMap<>();
    Map<CurrencyPair, CurrencyPairMetaData> existingCurrencyPairMetadata = exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = new HashMap<>();
    for (CCEXMarket product : products) {
        BigDecimal minSize = product.getMinTradeSize();
        CurrencyPair pair = adaptCurrencyPair(product);
        CurrencyPairMetaData existingMetaForPair = existingCurrencyPairMetadata.get(pair);
        FeeTier[] existingFeeTiers = null;
        if (existingMetaForPair != null) {
            existingFeeTiers = existingMetaForPair.getFeeTiers();
        }
        CurrencyPairMetaData cpmd = new CurrencyPairMetaData(null, minSize, null, 0, existingFeeTiers);
        currencyPairs.put(pair, cpmd);
        currencies.put(pair.base, null);
        currencies.put(pair.counter, null);
    }
    return new ExchangeMetaData(currencyPairs, currencies, null, null, true);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) CCEXMarket(org.knowm.xchange.ccex.dto.marketdata.CCEXMarket) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 7 with CurrencyMetaData

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

the class OkexAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(ExchangeMetaData exchangeMetaData, List<OkexInstrument> instruments, List<OkexCurrency> currs) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs() == null ? new HashMap<>() : exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies() == null ? new HashMap<>() : exchangeMetaData.getCurrencies();
    for (OkexInstrument instrument : instruments) {
        if (!"live".equals(instrument.getState())) {
            continue;
        }
        CurrencyPair pair = adaptCurrencyPair(instrument);
        CurrencyPairMetaData staticMetaData = currencyPairs.get(pair);
        int priceScale = numberOfDecimals(new BigDecimal(instrument.getTickSize()));
        currencyPairs.put(pair, new CurrencyPairMetaData(new BigDecimal("0.50"), new BigDecimal(instrument.getMinSize()), null, null, null, null, priceScale, null, staticMetaData != null ? staticMetaData.getFeeTiers() : null, null, pair.counter, true));
    }
    if (currs != null) {
        currs.stream().forEach(currency -> currencies.put(adaptCurrency(currency), new CurrencyMetaData(null, new BigDecimal(currency.getMaxFee()), new BigDecimal(currency.getMinWd()), currency.isCanWd() && currency.isCanDep() ? WalletHealth.ONLINE : WalletHealth.OFFLINE)));
    }
    return new ExchangeMetaData(currencyPairs, currencies, exchangeMetaData.getPublicRateLimits(), 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) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) OkexInstrument(org.knowm.xchange.okex.v5.dto.marketdata.OkexInstrument) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 8 with CurrencyMetaData

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

the class BinanceAdapters method adaptCurrencyMetaData.

static CurrencyMetaData adaptCurrencyMetaData(Map<Currency, CurrencyMetaData> currencies, Currency currency, Map<String, AssetDetail> assetDetailMap, int precision) {
    if (assetDetailMap != null) {
        AssetDetail asset = assetDetailMap.get(currency.getCurrencyCode());
        if (asset != null) {
            BigDecimal withdrawalFee = asset.getWithdrawFee().stripTrailingZeros();
            BigDecimal minWithdrawalAmount = new BigDecimal(asset.getMinWithdrawAmount()).stripTrailingZeros();
            WalletHealth walletHealth = getWalletHealth(asset.isDepositStatus(), asset.isWithdrawStatus());
            return new CurrencyMetaData(precision, withdrawalFee, minWithdrawalAmount, walletHealth);
        }
    }
    BigDecimal withdrawalFee = null;
    BigDecimal minWithdrawalAmount = null;
    if (currencies.containsKey(currency)) {
        CurrencyMetaData currencyMetaData = currencies.get(currency);
        withdrawalFee = currencyMetaData.getWithdrawalFee();
        minWithdrawalAmount = currencyMetaData.getMinWithdrawalAmount();
    }
    return new CurrencyMetaData(precision, withdrawalFee, minWithdrawalAmount);
}
Also used : WalletHealth(org.knowm.xchange.dto.meta.WalletHealth) AssetDetail(org.knowm.xchange.binance.dto.account.AssetDetail) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) BigDecimal(java.math.BigDecimal)

Example 9 with CurrencyMetaData

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

the class BinanceExchange method postInit.

protected void postInit(Map<String, AssetDetail> assetDetailMap) {
    // populate currency pair keys only, exchange does not provide any other metadata for download
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies();
    // Clear all hardcoded currencies when loading dynamically from exchange.
    if (assetDetailMap != null) {
        currencies.clear();
    }
    Symbol[] symbols = exchangeInfo.getSymbols();
    for (Symbol symbol : symbols) {
        if (symbol.getStatus().equals("TRADING")) {
            // Symbols which are trading
            int basePrecision = Integer.parseInt(symbol.getBaseAssetPrecision());
            int counterPrecision = Integer.parseInt(symbol.getQuotePrecision());
            int pairPrecision = 8;
            int amountPrecision = 8;
            BigDecimal minQty = null;
            BigDecimal maxQty = null;
            BigDecimal stepSize = null;
            BigDecimal counterMinQty = null;
            BigDecimal counterMaxQty = null;
            Filter[] filters = symbol.getFilters();
            CurrencyPair currentCurrencyPair = new CurrencyPair(symbol.getBaseAsset(), symbol.getQuoteAsset());
            for (Filter filter : filters) {
                if (filter.getFilterType().equals("PRICE_FILTER")) {
                    pairPrecision = Math.min(pairPrecision, numberOfDecimals(filter.getTickSize()));
                    counterMaxQty = new BigDecimal(filter.getMaxPrice()).stripTrailingZeros();
                } else if (filter.getFilterType().equals("LOT_SIZE")) {
                    amountPrecision = Math.min(amountPrecision, numberOfDecimals(filter.getStepSize()));
                    minQty = new BigDecimal(filter.getMinQty()).stripTrailingZeros();
                    maxQty = new BigDecimal(filter.getMaxQty()).stripTrailingZeros();
                    stepSize = new BigDecimal(filter.getStepSize()).stripTrailingZeros();
                } else if (filter.getFilterType().equals("MIN_NOTIONAL")) {
                    counterMinQty = new BigDecimal(filter.getMinNotional()).stripTrailingZeros();
                }
            }
            boolean marketOrderAllowed = Arrays.asList(symbol.getOrderTypes()).contains("MARKET");
            currencyPairs.put(currentCurrencyPair, new CurrencyPairMetaData(// Trading fee at Binance is 0.1 %
            new BigDecimal("0.1"), // Min amount
            minQty, // Max amount
            maxQty, counterMinQty, counterMaxQty, // base precision
            amountPrecision, // counter precision
            pairPrecision, null, null, /* TODO get fee tiers, although this is not necessary now
                      because their API returns current fee directly */
            stepSize, null, marketOrderAllowed));
            Currency baseCurrency = currentCurrencyPair.base;
            CurrencyMetaData baseCurrencyMetaData = BinanceAdapters.adaptCurrencyMetaData(currencies, baseCurrency, assetDetailMap, basePrecision);
            currencies.put(baseCurrency, baseCurrencyMetaData);
            Currency counterCurrency = currentCurrencyPair.counter;
            CurrencyMetaData counterCurrencyMetaData = BinanceAdapters.adaptCurrencyMetaData(currencies, counterCurrency, assetDetailMap, counterPrecision);
            currencies.put(counterCurrency, counterCurrencyMetaData);
        }
    }
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Symbol(org.knowm.xchange.binance.dto.meta.exchangeinfo.Symbol) BigDecimal(java.math.BigDecimal) Filter(org.knowm.xchange.binance.dto.meta.exchangeinfo.Filter) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 10 with CurrencyMetaData

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

the class BleutradeAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(List<BleutradeCurrency> bleutradeCurrencies, List<BleutradeMarket> bleutradeMarkets) {
    Map<CurrencyPair, CurrencyPairMetaData> marketMetaDataMap = new HashMap<>();
    Map<Currency, CurrencyMetaData> currencyMetaDataMap = new HashMap<>();
    for (BleutradeCurrency bleutradeCurrency : bleutradeCurrencies) {
        // the getTxFee parameter is the withdrawal charge in the currency in question
        currencyMetaDataMap.put(Currency.getInstance(bleutradeCurrency.getCurrency()), new CurrencyMetaData(8, null));
    }
    // https://bleutrade.com/help/fees_and_deadlines 11/25/2015 all == 0.25%
    BigDecimal txFee = new BigDecimal("0.0025");
    for (BleutradeMarket bleutradeMarket : bleutradeMarkets) {
        CurrencyPair currencyPair = CurrencyPairDeserializer.getCurrencyPairFromString(bleutradeMarket.getMarketName());
        CurrencyPairMetaData marketMetaData = new CurrencyPairMetaData(txFee, bleutradeMarket.getMinTradeSize(), null, 8, null);
        marketMetaDataMap.put(currencyPair, marketMetaData);
    }
    return new ExchangeMetaData(marketMetaDataMap, currencyMetaDataMap, null, null, null);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BleutradeCurrency(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrency) BleutradeMarket(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarket) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) BleutradeCurrency(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrency) Currency(org.knowm.xchange.currency.Currency) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

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