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