Skip to content

Frequently Asked Questions

Tim Molter edited this page Dec 15, 2019 · 7 revisions

What is the release cycle for XChange?

XChange is a unique project in that the exchanges (over 60 now) are in constant flux. API endpoints can change, the returned JSON can change, entire API versions are rewritten, currency pairs are added/removed, etc. It happens without fail, that within days of an XChange release, some important API change occurs making the released jar obsolete. The fixes will come in through a pull request on the develop branch, and the only way to integrate the fix into your project is to make your project depend on the latest SNAPSHOT jars. As a compromise between this constant break/fix cycle and having stable releases, XChange is released on a "request" based schedule, but no faster than once a month. Please open an issue if you need an official release and the SNAPSHOT jar isn't good enough.

I'm getting "Invalid nonce" error

Usually happens when running a different implementations of the client API with the same API key. Different implementations might use different nonce generation strategies. One client could generate higher nonce and after that another client could generate a lower value, but it must be always higher then any previous nonce for given API key. To fix the problem generate a new API key. If you want to use different implementations interchangeably, keep both keys and let each app use its own key. For more info about nonce generation see: https://github.com/timmolter/XChange/wiki/Design-Notes.

Where, if anywhere, are the http read timeouts configured?

See https://github.com/mmazi/rescu. "Rescu can be configured by adding a rescu.properties file in your classpath." For a Maven project, just put rescu.properties in your resources directory and rescu will pick up the configuration automatically.

How do I add my API Key and Secret Key to an ExchangeSpecification?

Usually, for public market data access, you do not need to add any secret API keys, and creating an ExchangeSpecification for access to the MarketDataService can be achieved as such:

// Use the factory to get Bitstamp exchange API using default settings
Exchange bitstamp = ExchangeFactory.INSTANCE.createExchange(BitstampExchange.class.getName());

// Interested in the public market data feed (no authentication)
MarketDataService marketDataService = bitstamp.getMarketDataService();

For accessing the TradeService and AccountService, creating the Exchange with secret API keys is necessary, and there are a few ways to accomplish this. Note that different exchanges may require different secret keys and/or other fields. Make sure to check out the xchange-examples module for specific example code.

Hardcoded Keys

ExchangeSpecification exSpec = new BitstampExchange().getDefaultExchangeSpecification();
exSpec.setUserName("34387");
exSpec.setApiKey("a4SDmpl9s6xWJS5fkKRT6yn41vXuY0AM");
exSpec.setSecretKey("sisJixU6Xd0d1yr6w02EHCb9UwYzTNuj");
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exSpec);

JSON File on Classpath

/**
 * Create a exchange using the keys provided in a bitcoinde/exchangeConfiguration.json file on the classpath.
 *
 * @return Create exchange or null if .json file was not on classpath.
 */
public static Exchange createExchangeFromJsonConfiguration() throws IOException {

  ExchangeSpecification exSpec = new ExchangeSpecification(BitcoindeExchange.class);
  ObjectMapper mapper = new ObjectMapper();
  InputStream is = ExchangeUtils.class.getClassLoader().getResourceAsStream("bitcoinde/exchangeConfiguration.json");
  if (is == null) {
    logger.warn("No bitcoinde/exchangeConfiguration.json file found. Returning null exchange.");
    return null;
  }
  try {
    ExchangeConfiguration conf = mapper.readValue(is, ExchangeConfiguration.class);
    logger.debug(conf.toString());

    if (conf.apiKey != null)
      exSpec.setApiKey(conf.apiKey);
    if (conf.secretKey != null)
      exSpec.setSecretKey(conf.secretKey);
  } catch (Exception e) {
    logger.warn("An exception occured while loading the bitcoinde/exchangeConfiguration.json file from the classpath. " + "Returning null exchange.", e);
    return null;
  }

  Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exSpec);
  exchange.remoteInit();
  return exchange;
}

}

Program Arguments

public static void main(String[] args) throws IOException {

    // API key with All Permissions.
    String publicKey = args[0];
    String privateKey = args[1];

    ExchangeSpecification spec = new ExchangeSpecification(BTCTradeExchange.class);
    spec.setApiKey(publicKey);
    spec.setSecretKey(privateKey);

    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(spec);
}