org.knowm.xchange.dto.meta.CurrencyPairMetaData Java Examples
The following examples show how to use
org.knowm.xchange.dto.meta.CurrencyPairMetaData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BitmexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
private static CurrencyPairMetaData adaptPair( BitmexTicker ticker, CurrencyPairMetaData OriginalMeta) { if (OriginalMeta != null) { return new CurrencyPairMetaData( ticker.getTakerFee(), OriginalMeta.getMinimumAmount(), OriginalMeta.getMaximumAmount(), Math.max(0, ticker.getTickSize().stripTrailingZeros().scale())); } else { return new CurrencyPairMetaData( ticker.getTakerFee(), null, null, Math.max(0, ticker.getTickSize().stripTrailingZeros().scale())); } }
Example #2
Source File: HuobiAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
static ExchangeMetaData adaptToExchangeMetaData( HuobiAssetPair[] assetPairs, HuobiAsset[] assets, ExchangeMetaData staticMetaData) { HuobiUtils.setHuobiAssets(assets); HuobiUtils.setHuobiAssetPairs(assetPairs); Map<CurrencyPair, CurrencyPairMetaData> pairsMetaData = staticMetaData.getCurrencyPairs(); Map<CurrencyPair, CurrencyPairMetaData> pairs = new HashMap<>(); for (HuobiAssetPair assetPair : assetPairs) { CurrencyPair pair = adaptCurrencyPair(assetPair.getKey()); pairs.put(pair, adaptPair(assetPair, pairsMetaData.getOrDefault(pair, null))); } Map<Currency, CurrencyMetaData> currenciesMetaData = staticMetaData.getCurrencies(); Map<Currency, CurrencyMetaData> currencies = new HashMap<>(); for (HuobiAsset asset : assets) { Currency currency = adaptCurrency(asset.getAsset()); CurrencyMetaData metadata = currenciesMetaData.getOrDefault(currency, null); BigDecimal withdrawalFee = metadata == null ? null : metadata.getWithdrawalFee(); int scale = metadata == null ? 8 : metadata.getScale(); currencies.put(currency, new CurrencyMetaData(scale, withdrawalFee)); } return new ExchangeMetaData(pairs, currencies, null, null, false); }
Example #3
Source File: BitfinexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
public static ExchangeMetaData adaptMetaData( List<CurrencyPair> currencyPairs, ExchangeMetaData metaData) { Map<CurrencyPair, CurrencyPairMetaData> pairsMap = metaData.getCurrencyPairs(); Map<Currency, CurrencyMetaData> currenciesMap = metaData.getCurrencies(); for (CurrencyPair c : currencyPairs) { if (!pairsMap.containsKey(c)) { pairsMap.put(c, null); } if (!currenciesMap.containsKey(c.base)) { currenciesMap.put(c.base, null); } if (!currenciesMap.containsKey(c.counter)) { currenciesMap.put(c.counter, null); } } return metaData; }
Example #4
Source File: BaseExchangeService.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
protected final void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) { CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair()); if (metaData == null) { throw new IllegalArgumentException("Invalid CurrencyPair"); } BigDecimal originalAmount = order.getOriginalAmount(); if (originalAmount == null) { throw new IllegalArgumentException("Missing originalAmount"); } BigDecimal amount = originalAmount.stripTrailingZeros(); BigDecimal minimumAmount = metaData.getMinimumAmount(); if (minimumAmount != null) { if (amount.scale() > minimumAmount.scale()) { throw new IllegalArgumentException("Unsupported amount scale " + amount.scale()); } else if (amount.compareTo(minimumAmount) < 0) { throw new IllegalArgumentException("Order amount less than minimum"); } } }
Example #5
Source File: XChangeMetadataIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCurrencyPairMetaData() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); CurrencyPairMetaData metadata = template.requestBody("direct:currencyPairMetaData", CurrencyPair.EOS_ETH, CurrencyPairMetaData.class); Assert.assertNotNull("CurrencyPairMetaData not null", metadata); metadata = template.requestBodyAndHeader("direct:currencyPairMetaData", null, HEADER_CURRENCY_PAIR, CurrencyPair.EOS_ETH, CurrencyPairMetaData.class); Assert.assertNotNull("CurrencyPairMetaData not null", metadata); } }
Example #6
Source File: ExchangeBuilder.java From arbitrader with MIT License | 5 votes |
public ExchangeBuilder withExchangeMetaData() { CurrencyPairMetaData currencyPairMetaData = new CurrencyPairMetaData( new BigDecimal("0.0020"), new BigDecimal("0.0010"), new BigDecimal("1000.00000000"), BTC_SCALE, null, null); Map<CurrencyPair, CurrencyPairMetaData> currencyPairMetaDataMap = new HashMap<>(); currencyPairMetaDataMap.put(currencyPair, currencyPairMetaData); CurrencyMetaData baseMetaData = new CurrencyMetaData(BTC_SCALE, BigDecimal.ZERO); CurrencyMetaData counterMetaData = new CurrencyMetaData(USD_SCALE, BigDecimal.ZERO); Map<Currency, CurrencyMetaData> currencyMetaDataMap = new HashMap<>(); currencyMetaDataMap.put(currencyPair.base, baseMetaData); currencyMetaDataMap.put(currencyPair.counter, counterMetaData); exchangeMetaData = new ExchangeMetaData( currencyPairMetaDataMap, currencyMetaDataMap, null, null, null ); return this; }
Example #7
Source File: BiboxAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static ExchangeMetaData adaptMetadata(List<BiboxMarket> markets) { Map<CurrencyPair, CurrencyPairMetaData> pairMeta = new HashMap<>(); for (BiboxMarket biboxMarket : markets) { pairMeta.put( new CurrencyPair(biboxMarket.getCoinSymbol(), biboxMarket.getCurrencySymbol()), new CurrencyPairMetaData(null, null, null, null)); } return new ExchangeMetaData(pairMeta, null, null, null, null); }
Example #8
Source File: HuobiAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
private static CurrencyPairMetaData adaptPair( HuobiAssetPair pair, CurrencyPairMetaData metadata) { BigDecimal minQty = metadata == null ? null : metadata.getMinimumAmount(); return new CurrencyPairMetaData( fee, minQty, // Min amount null, // Max amount new Integer(pair.getPricePrecision()) // Price scale ); }
Example #9
Source File: BitfinexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static ExchangeMetaData adaptMetaData( BitfinexAccountInfosResponse[] bitfinexAccountInfos, ExchangeMetaData exchangeMetaData) { final Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs(); // lets go with the assumption that the trading fees are common across all trading pairs for // now. // also setting the taker_fee as the trading_fee for now. final CurrencyPairMetaData metaData = new CurrencyPairMetaData(bitfinexAccountInfos[0].getTakerFees(), null, null, null); currencyPairs .keySet() .parallelStream() .forEach( currencyPair -> currencyPairs.merge( currencyPair, metaData, (oldMetaData, newMetaData) -> new CurrencyPairMetaData( newMetaData.getTradingFee(), oldMetaData.getMinimumAmount(), oldMetaData.getMaximumAmount(), oldMetaData.getPriceScale()))); return exchangeMetaData; }
Example #10
Source File: BitmexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 4 votes |
public static ExchangeMetaData adaptToExchangeMetaData( ExchangeMetaData originalMetaData, List<BitmexTicker> tickers, BiMap<BitmexPrompt, String> contracts) { // So we will create 3 maps. // A pairs map ( "ETC/BTC" -> price_scale:, min_amount:) // A currencies map : "BTC"->"scale": 5,"withdrawal_fee": 0.001 // A bitmexContracts Map XMRZ17->XMR.BTC.MONTHLY Map<CurrencyPair, CurrencyPairMetaData> pairs = new HashMap<>(); Map<Currency, CurrencyMetaData> currencies = new HashMap<>(); BitmexUtils.setBitmexAssetPairs(tickers); pairs.putAll(originalMetaData.getCurrencyPairs()); currencies.putAll(originalMetaData.getCurrencies()); for (BitmexTicker ticker : tickers) { String quote = ticker.getQuoteCurrency(); String base = ticker.getRootSymbol(); Currency baseCurrencyCode = BitmexAdapters.adaptCurrency(base); Currency quoteCurrencyCode = BitmexAdapters.adaptCurrency(quote); CurrencyPair pair = new CurrencyPair(baseCurrencyCode, quoteCurrencyCode); pairs.put(pair, adaptPair(ticker, pairs.get(adaptCurrencyPair(pair.toString())))); if (!BitmexUtils.bitmexCurrencies.containsKey(baseCurrencyCode) && !BitmexUtils.bitmexCurrencies.containsValue(base)) BitmexUtils.bitmexCurrencies.put(baseCurrencyCode, base); if (!BitmexUtils.bitmexCurrencies.containsKey(quoteCurrencyCode) && !BitmexUtils.bitmexCurrencies.containsValue(quote)) BitmexUtils.bitmexCurrencies.put(quoteCurrencyCode, quote); int scale = Math.max(0, ticker.getTickSize().stripTrailingZeros().scale()); BigDecimal baseWithdrawalFee = originalMetaData.getCurrencies().get(baseCurrencyCode) == null ? null : originalMetaData.getCurrencies().get(baseCurrencyCode).getWithdrawalFee(); BigDecimal quoteWithdrawalFee = originalMetaData.getCurrencies().get(quoteCurrencyCode) == null ? null : originalMetaData.getCurrencies().get(quoteCurrencyCode).getWithdrawalFee(); currencies.put(baseCurrencyCode, new CurrencyMetaData(scale, baseWithdrawalFee)); currencies.put(quoteCurrencyCode, new CurrencyMetaData(scale, quoteWithdrawalFee)); BitmexPrompt prompt = contracts.inverse().get(ticker.getSymbol().replaceFirst(ticker.getRootSymbol(), "")) != null ? contracts.inverse().get(ticker.getSymbol().replaceFirst(ticker.getRootSymbol(), "")) : BitmexPrompt.PERPETUAL; BitmexContract contract = new BitmexContract(pair, prompt); if (!BitmexUtils.bitmexContracts.containsKey(ticker.getSymbol()) && !BitmexUtils.bitmexContracts.containsValue(contract)) BitmexUtils.bitmexContracts.put(ticker.getSymbol(), contract); } return new ExchangeMetaData( pairs, currencies, originalMetaData == null ? null : originalMetaData.getPublicRateLimits(), originalMetaData == null ? null : originalMetaData.getPrivateRateLimits(), originalMetaData == null ? null : originalMetaData.isShareRateLimits()); }
Example #11
Source File: BinanceExchange.java From zheshiyigeniubidexiangmu with MIT License | 4 votes |
@Override public void remoteInit() { try { // 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(); BinanceMarketDataService marketDataService = (BinanceMarketDataService) this.marketDataService; exchangeInfo = marketDataService.getExchangeInfo(); Symbol[] symbols = exchangeInfo.getSymbols(); for (BinancePrice price : marketDataService.tickerAllPrices()) { CurrencyPair pair = price.getCurrencyPair(); for (Symbol symbol : symbols) { if (symbol .getSymbol() .equals(pair.base.getCurrencyCode() + pair.counter.getCurrencyCode())) { int basePrecision = Integer.parseInt(symbol.getBaseAssetPrecision()); int counterPrecision = Integer.parseInt(symbol.getQuotePrecision()); int pairPrecision = 8; int amountPrecision = 8; BigDecimal minQty = null; BigDecimal maxQty = null; Filter[] filters = symbol.getFilters(); for (Filter filter : filters) { if (filter.getFilterType().equals("PRICE_FILTER")) { pairPrecision = Math.min(pairPrecision, numberOfDecimals(filter.getMinPrice())); } else if (filter.getFilterType().equals("LOT_SIZE")) { amountPrecision = Math.min(amountPrecision, numberOfDecimals(filter.getMinQty())); minQty = new BigDecimal(filter.getMinQty()).stripTrailingZeros(); maxQty = new BigDecimal(filter.getMaxQty()).stripTrailingZeros(); } } currencyPairs.put( price.getCurrencyPair(), new CurrencyPairMetaData( new BigDecimal("0.1"), // Trading fee at Binance is 0.1 % minQty, // Min amount maxQty, // Max amount pairPrecision // precision )); currencies.put( pair.base, new CurrencyMetaData( basePrecision, currencies.containsKey(pair.base) ? currencies.get(pair.base).getWithdrawalFee() : null)); currencies.put( pair.counter, new CurrencyMetaData( counterPrecision, currencies.containsKey(pair.counter) ? currencies.get(pair.counter).getWithdrawalFee() : null)); } } } } catch (Exception e) { throw new ExchangeException("Failed to initialize: " + e.getMessage(), e); } }