Itbit refactored to be more consistent with rest of BATM system
This commit is contained in:
parent
a5bdbdee07
commit
9cf4bc2186
|
@ -36,6 +36,7 @@ public interface ICurrencies {
|
|||
public static final String EUR = "EUR";
|
||||
public static final String GBP = "GBP";
|
||||
public static final String JPY = "JPY";
|
||||
public static final String SGD = "SGD";
|
||||
public static final String USD = "USD";
|
||||
public static final String XAF = "XAF";
|
||||
public static final String XAU = "XAU"; //gold
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<cryptocurrency>BTC</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="itbit" name ="itBit.com Exchange" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
</ratesource>
|
||||
<paymentprocessor prefix="bitcoinpay" name="BitcoinPay.com" >
|
||||
|
@ -39,7 +40,6 @@
|
|||
<param name="pin" />
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
</paymentprocessor>
|
||||
<!-- Bitfinex extension by Orillia BVBA -->
|
||||
<exchange prefix="bitfinex" name="Bitfinex.com Exchange">
|
||||
<param name="apikey" />
|
||||
<param name="apisecret" />
|
||||
|
@ -50,6 +50,7 @@
|
|||
<param name="walletId" />
|
||||
<param name="apikey" />
|
||||
<param name="apisecret" />
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
</exchange>
|
||||
<cryptologo cryptocurrency="BTC" file="btc.png"/>
|
||||
|
|
|
@ -49,11 +49,15 @@ public class BitcoinExtension implements IExtension{
|
|||
String apiSecret = paramTokenizer.nextToken();
|
||||
return new BitfinexExchange(apiKey, apiSecret);
|
||||
} else if ("itbit".equalsIgnoreCase(prefix)) {
|
||||
String preferredFiatCurrency = ICurrencies.USD;
|
||||
String userId = paramTokenizer.nextToken();
|
||||
String walletId = paramTokenizer.nextToken();
|
||||
String clientKey = paramTokenizer.nextToken();
|
||||
String clientSecret = paramTokenizer.nextToken();
|
||||
return new ItBitExchange(userId, walletId, clientKey, clientSecret);
|
||||
if (paramTokenizer.hasMoreTokens()) {
|
||||
preferredFiatCurrency = paramTokenizer.nextToken();
|
||||
}
|
||||
return new ItBitExchange(userId, walletId, clientKey, clientSecret, preferredFiatCurrency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -138,7 +142,7 @@ public class BitcoinExtension implements IExtension{
|
|||
return new BitcoinAverageRateSource(ICurrencies.USD);
|
||||
}else if ("btcfix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
String preferedFiatCurrency = ICurrencies.USD;
|
||||
String preferredFiatCurrency = ICurrencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
|
@ -146,13 +150,17 @@ public class BitcoinExtension implements IExtension{
|
|||
}
|
||||
}
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken();
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new FixPriceRateSource(rate,preferedFiatCurrency);
|
||||
return new FixPriceRateSource(rate,preferredFiatCurrency);
|
||||
}else if ("bitfinex".equalsIgnoreCase(exchangeType)) {
|
||||
return new BitfinexExchange("**","**");
|
||||
}else if ("itbit".equalsIgnoreCase(exchangeType)) {
|
||||
return new ItBitExchange();
|
||||
String preferredFiatCurrency = ICurrencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new ItBitExchange(preferredFiatCurrency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************************
|
||||
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
|
||||
* Copyright (C) 2015 GENERAL BYTES s.r.o. All rights reserved.
|
||||
* <p/>
|
||||
* This software may be distributed and modified under the terms of the GNU
|
||||
* General Public License version 2 (GPL2) as published by the Free Software
|
||||
|
@ -16,10 +16,11 @@
|
|||
* <p/>
|
||||
* Other information:
|
||||
* <p/>
|
||||
* This implementation was created in cooperation with Orillia BVBA
|
||||
* This implementation was created in cooperation with Sumbits http://www.getsumbits.com/
|
||||
************************************************************************************/
|
||||
package com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IExchangeAdvanced;
|
||||
import com.generalbytes.batm.server.extensions.IRateSourceAdvanced;
|
||||
import com.generalbytes.batm.server.extensions.ITask;
|
||||
|
@ -36,6 +37,9 @@ import com.xeiam.xchange.dto.marketdata.Ticker;
|
|||
import com.xeiam.xchange.dto.trade.LimitOrder;
|
||||
import com.xeiam.xchange.dto.trade.MarketOrder;
|
||||
import com.xeiam.xchange.dto.trade.OpenOrders;
|
||||
import com.xeiam.xchange.exceptions.ExchangeException;
|
||||
import com.xeiam.xchange.exceptions.NotAvailableFromExchangeException;
|
||||
import com.xeiam.xchange.exceptions.NotYetImplementedForExchangeException;
|
||||
import com.xeiam.xchange.service.polling.account.PollingAccountService;
|
||||
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
|
||||
import com.xeiam.xchange.service.polling.trade.PollingTradeService;
|
||||
|
@ -53,8 +57,8 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceAdvanced {
|
||||
|
||||
private String preferredFiatCurrency;
|
||||
private static final long cacheRefreshSeconds = 30;
|
||||
private static final Cache<String, BigDecimal> balanceCache = createCache();
|
||||
private static final Cache<String, BigDecimal> rateCache = createCache();
|
||||
|
||||
private static Cache<String, BigDecimal> createCache() {
|
||||
|
@ -69,42 +73,67 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
private final Logger log;
|
||||
private final RateLimiter rateLimiter;
|
||||
|
||||
public XChangeExchange(ExchangeSpecification specification) {
|
||||
|
||||
public XChangeExchange(ExchangeSpecification specification, String preferredFiatCurrency) {
|
||||
exchange = ExchangeFactory.INSTANCE.createExchange(specification);
|
||||
name = exchange.getExchangeSpecification().getExchangeName();
|
||||
log = LoggerFactory.getLogger("batm.master." + name);
|
||||
log = LoggerFactory.getLogger("batm.master.exchange." + name);
|
||||
rateLimiter = RateLimiter.create(getAllowedCallsPerSecond());
|
||||
this.preferredFiatCurrency = preferredFiatCurrency;
|
||||
}
|
||||
|
||||
protected abstract boolean isWithdrawSuccessful(String result);
|
||||
protected abstract double getAllowedCallsPerSecond();
|
||||
|
||||
// exchanges that use non standard currency codes can override this
|
||||
protected String mapCurrency(String currency) {
|
||||
return currency;
|
||||
}
|
||||
|
||||
private String checkSupportedCrypto(String currency) {
|
||||
currency = mapCurrency(currency);
|
||||
private boolean isCryptoCurrencySupported(String currency) {
|
||||
if (!getCryptoCurrencies().contains(currency)) {
|
||||
log.debug("{} exchange doesn't support cryptocurrency '{}'", name, currency);
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
return currency;
|
||||
return true;
|
||||
}
|
||||
|
||||
private String checkSupportedFiat(String currency) {
|
||||
currency = mapCurrency(currency);
|
||||
if (!getCryptoCurrencies().contains(currency)) {
|
||||
private boolean isFiatCurrencySupported(String currency) {
|
||||
if (!getFiatCurrencies().contains(currency)) {
|
||||
log.debug("{} exchange doesn't support fiat currency '{}'", name, currency);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class RateCaller implements Callable<BigDecimal> {
|
||||
private final String key;
|
||||
|
||||
RateCaller(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal call() throws Exception {
|
||||
String[] keyParts = getCacheKeyParts(key);
|
||||
String cryptoCurrency = keyParts[0];
|
||||
String fiatCurrency = keyParts[1];
|
||||
|
||||
try {
|
||||
return exchange.getPollingMarketDataService()
|
||||
.getTicker(new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency))
|
||||
.getLast();
|
||||
} catch (ExchangeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotAvailableFromExchangeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotYetImplementedForExchangeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return currency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
String key = getKey(cryptoCurrency, fiatCurrency);
|
||||
String key = buildCacheKey(cryptoCurrency, fiatCurrency);
|
||||
try {
|
||||
BigDecimal result = rateCache.get(key, new RateCaller(key));
|
||||
log.debug("{} exchange rate request: {} = {}", name, key, result);
|
||||
|
@ -115,40 +144,54 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
}
|
||||
}
|
||||
|
||||
private String getKey(String cryptoCurrency, String fiatCurrency) {
|
||||
private static String buildCacheKey(String cryptoCurrency, String fiatCurrency) {
|
||||
return String.format("%s:%s", cryptoCurrency, fiatCurrency);
|
||||
}
|
||||
|
||||
private String[] getKeyParts(String key) {
|
||||
private static String[] getCacheKeyParts(String key) {
|
||||
return key.split(":");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
return cryptoCurrency == null ? BigDecimal.ZERO : getBalance(cryptoCurrency);
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
try {
|
||||
BigDecimal balance = exchange.getPollingAccountService()
|
||||
.getAccountInfo()
|
||||
.getWallet(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency))
|
||||
.getBalance();
|
||||
log.debug("{} exchange balance request: {} = {}", name, cryptoCurrency, balance);
|
||||
return balance;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("{} exchange balance request: {}", name, cryptoCurrency, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getFiatBalance(String fiatCurrency) {
|
||||
fiatCurrency = checkSupportedFiat(fiatCurrency);
|
||||
return fiatCurrency == null ? BigDecimal.ZERO : getBalance(fiatCurrency);
|
||||
if (!isFiatCurrencySupported(fiatCurrency)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private BigDecimal getBalance(String currency) {
|
||||
try {
|
||||
BigDecimal balance = balanceCache.get(currency, new BalanceCaller(currency));
|
||||
log.debug("{} exchange balance request: {} = {}", name, currency, balance);
|
||||
BigDecimal balance = exchange.getPollingAccountService()
|
||||
.getAccountInfo()
|
||||
.getWallet(fiatCurrency)
|
||||
.getBalance();
|
||||
log.debug("{} exchange balance request: {} = {}", name, fiatCurrency, balance);
|
||||
return balance;
|
||||
} catch (ExecutionException e) {
|
||||
log.error("{} exchange balance request: {}", name, currency, e);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("{} exchange balance request: {}", name, fiatCurrency, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
if (cryptoCurrency == null) {
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -156,7 +199,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
PollingAccountService accountService = exchange.getPollingAccountService();
|
||||
try {
|
||||
String result = accountService.withdrawFunds(cryptoCurrency, amount, destinationAddress);
|
||||
String result = accountService.withdrawFunds(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), amount, destinationAddress);
|
||||
if (isWithdrawSuccessful(result)) {
|
||||
log.debug("{} exchange withdrawal completed with result: {}", name, result);
|
||||
return "success";
|
||||
|
@ -170,11 +213,15 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
}
|
||||
|
||||
public String purchaseCoins(BigDecimal amount, String cryptoCurrency, String fiatCurrencyToUse, String description) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrencyToUse = checkSupportedFiat(fiatCurrencyToUse);
|
||||
if (cryptoCurrency == null || fiatCurrencyToUse == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isFiatCurrencySupported(fiatCurrencyToUse)) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)){
|
||||
return null;
|
||||
}
|
||||
|
||||
PollingAccountService accountService = exchange.getPollingAccountService();
|
||||
PollingMarketDataService marketService = exchange.getPollingMarketDataService();
|
||||
|
@ -183,7 +230,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
try {
|
||||
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());
|
||||
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrencyToUse);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
|
||||
|
||||
Ticker ticker = marketService.getTicker(currencyPair);
|
||||
|
||||
|
@ -191,7 +238,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
.limitPrice(ticker.getAsk())
|
||||
.tradableAmount(amount)
|
||||
.build();
|
||||
log.debug("marketOrder = {}", order);
|
||||
log.debug("limitOrder = {}", order);
|
||||
|
||||
String orderId = tradeService.placeLimitOrder(order);
|
||||
log.debug("orderId = {} {}", orderId, order);
|
||||
|
@ -239,24 +286,30 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
@Override
|
||||
public ITask createPurchaseCoinsTask(BigDecimal amount, String cryptoCurrency, String fiatCurrencyToUse, String description) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrencyToUse = checkSupportedFiat(fiatCurrencyToUse);
|
||||
if (cryptoCurrency == null || fiatCurrencyToUse == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
if (!isFiatCurrencySupported(fiatCurrencyToUse)) {
|
||||
return null;
|
||||
}
|
||||
return new PurchaseCoinsTask(amount, cryptoCurrency, fiatCurrencyToUse, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDepositAddress(String cryptoCurrency) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
if (cryptoCurrency == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PollingAccountService accountService = exchange.getPollingAccountService();
|
||||
try {
|
||||
return accountService.requestDepositAddress(cryptoCurrency);
|
||||
return accountService.requestDepositAddress(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -265,12 +318,18 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
@Override
|
||||
public String sellCoins(BigDecimal cryptoAmount, String cryptoCurrency, String fiatCurrencyToUse, String description) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrencyToUse = checkSupportedFiat(fiatCurrencyToUse);
|
||||
if (cryptoCurrency == null || fiatCurrencyToUse == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isFiatCurrencySupported(fiatCurrencyToUse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("Calling {} exchange (sell {} {})", name, cryptoAmount, cryptoCurrency);
|
||||
PollingAccountService accountService = exchange.getPollingAccountService();
|
||||
PollingTradeService tradeService = exchange.getPollingTradeService();
|
||||
|
@ -278,7 +337,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
try {
|
||||
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());
|
||||
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrencyToUse);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
|
||||
|
||||
MarketOrder order = new MarketOrder(OrderType.ASK, cryptoAmount, currencyPair);
|
||||
log.debug("marketOrder = {}", order);
|
||||
|
@ -329,11 +388,15 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
@Override
|
||||
public ITask createSellCoinsTask(BigDecimal amount, String cryptoCurrency, String fiatCurrencyToUse, String description) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrencyToUse = checkSupportedFiat(fiatCurrencyToUse);
|
||||
if (cryptoCurrency == null || fiatCurrencyToUse == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
if (!isFiatCurrencySupported(fiatCurrencyToUse)) {
|
||||
return null;
|
||||
}
|
||||
return new SellCoinsTask(amount, cryptoCurrency, fiatCurrencyToUse, description);
|
||||
}
|
||||
|
||||
|
@ -357,16 +420,20 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
@Override
|
||||
public BigDecimal calculateBuyPrice(String cryptoCurrency, String fiatCurrency, BigDecimal cryptoAmount) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrency = checkSupportedFiat(fiatCurrency);
|
||||
if (cryptoCurrency == null || fiatCurrency == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
if (!isFiatCurrencySupported(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
rateLimiter.acquire();
|
||||
PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
|
||||
try {
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrency);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency);
|
||||
OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
|
||||
List<LimitOrder> asks = orderBook.getAsks();
|
||||
BigDecimal targetAmount = cryptoAmount;
|
||||
|
@ -401,16 +468,20 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
@Override
|
||||
public BigDecimal calculateSellPrice(String cryptoCurrency, String fiatCurrency, BigDecimal cryptoAmount) {
|
||||
cryptoCurrency = checkSupportedCrypto(cryptoCurrency);
|
||||
fiatCurrency = checkSupportedFiat(fiatCurrency);
|
||||
if (cryptoCurrency == null || fiatCurrency == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isCryptoCurrencySupported(cryptoCurrency)){
|
||||
return null;
|
||||
}
|
||||
if(!isFiatCurrencySupported(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
rateLimiter.acquire();
|
||||
PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
|
||||
try {
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrency);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency);
|
||||
|
||||
OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
|
||||
List<LimitOrder> bids = orderBook.getBids();
|
||||
|
@ -445,38 +516,6 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
|
||||
}
|
||||
|
||||
class RateCaller implements Callable<BigDecimal> {
|
||||
private final String key;
|
||||
|
||||
RateCaller(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal call() throws Exception {
|
||||
String[] keyParts = getKeyParts(key);
|
||||
return exchange.getPollingMarketDataService()
|
||||
.getTicker(new CurrencyPair(keyParts[0], keyParts[1]))
|
||||
.getLast();
|
||||
}
|
||||
}
|
||||
|
||||
class BalanceCaller implements Callable<BigDecimal> {
|
||||
private final String currency;
|
||||
|
||||
BalanceCaller(String currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal call() throws Exception {
|
||||
return exchange.getPollingAccountService()
|
||||
.getAccountInfo()
|
||||
.getWallet(currency)
|
||||
.getBalance();
|
||||
}
|
||||
}
|
||||
|
||||
class PurchaseCoinsTask implements ITask {
|
||||
private long MAXIMUM_TIME_TO_WAIT_FOR_ORDER_TO_FINISH = 5 * 60 * 60 * 1000; //5 hours
|
||||
|
||||
|
@ -506,7 +545,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
try {
|
||||
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());
|
||||
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrencyToUse);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
|
||||
|
||||
Ticker ticker = marketService.getTicker(currencyPair);
|
||||
LimitOrder order = new LimitOrder.Builder(OrderType.BID, currencyPair)
|
||||
|
@ -632,7 +671,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
try {
|
||||
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());
|
||||
|
||||
CurrencyPair currencyPair = new CurrencyPair(cryptoCurrency, fiatCurrencyToUse);
|
||||
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
|
||||
|
||||
MarketOrder order = new MarketOrder(OrderType.ASK, cryptoAmount, currencyPair);
|
||||
log.debug("marketOrder = {}", order);
|
||||
|
@ -727,4 +766,12 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferredFiatCurrency;
|
||||
}
|
||||
|
||||
protected String translateCryptoCurrencySymbolToExchangeSpecificSymbol(String from) {
|
||||
return from;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************************
|
||||
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
|
||||
* Copyright (C) 2015 GENERAL BYTES s.r.o. All rights reserved.
|
||||
* <p/>
|
||||
* This software may be distributed and modified under the terms of the GNU
|
||||
* General Public License version 2 (GPL2) as published by the Free Software
|
||||
|
@ -16,20 +16,27 @@
|
|||
* <p/>
|
||||
* Other information:
|
||||
* <p/>
|
||||
* This implementation was created in cooperation with Orillia BVBA
|
||||
* This implementation was created in cooperation with Sumbits http://www.getsumbits.com/
|
||||
************************************************************************************/
|
||||
package com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.itbit;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IExchangeAdvanced;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.XChangeExchange;
|
||||
import com.xeiam.xchange.ExchangeSpecification;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItBitExchange extends XChangeExchange implements IExchangeAdvanced, IRateSource {
|
||||
public class ItBitExchange extends XChangeExchange {
|
||||
|
||||
public ItBitExchange(String preferredFiatCurrency) {
|
||||
super(getDefaultSpecification(), preferredFiatCurrency);
|
||||
}
|
||||
|
||||
public ItBitExchange(String userId, String walletId, String clientKey, String clientSecret, String preferredFiatCurrency) {
|
||||
super(getSpecification(userId, walletId, clientKey, clientSecret), preferredFiatCurrency);
|
||||
}
|
||||
|
||||
|
||||
private static ExchangeSpecification getDefaultSpecification() {
|
||||
return new com.xeiam.xchange.itbit.v1.ItBitExchange().getDefaultExchangeSpecification();
|
||||
|
@ -44,18 +51,10 @@ public class ItBitExchange extends XChangeExchange implements IExchangeAdvanced,
|
|||
return spec;
|
||||
}
|
||||
|
||||
public ItBitExchange() {
|
||||
super(getDefaultSpecification());
|
||||
}
|
||||
|
||||
public ItBitExchange(String userId, String walletId, String clientKey, String clientSecret) {
|
||||
super(getSpecification(userId, walletId, clientKey, clientSecret));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> cryptoCurrencies = new HashSet<String>();
|
||||
cryptoCurrencies.add(ICurrencies.XBT);
|
||||
cryptoCurrencies.add(ICurrencies.BTC);
|
||||
return cryptoCurrencies;
|
||||
}
|
||||
|
||||
|
@ -64,14 +63,10 @@ public class ItBitExchange extends XChangeExchange implements IExchangeAdvanced,
|
|||
Set<String> fiatCurrencies = new HashSet<String>();
|
||||
fiatCurrencies.add(ICurrencies.USD);
|
||||
fiatCurrencies.add(ICurrencies.EUR);
|
||||
fiatCurrencies.add(ICurrencies.SGD);
|
||||
return fiatCurrencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return ICurrencies.USD;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWithdrawSuccessful(String result) {
|
||||
return true;
|
||||
|
@ -83,7 +78,10 @@ public class ItBitExchange extends XChangeExchange implements IExchangeAdvanced,
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String mapCurrency(String currency) {
|
||||
return currency.equals(ICurrencies.BTC) ? ICurrencies.XBT : currency;
|
||||
protected String translateCryptoCurrencySymbolToExchangeSpecificSymbol(String from) {
|
||||
if (ICurrencies.BTC.equalsIgnoreCase(from)) {
|
||||
return "XBT";
|
||||
}
|
||||
return from;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue