Skip to content

How to Add an XChange

douggie edited this page Apr 1, 2018 · 2 revisions

The XchangeData class does all the work, but for each exchange available, three things need to be done:

  1. add a Maven <dependency> block to pom.xml
  2. add a singleton entry to Exchanges
  3. add a helper class for given exchange
  4. edit the cointrader.properties file
xchange.bitstamp.class=com.xeiam.xchange.bitstamp.BitstampExchange
xchange.bitstamp.helper.class=BitstampHelper
xchange.bitstamp.rate.queries=1
xchange.bitstamp.rate.period=2
xchange.bitstamp.listings=BTC.USD

period is specified in seconds, so in the above example we allow one query every 2 seconds. listings is comma-separated.

Some XChange adapters require the most recent trade id or datetime as a parameter, otherwise they report redundant data we've already recorded. If this is the case, you can create a delegate class helper

xchange.bitfinex.helper.class=BitfinexHelper

The helper class must reside in the module.xchange package and subclass XchangeDataHelperBase. It allows you to set the parameters passed to XChange's getTrades(currencyPair,params) and getBooks(currencyPair,params) commands. It also allows you to handle/manipulate the list of Trades or Books returned.

public class BitfinexHelper extends XchangeDataHelperBase
{
    /** Send the lastTradeTime in millis as the first parameter to getTrades() */
    public Object[] getTradesParameters( CurrencyPair pair, long lastTradeTime, long lastTradeId )
    {
        return new Object[] {lastTradeTime};
    }

    /** option to manipulate the incoming XChange data before it is processed by Coin Trader */
    public void handleTrades( Trades xchangeTrades ) { }
    public void handleOrderBook( OrderBook orderBook ) { }
}
Clone this wiki locally