add MrCoin RateSource
This commit is contained in:
parent
e2af787d25
commit
4aa76fc68c
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue