Skip to content

Commit

Permalink
coinmate - basic ticker working
Browse files Browse the repository at this point in the history
  • Loading branch information
stachon committed Apr 5, 2015
1 parent d451e74 commit 30ffae9
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.xeiam.xchange.BaseExchange;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeSpecification;
import com.xeiam.xchange.coinmate.service.polling.CoinmateMarketDataService;
import com.xeiam.xchange.utils.nonce.CurrentTimeNonceFactory;
import si.mazi.rescu.SynchronizedValueFactory;

Expand All @@ -19,14 +20,29 @@ public SynchronizedValueFactory<Long> getNonceFactory() {
return nonceFactory;
}

@Override
public void applySpecification(ExchangeSpecification exchangeSpecification) {

super.applySpecification(exchangeSpecification);

this.pollingMarketDataService = new CoinmateMarketDataService(this);
this.pollingAccountService = null;
this.pollingTradeService = null;

}



@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
exchangeSpecification.setSslUri("https://coinmate.io");
exchangeSpecification.setHost("coinmate.io");
exchangeSpecification.setPort(80);
exchangeSpecification.setExchangeName("CoinMate");
exchangeSpecification.setExchangeDescription("Bitcoin trading made simple.");

return exchangeSpecification;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.xeiam.xchange.coinmate;

import com.xeiam.xchange.currency.CurrencyPair;

/**
*
* @author Martin Stachon
*/
public class CoinmateUtils {

public static String getPair(CurrencyPair currencyPair) {

return currencyPair.baseSymbol.toUpperCase() + "_" + currencyPair.counterSymbol.toUpperCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.xeiam.xchange.coinmate.service.polling;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.service.polling.BasePollingExchangeService;
import com.xeiam.xchange.service.polling.BasePollingService;
import java.io.IOException;
import java.util.List;

/**
*
* @author Martin Stachon
*/
public class CoinmateBasePollingService extends BasePollingExchangeService implements BasePollingService {

public CoinmateBasePollingService(Exchange exchange) {
super(exchange);
}

@Override
public List<CurrencyPair> getExchangeSymbols() throws IOException {
return exchange.getMetaData().getCurrencyPairs();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

package com.xeiam.xchange.coinmate.service.polling;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.coinmate.CoinmateAdapters;
import com.xeiam.xchange.coinmate.CoinmateUtils;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.OrderBook;
import com.xeiam.xchange.dto.marketdata.Ticker;
import com.xeiam.xchange.dto.marketdata.Trades;
import com.xeiam.xchange.exceptions.ExchangeException;
import com.xeiam.xchange.exceptions.NotAvailableFromExchangeException;
import com.xeiam.xchange.exceptions.NotYetImplementedForExchangeException;
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
import java.io.IOException;

/**
*
* @author Martin Stachon
*/
public class CoinmateMarketDataService extends CoinmateMarketDataServiceRaw implements PollingMarketDataService {

public CoinmateMarketDataService(Exchange exchange) {
super(exchange);
}

@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {

return CoinmateAdapters.adaptTicker(getCoinmateTicker(CoinmateUtils.getPair(currencyPair)), currencyPair);
}

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public Trades getTrades(CurrencyPair currencyPair, Object... args) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.xeiam.xchange.coinmate.service.polling;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.coinmate.Coinmate;
import com.xeiam.xchange.coinmate.dto.marketdata.CoinmateTicker;
import java.io.IOException;
import si.mazi.rescu.RestProxyFactory;

/**
*
* @author Martin Stachon
*/
public class CoinmateMarketDataServiceRaw extends CoinmateBasePollingService {

private final Coinmate coinmate;

public CoinmateMarketDataServiceRaw(Exchange exchange) {
super(exchange);
this.coinmate = RestProxyFactory.createProxy(Coinmate.class, exchange.getExchangeSpecification().getSslUri());
}

public CoinmateTicker getCoinmateTicker(String currencyPair) throws IOException {

return coinmate.getTicker(currencyPair);
}

}
5 changes: 5 additions & 0 deletions xchange-coinmate/src/main/resources/coinmate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"currency_pairs":[
"BTC/USD"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.xeiam.xchange.coinmate.service.polling;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.coinmate.CoinmateExchange;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.Ticker;
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
import static org.fest.assertions.api.Assertions.assertThat;
import org.junit.Test;

/**
*
* @author Martin Stachon
*/
public class CoinmateBasePollingServiceTest {

@Test
public void tickerFetchTest() throws Exception {

Exchange exchange = ExchangeFactory.INSTANCE.createExchange(CoinmateExchange.class.getName());
PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
Ticker ticker = marketDataService.getTicker(new CurrencyPair("BTC", "USD"));
System.out.println(ticker.toString());
assertThat(ticker).isNotNull();
}
}

0 comments on commit 30ffae9

Please sign in to comment.