Merge branch 'master' of https://github.com/GENERALBYTESCOM/batm_public into digibyte
This commit is contained in:
commit
ea1edb1956
|
@ -29,6 +29,8 @@ dependencies {
|
|||
compile(group: 'com.github.mmazi', name: 'rescu', version: '1.9.1')
|
||||
compile(group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.0')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.2')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.2')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-core', version: '4.2.1')
|
||||
compile(group: 'com.google.guava', name: 'guava', version: '18.0')
|
||||
compile(group: 'com.google.zxing', name: 'core', version: '2.3.0')
|
||||
|
@ -65,4 +67,4 @@ publishing {
|
|||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.generalbytes.batm.server.extensions.extra.smartcash;
|
|||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash.SmartCashRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.wallets.smartcashd.SmartcashRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
|
@ -99,6 +100,12 @@ public class SmartcashExtension implements IExtension{
|
|||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate,preferedFiatCurrency);
|
||||
}else if ("smartapi".equalsIgnoreCase(exchangeType)) {
|
||||
String preferredFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new SmartCashRateSource(preferredFiatCurrency);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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
|
||||
* Foundation and appearing in the file GPL2.TXT included in the packaging of
|
||||
* this file. Please note that GPL2 Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL2 ("Copyleft").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class APIResponse {
|
||||
|
||||
public BigDecimal count;
|
||||
public Item[] items;
|
||||
public Last last;
|
||||
public String resource;
|
||||
public BigDecimal status;
|
||||
public BigDecimal execution;
|
||||
|
||||
public static class Item {
|
||||
public String updated;
|
||||
public Currency currencies;
|
||||
}
|
||||
|
||||
public static class Currency {
|
||||
public BigDecimal USD;
|
||||
public BigDecimal EUR;
|
||||
public BigDecimal CHF;
|
||||
public BigDecimal CAD;
|
||||
public BigDecimal AUD;
|
||||
public BigDecimal GBP;
|
||||
public BigDecimal BRL;
|
||||
public BigDecimal VEF;
|
||||
public BigDecimal SGD;
|
||||
public BigDecimal KRW;
|
||||
public BigDecimal JPY;
|
||||
}
|
||||
|
||||
public class Last {
|
||||
public String id;
|
||||
public String created;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice(String fiatCurrency) {
|
||||
|
||||
BigDecimal price = null;
|
||||
|
||||
try {
|
||||
Field field = this.items[0].currencies.getClass().getDeclaredField(fiatCurrency);
|
||||
field.setAccessible(true);
|
||||
price = (BigDecimal)field.get(this.items[0].currencies);
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
return price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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
|
||||
* Foundation and appearing in the file GPL2.TXT included in the packaging of
|
||||
* this file. Please note that GPL2 Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL2 ("Copyleft").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/v1/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface ISmartCashAPI {
|
||||
|
||||
@GET
|
||||
@Path("exchange/currencies?limit=2")
|
||||
public APIResponse returnResponse();
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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
|
||||
* Foundation and appearing in the file GPL2.TXT included in the packaging of
|
||||
* this file. Please note that GPL2 Section 2[b] requires that all works based
|
||||
* on this software must also be made publicly available under the terms of
|
||||
* the GPL2 ("Copyleft").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import si.mazi.rescu.ClientConfig;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
import si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory;
|
||||
import si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SmartCashRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(SmartCashRateSource.class);
|
||||
|
||||
private String preferedFiatCurrency;
|
||||
private ISmartCashAPI api;
|
||||
|
||||
private static HashMap<String,BigDecimal> rateAmounts = new HashMap<String, BigDecimal>();
|
||||
private static HashMap<String,Long> rateTimes = new HashMap<String, Long>();
|
||||
private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec
|
||||
|
||||
public SmartCashRateSource(String preferedFiatCurrency) {
|
||||
|
||||
if (!getFiatCurrencies().contains(preferedFiatCurrency)) {
|
||||
preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
|
||||
this.preferedFiatCurrency = preferedFiatCurrency;
|
||||
|
||||
api = RestProxyFactory.createProxy(ISmartCashAPI.class, "https://api.smartcash.cc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> fiatCurrencies = new HashSet<String>();
|
||||
|
||||
Field[] fields = APIResponse.Currency.class.getFields();
|
||||
|
||||
for (Field f : fields) {
|
||||
fiatCurrencies.add(f.getName());
|
||||
}
|
||||
|
||||
return fiatCurrencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return this.preferedFiatCurrency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.SMART);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
|
||||
String key = cryptoCurrency +"_" + fiatCurrency;
|
||||
synchronized (rateAmounts) {
|
||||
long now = System.currentTimeMillis();
|
||||
BigDecimal amount = rateAmounts.get(key);
|
||||
if (amount == null) {
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called smartcash exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}else {
|
||||
Long expirationTime = rateTimes.get(key);
|
||||
if (expirationTime > now) {
|
||||
return rateAmounts.get(key);
|
||||
}else{
|
||||
//do the job;
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called smartcash exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal getExchangeRateLastSync(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!Currencies.SMART.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return null; //unsupported currency
|
||||
}
|
||||
APIResponse response = api.returnResponse();
|
||||
|
||||
if (response != null) {
|
||||
return response.getPrice(fiatCurrency);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -347,6 +347,10 @@
|
|||
<param name="price" />
|
||||
<cryptocurrency>SMART</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="smartapi" name ="SmartCash API" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>SMART</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="SMART" file="smart.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.startcoin.StartcoinExtension" >
|
||||
|
@ -452,6 +456,6 @@
|
|||
<cryptocurrency>BTX</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="BTX" file="btx.png"/>
|
||||
</extension>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.watchlists.BasicWatchlistsExtension" />
|
||||
</extensions>
|
||||
|
|
Loading…
Reference in New Issue