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 9d977d5..b334073 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.sources.yahoo.YahooFinanceRateSource; import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcoind.BATMBitcoindRPCWallet; import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcore.BitcoreWallet; @@ -175,6 +176,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