Itbit fixes
This commit is contained in:
parent
aaf3f5bad3
commit
e9ce03cad5
|
@ -53,13 +53,13 @@ public class BitcoinExtension implements IExtension{
|
||||||
} else if ("itbit".equalsIgnoreCase(prefix)) {
|
} else if ("itbit".equalsIgnoreCase(prefix)) {
|
||||||
String preferredFiatCurrency = ICurrencies.USD;
|
String preferredFiatCurrency = ICurrencies.USD;
|
||||||
String userId = paramTokenizer.nextToken();
|
String userId = paramTokenizer.nextToken();
|
||||||
String walletId = paramTokenizer.nextToken();
|
String accountId = paramTokenizer.nextToken();
|
||||||
String clientKey = paramTokenizer.nextToken();
|
String clientKey = paramTokenizer.nextToken();
|
||||||
String clientSecret = paramTokenizer.nextToken();
|
String clientSecret = paramTokenizer.nextToken();
|
||||||
if (paramTokenizer.hasMoreTokens()) {
|
if (paramTokenizer.hasMoreTokens()) {
|
||||||
preferredFiatCurrency = paramTokenizer.nextToken().toUpperCase();
|
preferredFiatCurrency = paramTokenizer.nextToken().toUpperCase();
|
||||||
}
|
}
|
||||||
return new ItBitExchange(userId, walletId, clientKey, clientSecret, preferredFiatCurrency);
|
return new ItBitExchange(userId, accountId, clientKey, clientSecret, preferredFiatCurrency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -32,6 +32,8 @@ import org.knowm.xchange.ExchangeSpecification;
|
||||||
import org.knowm.xchange.currency.Currency;
|
import org.knowm.xchange.currency.Currency;
|
||||||
import org.knowm.xchange.currency.CurrencyPair;
|
import org.knowm.xchange.currency.CurrencyPair;
|
||||||
import org.knowm.xchange.dto.Order;
|
import org.knowm.xchange.dto.Order;
|
||||||
|
import org.knowm.xchange.dto.account.AccountInfo;
|
||||||
|
import org.knowm.xchange.dto.account.Wallet;
|
||||||
import org.knowm.xchange.dto.marketdata.OrderBook;
|
import org.knowm.xchange.dto.marketdata.OrderBook;
|
||||||
import org.knowm.xchange.dto.marketdata.Ticker;
|
import org.knowm.xchange.dto.marketdata.Ticker;
|
||||||
import org.knowm.xchange.dto.trade.LimitOrder;
|
import org.knowm.xchange.dto.trade.LimitOrder;
|
||||||
|
@ -74,7 +76,6 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
||||||
private final Logger log;
|
private final Logger log;
|
||||||
private final RateLimiter rateLimiter;
|
private final RateLimiter rateLimiter;
|
||||||
|
|
||||||
|
|
||||||
public XChangeExchange(ExchangeSpecification specification, String preferredFiatCurrency) {
|
public XChangeExchange(ExchangeSpecification specification, String preferredFiatCurrency) {
|
||||||
exchange = ExchangeFactory.INSTANCE.createExchange(specification);
|
exchange = ExchangeFactory.INSTANCE.createExchange(specification);
|
||||||
name = exchange.getExchangeSpecification().getExchangeName();
|
name = exchange.getExchangeSpecification().getExchangeName();
|
||||||
|
@ -159,10 +160,9 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
BigDecimal balance = exchange.getAccountService()
|
AccountInfo accountInfo = exchange.getAccountService().getAccountInfo();
|
||||||
.getAccountInfo()
|
Wallet wallet = getWallet(accountInfo, cryptoCurrency);
|
||||||
.getWallet(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency))
|
BigDecimal balance = wallet.getBalance(Currency.getInstance(cryptoCurrency)).getAvailable();
|
||||||
.getBalance(Currency.getInstance(cryptoCurrency)).getAvailable();
|
|
||||||
log.debug("{} exchange balance request: {} = {}", name, cryptoCurrency, balance);
|
log.debug("{} exchange balance request: {} = {}", name, cryptoCurrency, balance);
|
||||||
return balance;
|
return balance;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -178,10 +178,9 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
BigDecimal balance = exchange.getAccountService()
|
AccountInfo accountInfo = exchange.getAccountService().getAccountInfo();
|
||||||
.getAccountInfo()
|
Wallet wallet = getWallet(accountInfo, fiatCurrency);
|
||||||
.getWallet(fiatCurrency)
|
BigDecimal balance = wallet.getBalance(Currency.getInstance(fiatCurrency)).getAvailable();
|
||||||
.getBalance(Currency.getInstance(fiatCurrency)).getAvailable();
|
|
||||||
log.debug("{} exchange balance request: {} = {}", name, fiatCurrency, balance);
|
log.debug("{} exchange balance request: {} = {}", name, fiatCurrency, balance);
|
||||||
return balance;
|
return balance;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -191,6 +190,10 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Wallet getWallet(AccountInfo accountInfo, String currency) {
|
||||||
|
return accountInfo.getWallet(translateCryptoCurrencySymbolToExchangeSpecificSymbol(currency));
|
||||||
|
}
|
||||||
|
|
||||||
public final String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
|
public final String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
|
||||||
if (!isCryptoCurrencySupported(cryptoCurrency)){
|
if (!isCryptoCurrencySupported(cryptoCurrency)){
|
||||||
return null;
|
return null;
|
||||||
|
@ -280,7 +283,7 @@ public abstract class XChangeExchange implements IExchangeAdvanced, IRateSourceA
|
||||||
return orderId;
|
return orderId;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(String.format("{} exchange purchase coins failed", name), e);
|
log.error(String.format("%s exchange purchase coins failed", name), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,23 @@ package com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.itbit;
|
||||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||||
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.XChangeExchange;
|
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.XChangeExchange;
|
||||||
import org.knowm.xchange.ExchangeSpecification;
|
import org.knowm.xchange.ExchangeSpecification;
|
||||||
|
import org.knowm.xchange.dto.account.AccountInfo;
|
||||||
|
import org.knowm.xchange.dto.account.Wallet;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ItBitExchange extends XChangeExchange {
|
public class ItBitExchange extends XChangeExchange {
|
||||||
|
|
||||||
|
private String accountId;
|
||||||
|
|
||||||
public ItBitExchange(String preferredFiatCurrency) {
|
public ItBitExchange(String preferredFiatCurrency) {
|
||||||
super(getDefaultSpecification(), preferredFiatCurrency);
|
super(getDefaultSpecification(), preferredFiatCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItBitExchange(String userId, String walletId, String clientKey, String clientSecret, String preferredFiatCurrency) {
|
public ItBitExchange(String userId, String accountId, String clientKey, String clientSecret, String preferredFiatCurrency) {
|
||||||
super(getSpecification(userId, walletId, clientKey, clientSecret), preferredFiatCurrency);
|
super(getSpecification(userId, accountId, clientKey, clientSecret), preferredFiatCurrency);
|
||||||
|
this.accountId = accountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,10 +47,10 @@ public class ItBitExchange extends XChangeExchange {
|
||||||
return new org.knowm.xchange.itbit.v1.ItBitExchange().getDefaultExchangeSpecification();
|
return new org.knowm.xchange.itbit.v1.ItBitExchange().getDefaultExchangeSpecification();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExchangeSpecification getSpecification(String userId, String walletId, String clientKey, String clientSecret) {
|
private static ExchangeSpecification getSpecification(String userId, String accountId, String clientKey, String clientSecret) {
|
||||||
ExchangeSpecification spec = getDefaultSpecification();
|
ExchangeSpecification spec = getDefaultSpecification();
|
||||||
spec.setExchangeSpecificParametersItem("userId", userId);
|
spec.setExchangeSpecificParametersItem("userId", userId);
|
||||||
spec.setExchangeSpecificParametersItem("walletId", walletId);
|
spec.setExchangeSpecificParametersItem("walletId", accountId);
|
||||||
spec.setApiKey(clientKey);
|
spec.setApiKey(clientKey);
|
||||||
spec.setSecretKey(clientSecret);
|
spec.setSecretKey(clientSecret);
|
||||||
return spec;
|
return spec;
|
||||||
|
@ -53,14 +58,14 @@ public class ItBitExchange extends XChangeExchange {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getCryptoCurrencies() {
|
public Set<String> getCryptoCurrencies() {
|
||||||
Set<String> cryptoCurrencies = new HashSet<String>();
|
Set<String> cryptoCurrencies = new HashSet<>();
|
||||||
cryptoCurrencies.add(ICurrencies.BTC);
|
cryptoCurrencies.add(ICurrencies.BTC);
|
||||||
return cryptoCurrencies;
|
return cryptoCurrencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getFiatCurrencies() {
|
public Set<String> getFiatCurrencies() {
|
||||||
Set<String> fiatCurrencies = new HashSet<String>();
|
Set<String> fiatCurrencies = new HashSet<>();
|
||||||
fiatCurrencies.add(ICurrencies.USD);
|
fiatCurrencies.add(ICurrencies.USD);
|
||||||
fiatCurrencies.add(ICurrencies.EUR);
|
fiatCurrencies.add(ICurrencies.EUR);
|
||||||
fiatCurrencies.add(ICurrencies.SGD);
|
fiatCurrencies.add(ICurrencies.SGD);
|
||||||
|
@ -77,6 +82,11 @@ public class ItBitExchange extends XChangeExchange {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Wallet getWallet(AccountInfo accountInfo, String fiatCurrency) {
|
||||||
|
return accountInfo.getWallet(accountId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String translateCryptoCurrencySymbolToExchangeSpecificSymbol(String from) {
|
protected String translateCryptoCurrencySymbolToExchangeSpecificSymbol(String from) {
|
||||||
if (ICurrencies.BTC.equalsIgnoreCase(from)) {
|
if (ICurrencies.BTC.equalsIgnoreCase(from)) {
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
</exchange>
|
</exchange>
|
||||||
<exchange prefix="itbit" name="itBit.com Exchange">
|
<exchange prefix="itbit" name="itBit.com Exchange">
|
||||||
<param name="userId" />
|
<param name="userId" />
|
||||||
<param name="walletId" />
|
<param name="accountId" />
|
||||||
<param name="apikey" />
|
<param name="apikey" />
|
||||||
<param name="apisecret" />
|
<param name="apisecret" />
|
||||||
<param name="fiatcurrency" />
|
<param name="fiatcurrency" />
|
||||||
|
@ -289,23 +289,6 @@
|
||||||
</ratesource>
|
</ratesource>
|
||||||
<cryptologo cryptocurrency="NXT" file="nxt.png"/>
|
<cryptologo cryptocurrency="NXT" file="nxt.png"/>
|
||||||
</extension>
|
</extension>
|
||||||
<extension class="com.generalbytes.batm.server.extensions.extra.potcoin.PotcoinExtension" >
|
|
||||||
<wallet prefix="potwallet" name="PotCoin">
|
|
||||||
<param name="publicKey" />
|
|
||||||
<param name="privateKey" />
|
|
||||||
<param name="walletId" />
|
|
||||||
<cryptocurrency>POT</cryptocurrency>
|
|
||||||
</wallet>
|
|
||||||
<ratesource prefix="potfix" name ="Fix Price" >
|
|
||||||
<param name="price" />
|
|
||||||
<cryptocurrency>POT</cryptocurrency>
|
|
||||||
</ratesource>
|
|
||||||
<ratesource prefix="coinmarketcap" name ="coinmarketcap.com" >
|
|
||||||
<param name="fiatcurrency" />
|
|
||||||
<cryptocurrency>POT</cryptocurrency>
|
|
||||||
</ratesource>
|
|
||||||
<cryptologo cryptocurrency="POT" file="pot.png"/>
|
|
||||||
</extension>
|
|
||||||
<extension class="com.generalbytes.batm.server.extensions.extra.dexacoin.DexCoinSupport">
|
<extension class="com.generalbytes.batm.server.extensions.extra.dexacoin.DexCoinSupport">
|
||||||
<ratesource prefix="dex_fix" name ="Fix Price" >
|
<ratesource prefix="dex_fix" name ="Fix Price" >
|
||||||
<param name="price" />
|
<param name="price" />
|
||||||
|
|
Loading…
Reference in New Issue