<commit_before>package org.knowm.xchange.kraken;

import java.util.HashSet;
import java.util.Set;

import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.exceptions.ExchangeException;

/**
 * @author timmolter
 */
public class KrakenUtils {

  private static final Set<Currency> FIAT_CURRENCIES = new HashSet<>();
  private static final Set<Currency> DIGITAL_CURRENCIES = new HashSet<>();

  static {

    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("USD"));
    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("EUR"));
    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("JPY"));
    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("KRW"));
    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("GBP"));
    FIAT_CURRENCIES.add(KrakenAdapters.adaptCurrency("CAD"));

    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("BTC"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("DAO"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("ETH"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("LTC"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("NMC"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XBT"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XDG"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XLM"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XRP"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XVN"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("ETC"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("XMR"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("ZEC"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("REP"));
    DIGITAL_CURRENCIES.add(KrakenAdapters.adaptCurrency("BCH"));
  }

  /**
   * Private Constructor
   */
  private KrakenUtils() {

  }

  public static String createKrakenCurrencyPair(CurrencyPair currencyPair) {
    // DASH, GNO, EOS and BCH are strange exceptions for X and Z adds.
    String baseCurrencyCode = currencyPair.base.getCurrencyCode();
    if ("DASH".equals(baseCurrencyCode) || "GNO".equals(baseCurrencyCode) || "EOS".equals(baseCurrencyCode) || "BCH".equals(baseCurrencyCode)) {
      Currency counter = currencyPair.counter;
      if (counter.getIso4217Currency() != null) {
        counter = currencyPair.counter.getIso4217Currency();
      }
      return baseCurrencyCode + counter.getCurrencyCode();
    }
    return getKrakenCurrencyCode(currencyPair.base) + getKrakenCurrencyCode(currencyPair.counter);
  }

  public static String createKrakenCurrencyPair(Currency tradableIdentifier, Currency currency) {
      return createKrakenCurrencyPair(new CurrencyPair(tradableIdentifier, currency));
  }

  public static String getKrakenCurrencyCode(Currency currency) {

    String c = currency.getCurrencyCode();
    if ("USDT".equals(c) || "KFEE".equals(c) || "DASH".equals(c) || "GNO".equals(c) || "EOS".equals(c) || "BCH".equals(c)) {
      return c;
    }

    if (FIAT_CURRENCIES.contains(currency)) {
      return "Z" + currency;

    } else if (DIGITAL_CURRENCIES.contains(currency)) {

      if (currency.getIso4217Currency() != null) {
        currency = currency.getIso4217Currency();
      }
      return "X" + currency;
    }

    throw new ExchangeException("Kraken does not support the currency code " + currency);
  }

  public static Currency addCurrencyAndGetCode(String krakenCurrencyString) {

    Currency currencyCode = KrakenAdapters.adaptCurrency(krakenCurrencyString);
    if (krakenCurrencyString.startsWith("X")) {
      DIGITAL_CURRENCIES.add(currencyCode);
    } else {
      FIAT_CURRENCIES.add(currencyCode);
    }

    return currencyCode;
  }
}<commit_msg>Removed hardcoded pair translations<commit_after>package org.knowm.xchange.kraken;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.kraken.dto.marketdata.KrakenAsset;
import org.knowm.xchange.kraken.dto.marketdata.KrakenAssetPair;
import org.knowm.xchange.kraken.dto.marketdata.KrakenAssetPairs;
import org.knowm.xchange.kraken.dto.marketdata.KrakenAssets;

/**
 * @author timmolter
 */
public class KrakenUtils {

  private static Map<String, CurrencyPair> assetPairMap = new HashMap<String, CurrencyPair>();
  private static Map<CurrencyPair, String> assetPairMapReverse = new HashMap<CurrencyPair, String>();
  private static Map<String, Currency> assetsMap = new HashMap<String, Currency>();
  private static Map<Currency, String> assetsMapReverse = new HashMap<Currency, String>();
  
  

  /**
   * Private Constructor
   */
  private KrakenUtils() {

  }

  public static void setKrakenAssetPairs(  Map<String, KrakenAssetPair> pairs) 
  {
	  if (assetPairMap.isEmpty()) {
		  for (Map.Entry<String, KrakenAssetPair> entry : pairs.entrySet())
		  {   
			  //  skip dark markets!
			  if (!entry.getKey().endsWith(".d"))
              {
				  CurrencyPair pair = new CurrencyPair(translateKrakenCurrencyCode(entry.getValue().getBase()),translateKrakenCurrencyCode(entry.getValue().getQuote()));
				  assetPairMap.put(entry.getKey(), pair);
				  assetPairMapReverse.put(pair, entry.getKey());
			  }
		  }
	  }
  }

  public static void setKrakenAssets( Map<String, KrakenAsset> assetSource) 
  {
	  if (assetsMap.isEmpty()) {
		  for (Map.Entry<String, KrakenAsset> entry : assetSource.entrySet())
		  {
			  assetsMap.put(entry.getKey(), Currency.getInstance(entry.getValue().getAltName()));
			  assetsMapReverse.put(Currency.getInstance(entry.getValue().getAltName()), entry.getKey());
		  }
	  }
  }

  public static String createKrakenCurrencyPair(CurrencyPair currencyPair) {
	  return assetPairMapReverse.get(currencyPair);
  }
  
  public static CurrencyPair translateKrakenCurrencyPair(String currencyPairIn) {
	  return assetPairMap.get(currencyPairIn);
  }


  public static String createKrakenCurrencyPair(Currency tradableIdentifier, Currency currency) {
      return createKrakenCurrencyPair(new CurrencyPair(tradableIdentifier, currency));
  }

  public static String getKrakenCurrencyCode(Currency currency) 
  {
    if (currency.getIso4217Currency() != null) 
    {
  	  currency = currency.getIso4217Currency();
    }
    String krakenCode = assetsMapReverse.get(currency);
    if (krakenCode == null)
    {
    	throw new ExchangeException("Kraken does not support the currency code " + currency);
    }
    return krakenCode;
  }

  public static Currency translateKrakenCurrencyCode(String currencyIn) 
  {
	    Currency currencyOut = assetsMap.get(currencyIn);
	    if (currencyOut == null)
	    {
	    	throw new ExchangeException("Kraken does not support the currency code " + currencyIn);
	    }
	    return currencyOut.getCommonlyUsedCurrency();
  }
}
{'fraction_non_alphanumeric': 0.11704724974867155, 'fraction_numerical': 0.0034467901766479965, 'mean_word_length': 4.698854337152209, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2654766', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2310, 'n_words': 355}