From 845ebdba1d10ebd74d287a0245ef748d5df69ceb Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sun, 29 Apr 2018 11:27:48 +0200 Subject: [PATCH 1/3] Created SmartCash API rate source extension. --- server_extensions_extra/build.gradle | 4 +- .../extra/smartcash/SmartcashExtension.java | 7 + .../sources/smartcash/APIResponse.java | 67 +++++++++ .../sources/smartcash/ISmartCashAPI.java | 41 ++++++ .../smartcash/SmartCashRateSource.java | 131 ++++++++++++++++++ .../src/main/resources/batm-extensions.xml | 6 +- 6 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java create mode 100644 server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java create mode 100644 server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java diff --git a/server_extensions_extra/build.gradle b/server_extensions_extra/build.gradle index 7da0690..081ed6e 100644 --- a/server_extensions_extra/build.gradle +++ b/server_extensions_extra/build.gradle @@ -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 } } -} \ No newline at end of file +} diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/SmartcashExtension.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/SmartcashExtension.java index c80590b..5fc47dc 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/SmartcashExtension.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/SmartcashExtension.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); } } diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java new file mode 100644 index 0000000..c7df692 --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java @@ -0,0 +1,67 @@ +/* ## +# Part of the SmartCash API price extension +# +# Copyright 2018 dustinface +# Created 29.04.2018 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +## */ + +package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash; + +import java.math.BigDecimal; + +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 Currencies currencies; + } + + public static class Currencies { + public BigDecimal USD; + public BigDecimal EUR; + public BigDecimal CHF; + } + + public class Last { + public String id; + public String created; + } + + public BigDecimal getPrice(String fiatCurrency) { + + if (fiatCurrency.equalsIgnoreCase("USD")) { + return this.items[0].currencies.USD; + }else if (fiatCurrency.equalsIgnoreCase("EUR")) { + return this.items[0].currencies.EUR; + }else if (fiatCurrency.equalsIgnoreCase("CHF")) { + return this.items[0].currencies.CHF; + } + + return null; + } +} diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java new file mode 100644 index 0000000..4d2a2a9 --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java @@ -0,0 +1,41 @@ +/* ## +# Part of the SmartCash API price extension +# +# Copyright 2018 dustinface +# Created 29.04.2018 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +## */ + +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(); +} diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java new file mode 100644 index 0000000..dde433f --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java @@ -0,0 +1,131 @@ +/* ## +# Part of the SmartCash API price extension +# +# Copyright 2018 dustinface +# Created 29.04.2018 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +## */ + +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; + +public class SmartCashRateSource implements IRateSource{ + private static final Logger log = LoggerFactory.getLogger(SmartCashRateSource.class); + + private String preferedFiatCurrency; + private ISmartCashAPI api; + + private static HashMap rateAmounts = new HashMap(); + private static HashMap rateTimes = new HashMap(); + private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec + + public SmartCashRateSource(String preferedFiatCurrency) { + if (preferedFiatCurrency == null) { + preferedFiatCurrency = Currencies.USD; + } + this.preferedFiatCurrency = preferedFiatCurrency; + + api = RestProxyFactory.createProxy(ISmartCashAPI.class, "https://api.smartcash.cc"); + } + + @Override + public Set getFiatCurrencies() { + Set fiatCurrencies = new HashSet(); + fiatCurrencies.add(Currencies.USD); + fiatCurrencies.add(Currencies.EUR); + fiatCurrencies.add(Currencies.CHF); + return fiatCurrencies; + } + + @Override + public String getPreferredFiatCurrency() { + return this.preferedFiatCurrency; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + 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; + } + +} diff --git a/server_extensions_extra/src/main/resources/batm-extensions.xml b/server_extensions_extra/src/main/resources/batm-extensions.xml index 7146710..964ee56 100644 --- a/server_extensions_extra/src/main/resources/batm-extensions.xml +++ b/server_extensions_extra/src/main/resources/batm-extensions.xml @@ -327,6 +327,10 @@ SMART + + + SMART + @@ -432,6 +436,6 @@ BTX - + From f5cc8b3b3ef92b81c1e77874a44fc772bade5b7b Mon Sep 17 00:00:00 2001 From: xdustinface Date: Wed, 2 May 2018 13:20:57 +0200 Subject: [PATCH 2/3] Changed licence --- .../sources/smartcash/APIResponse.java | 22 +++++-------------- .../sources/smartcash/ISmartCashAPI.java | 22 +++++-------------- .../smartcash/SmartCashRateSource.java | 22 +++++-------------- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java index c7df692..6e8b582 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java @@ -4,23 +4,13 @@ # Copyright 2018 dustinface # Created 29.04.2018 # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: +* 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"). # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. ## */ package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash; diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java index 4d2a2a9..e95f8b4 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/ISmartCashAPI.java @@ -4,23 +4,13 @@ # Copyright 2018 dustinface # Created 29.04.2018 # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: +* 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"). # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. ## */ package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash; diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java index dde433f..3a315e7 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java @@ -4,23 +4,13 @@ # Copyright 2018 dustinface # Created 29.04.2018 # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: +* 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"). # -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. ## */ package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash; From 4f6d5fbefa1b681ecc530b38d9efc896519518da Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 3 May 2018 15:34:30 +0200 Subject: [PATCH 3/3] Added more currencies of smartapi. --- .../sources/smartcash/APIResponse.java | 29 +++++++++++++------ .../smartcash/SmartCashRateSource.java | 16 ++++++---- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java index 6e8b582..1e51207 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/APIResponse.java @@ -16,6 +16,7 @@ package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash; import java.math.BigDecimal; +import java.lang.reflect.Field; public class APIResponse { @@ -28,13 +29,21 @@ public class APIResponse { public static class Item { public String updated; - public Currencies currencies; + public Currency currencies; } - public static class 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 { @@ -44,14 +53,16 @@ public class APIResponse { public BigDecimal getPrice(String fiatCurrency) { - if (fiatCurrency.equalsIgnoreCase("USD")) { - return this.items[0].currencies.USD; - }else if (fiatCurrency.equalsIgnoreCase("EUR")) { - return this.items[0].currencies.EUR; - }else if (fiatCurrency.equalsIgnoreCase("CHF")) { - return this.items[0].currencies.CHF; + 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 null; + return price; } } diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java index 3a315e7..2757c72 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/smartcash/sources/smartcash/SmartCashRateSource.java @@ -33,6 +33,7 @@ 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); @@ -45,9 +46,11 @@ public class SmartCashRateSource implements IRateSource{ private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec public SmartCashRateSource(String preferedFiatCurrency) { - if (preferedFiatCurrency == null) { + + if (!getFiatCurrencies().contains(preferedFiatCurrency)) { preferedFiatCurrency = Currencies.USD; } + this.preferedFiatCurrency = preferedFiatCurrency; api = RestProxyFactory.createProxy(ISmartCashAPI.class, "https://api.smartcash.cc"); @@ -56,9 +59,13 @@ public class SmartCashRateSource implements IRateSource{ @Override public Set getFiatCurrencies() { Set fiatCurrencies = new HashSet(); - fiatCurrencies.add(Currencies.USD); - fiatCurrencies.add(Currencies.EUR); - fiatCurrencies.add(Currencies.CHF); + + Field[] fields = APIResponse.Currency.class.getFields(); + + for (Field f : fields) { + fiatCurrencies.add(f.getName()); + } + return fiatCurrencies; } @@ -74,7 +81,6 @@ public class SmartCashRateSource implements IRateSource{ return result; } - @Override public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {