Merge pull request #37 from keo/add_mrcoin

Add MrCoin.eu RateSource
This commit is contained in:
GENERAL BYTES 2017-11-08 15:19:40 +01:00 committed by GitHub
commit 187e67e767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 252 additions and 12 deletions

3
.gitignore vendored
View File

@ -2,9 +2,10 @@
.DS_Store
dist/
build/
out/
.idea
.gradle
.iml
*.iml
target
install-libs.sh
.mvn-repo

View File

@ -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";

View File

@ -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()) {

View File

@ -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();
}

View File

@ -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<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
result.add(ICurrencies.ETH);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
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;
}
}

View File

@ -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<String, Ticker> atm_tickers;
@JsonSetter("atm_ticker")
public void setAtmTickers(Map<String, Ticker> 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;
}
}
}

View File

@ -41,6 +41,10 @@
<ratesource prefix="bity" name ="Bity.com" >
<cryptocurrency>BTC</cryptocurrency>
</ratesource>
<ratesource prefix="mrcoin" name ="MrCoin.eu" >
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>ETH</cryptocurrency>
</ratesource>
<ratesource prefix="bitfinex" name ="Bitfinex.com Exchange" >
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>ETH</cryptocurrency>

View File

@ -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;
}