diff --git a/.gitignore b/.gitignore index fadbae3..77921c6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,10 @@ .DS_Store dist/ build/ +out/ .idea .gradle -.iml +*.iml target install-libs.sh .mvn-repo \ No newline at end of file diff --git a/server_extensions_api/src/main/java/com/generalbytes/batm/server/extensions/ICurrencies.java b/server_extensions_api/src/main/java/com/generalbytes/batm/server/extensions/ICurrencies.java index 28a3448..a09116c 100644 --- a/server_extensions_api/src/main/java/com/generalbytes/batm/server/extensions/ICurrencies.java +++ b/server_extensions_api/src/main/java/com/generalbytes/batm/server/extensions/ICurrencies.java @@ -45,6 +45,7 @@ public interface ICurrencies { public static final String CZK = "CZK"; public static final String EUR = "EUR"; public static final String GBP = "GBP"; + public static final String HUF = "HUF"; public static final String JPY = "JPY"; public static final String SGD = "SGD"; public static final String USD = "USD"; diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java index afc62c9..59ac32c 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java @@ -24,6 +24,7 @@ import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.b import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.coinofsale.CoinOfSalePP; import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.FixPriceRateSource; import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.bity.BityRateSource; +import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.mrcoin.MrCoinRateSource; import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcoind.BATMBitcoindRPCWallet; import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcore.BitcoreWallet; import com.generalbytes.batm.server.extensions.watchlist.IWatchList; @@ -169,6 +170,8 @@ public class BitcoinExtension implements IExtension{ return new BitfinexExchange("**","**"); }else if ("bity".equalsIgnoreCase(rsType)) { return new BityRateSource(); + }else if ("mrcoin".equalsIgnoreCase(rsType)) { + return new MrCoinRateSource(); }else if ("itbit".equalsIgnoreCase(rsType)) { String preferredFiatCurrency = ICurrencies.USD; if (st.hasMoreTokens()) { diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/IMrCoin.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/IMrCoin.java new file mode 100644 index 0000000..2abd97a --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/IMrCoin.java @@ -0,0 +1,38 @@ +/************************************************************************************* + * Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved. + * Copyright (C) 2017 MrCoin Ltd. + * + * 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.bitcoin.sources.mrcoin; + + +import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.mrcoin.dto.RateInfo; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.APPLICATION_JSON) +@Path("/api/v1") +public interface IMrCoin { + + @GET + @Path("/price_ticker") + RateInfo getAtmTickers(); + +} diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/MrCoinRateSource.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/MrCoinRateSource.java new file mode 100644 index 0000000..9b20e58 --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/MrCoinRateSource.java @@ -0,0 +1,101 @@ +/************************************************************************************* + * Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved. + * Copyright (C) 2017 MrCoin Ltd. + * + * 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.bitcoin.sources.mrcoin; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSourceAdvanced; +import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.mrcoin.dto.RateInfo; +import si.mazi.rescu.RestProxyFactory; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +public class MrCoinRateSource implements IRateSourceAdvanced{ + private final IMrCoin api; + public MrCoinRateSource() { + api = RestProxyFactory.createProxy(IMrCoin.class, "https://www.mrcoin.eu"); + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.BTC); + result.add(ICurrencies.ETH); + return result; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.EUR); + result.add(ICurrencies.HUF); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + return getExchangeRateForSell(cryptoCurrency,fiatCurrency); + } + + @Override + public String getPreferredFiatCurrency() { + return ICurrencies.HUF; + } + + + @Override + public BigDecimal getExchangeRateForBuy(String cryptoCurrency, String fiatCurrency) { + final RateInfo rates = api.getAtmTickers(); + if (rates != null) { + return rates.getRateBuy(cryptoCurrency, fiatCurrency); + } + return null; + } + + @Override + public BigDecimal getExchangeRateForSell(String cryptoCurrency, String fiatCurrency) { + final RateInfo rates = api.getAtmTickers(); + if (rates != null) { + return rates.getRateSell(cryptoCurrency, fiatCurrency); + } + return null; + } + + @Override + public BigDecimal calculateBuyPrice(String cryptoCurrency, String fiatCurrency, BigDecimal cryptoAmount) { + final BigDecimal rate = getExchangeRateForBuy(cryptoCurrency, fiatCurrency); + if (rate != null) { + return rate.multiply(cryptoAmount); + } + return null; + } + + @Override + public BigDecimal calculateSellPrice(String cryptoCurrency, String fiatCurrency, BigDecimal cryptoAmount) { + final BigDecimal rate = getExchangeRateForSell(cryptoCurrency, fiatCurrency); + if (rate != null) { + return rate.multiply(cryptoAmount); + } + return null; + } + +} diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/dto/RateInfo.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/dto/RateInfo.java new file mode 100644 index 0000000..99caba2 --- /dev/null +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/mrcoin/dto/RateInfo.java @@ -0,0 +1,85 @@ +/************************************************************************************* + * Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved. + * Copyright (C) 2017 MrCoin Ltd. + * + * 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.bitcoin.sources.mrcoin.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.math.BigDecimal; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonSetter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@JsonIgnoreProperties({"ticker"}) +public class RateInfo { + + private static final Logger log = LoggerFactory.getLogger(RateInfo.class); + private Map atm_tickers; + + @JsonSetter("atm_ticker") + public void setAtmTickers(Map atm_tickers) { + this.atm_tickers = atm_tickers; + } + + public Ticker getTicker(String fromCurrency, String toCurrency) { + String pair = (fromCurrency + toCurrency).toUpperCase(); + return this.atm_tickers.get(pair); + } + + public BigDecimal getRateBuy(String fromCurrency, String toCurrency) { + Ticker t = getTicker(fromCurrency, toCurrency); + return t.isValid() ? t.getAsk() : null; + } + + public BigDecimal getRateSell(String fromCurrency, String toCurrency) { + Ticker t = getTicker(fromCurrency, toCurrency); + return t.isValid() ? t.getBid() : null; + } + + public static class Ticker { + private BigDecimal bid; + private BigDecimal ask; + private boolean valid; + + public Ticker( + @JsonProperty("bid") BigDecimal bid, + @JsonProperty("ask") BigDecimal ask, + @JsonProperty("valid") boolean valid) { + + this.bid = bid; + this.ask = ask; + this.valid = valid; + } + + public BigDecimal getBid() { + return bid; + } + + public BigDecimal getAsk() { + return ask; + } + + public boolean isValid() { + return valid; + } + } +} diff --git a/server_extensions_extra/src/main/resources/batm-extensions.xml b/server_extensions_extra/src/main/resources/batm-extensions.xml index d3f4854..d92e0e4 100644 --- a/server_extensions_extra/src/main/resources/batm-extensions.xml +++ b/server_extensions_extra/src/main/resources/batm-extensions.xml @@ -41,6 +41,10 @@ BTC + + BTC + ETH + BTC ETH diff --git a/server_extensions_test/src/main/java/com/generalbytes/batm/server/extensions/test/Tester.java b/server_extensions_test/src/main/java/com/generalbytes/batm/server/extensions/test/Tester.java index b519652..de3f958 100644 --- a/server_extensions_test/src/main/java/com/generalbytes/batm/server/extensions/test/Tester.java +++ b/server_extensions_test/src/main/java/com/generalbytes/batm/server/extensions/test/Tester.java @@ -420,19 +420,26 @@ public class Tester { if (rs instanceof IRateSourceAdvanced) { IRateSourceAdvanced rsa = (IRateSourceAdvanced)rs; - final BigDecimal buyPrice = rsa.getExchangeRateForSell(selectedCryptoCurrency, preferredFiatCurrency); - if (buyPrice != null) { - System.out.println("Buy Price: 1 " + selectedCryptoCurrency + " = " + buyPrice.stripTrailingZeros().toPlainString() + " " + preferredFiatCurrency); - }else{ - System.err.println("Rate source returned NULL on Buy Price."); + + for (String fiatCurrency : fiatCurrencies) { + System.out.println("Checking price for " + fiatCurrency); + + final BigDecimal buyPrice = rsa.getExchangeRateForBuy(selectedCryptoCurrency, fiatCurrency); + if (buyPrice != null) { + System.out.println("Buy Price: 1 " + selectedCryptoCurrency + " = " + buyPrice.stripTrailingZeros().toPlainString() + " " + fiatCurrency); + }else{ + System.err.println("Rate source returned NULL on Buy Price."); + } + + final BigDecimal sellPrice = rsa.getExchangeRateForSell(selectedCryptoCurrency, fiatCurrency); + if (sellPrice != null) { + System.out.println("Sell Price: 1 " + selectedCryptoCurrency + " = " + sellPrice.stripTrailingZeros().toPlainString() + " " + fiatCurrency); + }else{ + System.err.println("Rate source returned NULL on Sell Price."); + } + } - final BigDecimal sellPrice = rsa.getExchangeRateForSell(selectedCryptoCurrency, preferredFiatCurrency); - if (sellPrice != null) { - System.out.println("Sell Price: 1 " + selectedCryptoCurrency + " = " + sellPrice.stripTrailingZeros().toPlainString() + " " + preferredFiatCurrency); - }else{ - System.err.println("Rate source returned NULL on Sell Price."); - } } return; }