org.knowm.xchange.dto.meta.CurrencyMetaData Java Examples

The following examples show how to use org.knowm.xchange.dto.meta.CurrencyMetaData. 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: HuobiAdapters.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
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 #2
Source File: BitfinexAdapters.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
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 #3
Source File: BitfinexAdapters.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
public static ExchangeMetaData adaptMetaData(
    BitfinexAccountFeesResponse accountFeesResponse, ExchangeMetaData metaData) {
  Map<Currency, CurrencyMetaData> currencies = metaData.getCurrencies();
  final Map<Currency, BigDecimal> withdrawFees = accountFeesResponse.getWithdraw();
  withdrawFees.forEach(
      (currency, withdrawalFee) -> {
        if (currencies.get(currency) == null) {
          CurrencyMetaData currencyMetaData = new CurrencyMetaData(0, withdrawalFee);
          currencies.put(currency, currencyMetaData);
        } else {
          final CurrencyMetaData oldMetaData = currencies.get(currency);
          CurrencyMetaData newMetaData =
              new CurrencyMetaData(oldMetaData.getScale(), withdrawalFee);
          currencies.put(currency, newMetaData);
        }
      });
  return metaData;
}
 
Example #4
Source File: XChangeMetadataIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCurrencyMetaData() throws Exception {

    try (CamelContext camelctx = new DefaultCamelContext()) {

        Assume.assumeTrue(checkAPIConnection());

        camelctx.addRoutes(createRouteBuilder());
        camelctx.start();

        ProducerTemplate template = camelctx.createProducerTemplate();
        CurrencyMetaData metadata = template.requestBody("direct:currencyMetaData", Currency.ETH, CurrencyMetaData.class);
        Assert.assertNotNull("CurrencyMetaData not null", metadata);

        metadata = template.requestBodyAndHeader("direct:currencyMetaData", null, HEADER_CURRENCY, Currency.ETH, CurrencyMetaData.class);
        Assert.assertNotNull("CurrencyMetaData not null", metadata);
    }
}
 
Example #5
Source File: ExchangeBuilder.java    From arbitrader with MIT License 5 votes vote down vote up
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 #6
Source File: BitmexAdapters.java    From zheshiyigeniubidexiangmu with MIT License 4 votes vote down vote up
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 #7
Source File: BinanceExchange.java    From zheshiyigeniubidexiangmu with MIT License 4 votes vote down vote up
@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);
  }
}