diff --git a/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java b/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java index c29c592..f36a6cd 100644 --- a/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java +++ b/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java @@ -24,7 +24,7 @@ public interface ICurrencies { public static final String DOGE = "DOGE"; public static final String MAX = "MAX"; public static final String LEO = "LEO"; - public static final String LEO = "GLD"; + public static final String NLG = "NLG"; public static final String CZK = "CZK"; diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/GuldencoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/GuldencoinExtension.java index 761de13..8db3588 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/GuldencoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/GuldencoinExtension.java @@ -68,7 +68,7 @@ public class GuldencoinExtension implements IExtension{ @Override public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) { - if (ICurrencies.GLD.equalsIgnoreCase(cryptoCurrency)) { + if (ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency)) { return new GuldencoinAddressValidator(); } return null; @@ -102,7 +102,7 @@ public class GuldencoinExtension implements IExtension{ @Override public Set getSupportedCryptoCurrencies() { Set result = new HashSet(); - result.add(ICurrencies.GLD); + result.add(ICurrencies.NLG); return result; } diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/FixPriceRateSource.java index d135d45..6f74a43 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/FixPriceRateSource.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/FixPriceRateSource.java @@ -20,13 +20,13 @@ public class FixPriceRateSource implements IRateSource { @Override public Set getCryptoCurrencies() { Set result = new HashSet(); - result.add(ICurrencies.GLD); + result.add(ICurrencies.NLG); return result; } @Override public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { - if (ICurrencies.GLD.equalsIgnoreCase(cryptoCurrency)) { + if (ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency)) { return rate; } return null; @@ -35,7 +35,6 @@ public class FixPriceRateSource implements IRateSource { @Override public Set getFiatCurrencies() { Set result = new HashSet(); - result.add(ICurrencies.USD); result.add(ICurrencies.EUR); return result; } diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerRateSource.java new file mode 100644 index 0000000..2034cb7 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerRateSource.java @@ -0,0 +1,110 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * 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"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.guldencoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import si.mazi.rescu.RestProxyFactory; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +public class GuldencoinTickerRateSource implements IRateSource{ + private static final Logger log = LoggerFactory.getLogger(GuldencoinTickerRateSource.class); + + private static HashMap rateAmounts = new HashMap(); + private static HashMap rateTimes = new HashMap(); + private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec + + private IGuldencoinTickerRateAPI api; + + public GuldencoinTickerRateSource() { + api = RestProxyFactory.createProxy(IGuldencoinTickerRateAPI.class, "https://markets.guldencoin.com"); + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (!(ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency))) { + return null; + } + if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) { + return null; + } + + 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 GuldencoinTicker 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 GuldencoinTicker 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 (!(ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency))) { + return null; + } + if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) { + return null; + } + GuldencoinTickerResponse ticker = api.getTicker(); + if (ticker != null && ticker.getEUR() != null) { + if (ICurrencies.EUR.equalsIgnoreCase(fiatCurrency)){ + return ticker.getEUR().getSell15m(); + } + return null; + } + return null; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.NLG); + return result; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.EUR); + return result; + } +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerResponse.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerResponse.java new file mode 100644 index 0000000..d2bfd05 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/GuldencoinTickerResponse.java @@ -0,0 +1,143 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * 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"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.guldencoin.sources; + +import java.math.BigDecimal; + +public class GuldencoinTickerResponse { + private EUR euro; + private BTC btc; + + public class BTC { + private String code; + private String symbol; + private BigDecimal buy; + private BigDecimal sell; + private BigDecimal buy15m; + private BigDecimal sell15m; + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + public String getSymbol() { + return symbol; + } + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getBuy() { + return buy; + } + public void setBuy(BigDecimal buy) { + this.buy = buy; + } + + public String getSell() { + return sell; + } + public void setSell(BigDecimal sell) { + this.sell = sell; + } + + public String getBuy15m() { + return buy15m; + } + public void setBuy15m(BigDecimal buy15m) { + this.buy15m = buy15m; + } + + public String getSell15m() { + return sell15m; + } + public void setSell15m(BigDecimal sell15m) { + this.sell15m = sell15m; + } + + } + + public class EUR { + private String code; + private String symbol; + private BigDecimal buy; + private BigDecimal sell; + private BigDecimal buy15m; + private BigDecimal sell15m; + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + public String getSymbol() { + return symbol; + } + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getBuy() { + return buy; + } + public void setBuy(BigDecimal buy) { + this.buy = buy; + } + + public String getSell() { + return sell; + } + public void setSell(BigDecimal sell) { + this.sell = sell; + } + + public String getBuy15m() { + return buy15m; + } + public void setBuy15m(BigDecimal buy15m) { + this.buy15m = buy15m; + } + + public String getSell15m() { + return sell15m; + } + public void setSell15m(BigDecimal sell15m) { + this.sell15m = sell15m; + } + + } + + public EUR getEUR() { + return euro; + } + public void setEUR(EUR euro) { + this.euro = euro; + } + + public BTC getBTC() { + return btc; + } + public void setBTC(BTC btc) { + this.btc = btc; + } +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/IGuldencoinTickerRateAPI.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/IGuldencoinTickerRateAPI.java new file mode 100644 index 0000000..2e94db2 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/sources/IGuldencoinTickerRateAPI.java @@ -0,0 +1,31 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * 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"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.guldencoin.sources; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/api/v1/") +@Produces(MediaType.APPLICATION_JSON) +public interface IGuldencoinTickerRateAPI { + @GET + @Path("ticker") + GuldencoinTickerResponse getTicker(); +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/wallets/guldencoind/GuldencoindRPCWallet.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/wallets/guldencoind/GuldencoindRPCWallet.java index f28d3de..7af68c3 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/wallets/guldencoind/GuldencoindRPCWallet.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/guldencoin/wallets/guldencoind/GuldencoindRPCWallet.java @@ -32,7 +32,7 @@ import java.util.Set; public class GuldencoindRPCWallet implements IWallet{ private static final Logger log = LoggerFactory.getLogger(GuldencoindRPCWallet.class); - private static final String CRYPTO_CURRENCY = ICurrencies.GLD; + private static final String CRYPTO_CURRENCY = ICurrencies.NLG; public GuldencoindRPCWallet(String rpcURL, String accountName) { this.rpcURL = rpcURL;