Merge pull request #1 from GENERALBYTESCOM/master

Merging
This commit is contained in:
Proteus 2017-12-03 22:42:39 -05:00 committed by GitHub
commit 06273c22e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 274 additions and 161 deletions

View File

@ -22,6 +22,7 @@ import com.generalbytes.batm.server.extensions.extra.dash.sources.FixPriceRateSo
//import com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso.ChainSoRateSource;
//import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio.BlockIOWallet;
import com.generalbytes.batm.server.extensions.extra.dash.sources.cddash.CryptodiggersRateSource;
import com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap.CoinmarketcapRateSource;
import com.generalbytes.batm.server.extensions.extra.dash.wallets.dashd.DashRPCWallet;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
@ -90,15 +91,14 @@ public class DashExtension implements IExtension{
@Override
public IRateSource createRateSource(String sourceLogin) {
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(sourceLogin,":");
StringTokenizer st = new StringTokenizer(sourceLogin, ":");
String exchangeType = st.nextToken();
if ("cddash".equalsIgnoreCase(exchangeType)) {
if ("cddash".equalsIgnoreCase(exchangeType)) {
if (st.hasMoreTokens()) {
return new CryptodiggersRateSource(st.nextToken().toUpperCase());
}
return new CryptodiggersRateSource(ICurrencies.USD);
}
else if ("dashfix".equalsIgnoreCase(exchangeType)) {
} else if ("dashfix".equalsIgnoreCase(exchangeType)) {
BigDecimal rate = BigDecimal.ZERO;
if (st.hasMoreTokens()) {
try {
@ -110,7 +110,9 @@ public class DashExtension implements IExtension{
if (st.hasMoreTokens()) {
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new FixPriceRateSource(rate,preferedFiatCurrency);
return new FixPriceRateSource(rate, preferedFiatCurrency);
} else if ("coinmarketcap".equalsIgnoreCase(exchangeType)) {
return new CoinmarketcapRateSource();
}
}
return null;
@ -119,7 +121,12 @@ public class DashExtension implements IExtension{
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
result.add(ICurrencies.BCH);
result.add(ICurrencies.LTC);
result.add(ICurrencies.XMR);
result.add(ICurrencies.DASH);
result.add(ICurrencies.POT);
return result;
}

View File

@ -0,0 +1,149 @@
package com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
/**
* Created by kkyovsky on 11/29/17.
*/
public class CMCTicker {
private String id;
private String name;
private String symbol;
private BigDecimal rank;
private BigDecimal price_usd;
private BigDecimal price_btc;
@JsonProperty("24h_volume_usd")
private BigDecimal _24h_volume_usd;
private BigDecimal market_cap_usd;
private BigDecimal available_supply;
private BigDecimal total_supply;
private BigDecimal max_supply;
private BigDecimal percent_change_1h;
private BigDecimal percent_change_24h;
private BigDecimal percent_change_7d;
private long last_updated;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public BigDecimal getRank() {
return rank;
}
public void setRank(BigDecimal rank) {
this.rank = rank;
}
public BigDecimal getPrice_usd() {
return price_usd;
}
public void setPrice_usd(BigDecimal price_usd) {
this.price_usd = price_usd;
}
public BigDecimal getPrice_btc() {
return price_btc;
}
public void setPrice_btc(BigDecimal price_btc) {
this.price_btc = price_btc;
}
public BigDecimal get_24h_volume_usd() {
return _24h_volume_usd;
}
public void set_24h_volume_usd(BigDecimal _24h_volume_usd) {
this._24h_volume_usd = _24h_volume_usd;
}
public BigDecimal getMarket_cap_usd() {
return market_cap_usd;
}
public void setMarket_cap_usd(BigDecimal market_cap_usd) {
this.market_cap_usd = market_cap_usd;
}
public BigDecimal getAvailable_supply() {
return available_supply;
}
public void setAvailable_supply(BigDecimal available_supply) {
this.available_supply = available_supply;
}
public BigDecimal getTotal_supply() {
return total_supply;
}
public void setTotal_supply(BigDecimal total_supply) {
this.total_supply = total_supply;
}
public BigDecimal getMax_supply() {
return max_supply;
}
public void setMax_supply(BigDecimal max_supply) {
this.max_supply = max_supply;
}
public BigDecimal getPercent_change_1h() {
return percent_change_1h;
}
public void setPercent_change_1h(BigDecimal percent_change_1h) {
this.percent_change_1h = percent_change_1h;
}
public BigDecimal getPercent_change_24h() {
return percent_change_24h;
}
public void setPercent_change_24h(BigDecimal percent_change_24h) {
this.percent_change_24h = percent_change_24h;
}
public BigDecimal getPercent_change_7d() {
return percent_change_7d;
}
public void setPercent_change_7d(BigDecimal percent_change_7d) {
this.percent_change_7d = percent_change_7d;
}
public long getLast_updated() {
return last_updated;
}
public void setLast_updated(long last_updated) {
this.last_updated = last_updated;
}
}

View File

@ -0,0 +1,70 @@
package com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap;
import com.generalbytes.batm.server.extensions.ICurrencies;
import com.generalbytes.batm.server.extensions.IRateSource;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import si.mazi.rescu.RestProxyFactory;
/**
* Created by kkyovsky on 11/29/17.
*/
public class CoinmarketcapRateSource implements IRateSource {
private ICoinmarketcapAPI api;
public CoinmarketcapRateSource() {
api = RestProxyFactory.createProxy(ICoinmarketcapAPI.class, "https://api.coinmarketcap.com");
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
result.add(ICurrencies.BCH);
result.add(ICurrencies.LTC);
result.add(ICurrencies.ETH);
result.add(ICurrencies.DASH);
result.add(ICurrencies.XMR);
result.add(ICurrencies.POT);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
return result;
}
@Override
public String getPreferredFiatCurrency() {
return ICurrencies.USD;
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (!getFiatCurrencies().contains(fiatCurrency)) {
return null;
}
CMCTicker[] tickers = api.getTickers();
for (int i = 0; i < tickers.length; i++) {
CMCTicker ticker = tickers[i];
if (cryptoCurrency.equalsIgnoreCase(ticker.getSymbol())) {
return ticker.getPrice_usd();
}
}
return null;
}
// public static void main(String[] args) {
// CoinmarketcapRateSource rs = new CoinmarketcapRateSource();
// BigDecimal exchangeRateLast = rs.getExchangeRateLast(ICurrencies.BTC, ICurrencies.USD);
// System.out.println("exchangeRateLast = " + exchangeRateLast);
// }
}

View File

@ -0,0 +1,34 @@
/*************************************************************************************
* Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved.
*
* 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.dash.sources.coinmarketcap;
import com.generalbytes.batm.server.extensions.extra.dash.sources.cddash.CryptodiggersResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/v1/ticker")
@Produces(MediaType.APPLICATION_JSON)
public interface ICoinmarketcapAPI {
@GET
@Path("/")
CMCTicker[] getTickers();
}

View File

@ -2,7 +2,6 @@ package com.generalbytes.batm.server.extensions.extra.potcoin;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.potcoin.sources.FixPriceRateSource;
import com.generalbytes.batm.server.extensions.extra.potcoin.sources.coinmarketcap.CoinmarketcapRateSource;
import com.generalbytes.batm.server.extensions.extra.potcoin.wallets.potwallet.Potwallet;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
@ -76,12 +75,6 @@ public class PotcoinExtension implements IExtension{
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new FixPriceRateSource(rate,preferedFiatCurrency);
} else if ("coinmarketcap".equalsIgnoreCase(rsType)) {
String preferredFiatCurrency = ICurrencies.CAD;
if (st.hasMoreTokens()) {
preferredFiatCurrency = st.nextToken();
}
return new CoinmarketcapRateSource(preferredFiatCurrency);
}
}

View File

@ -1,100 +0,0 @@
package com.generalbytes.batm.server.extensions.extra.potcoin.sources.coinmarketcap;
import com.generalbytes.batm.server.extensions.ICurrencies;
import com.generalbytes.batm.server.extensions.IRateSource;
import si.mazi.rescu.RestProxyFactory;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
public class CoinmarketcapRateSource implements IRateSource {
private String preferedFiatCurrency = ICurrencies.USD;
private ICoinmarketcapRateAPI api;
/**
* Constructor
*/
public CoinmarketcapRateSource(String preferedFiatCurrency) {
if (ICurrencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.USD;
}
if (ICurrencies.CAD.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.CAD;
}
if (ICurrencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.EUR;
}
api = RestProxyFactory.createProxy(ICoinmarketcapRateAPI.class, "https://api.coinmarketcap.com");
}
/**
* This method returns list of supported crypto currencies
* @return
*/
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.POT);
//result.add(ICurrencies.BTC);
return result;
}
/**
* Returns current price of cryptocurrency in specified fiat currency
* @param cryptoCurrency
* @param fiatCurrency
* @return
*/
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
// coinmarketcap uses coin name instead coin symbol
if (ICurrencies.BTC.equalsIgnoreCase(cryptoCurrency)) {
cryptoCurrency = "bitcoin";
} else if (ICurrencies.POT.equalsIgnoreCase(cryptoCurrency)) {
cryptoCurrency = "potcoin";
}
CoinmarketcapResponse[] response = api.getRequest(cryptoCurrency, fiatCurrency);
if (response != null) {
if (ICurrencies.USD.equalsIgnoreCase(fiatCurrency)) {
BigDecimal rate = response[0].getPrice_usd();
return rate;
} else if (ICurrencies.CAD.equalsIgnoreCase(fiatCurrency)) {
BigDecimal rate = response[0].getPrice_cad();
return rate;
} else if (ICurrencies.EUR.equalsIgnoreCase(fiatCurrency)) {
BigDecimal rate = response[0].getPrice_eur();
return rate;
} else {
return null;
}
}
return null;
}
/**
* This method returns list of supported fiat currencies
* @return
*/
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
result.add(ICurrencies.CAD);
result.add(ICurrencies.EUR);
return result;
}
/**
* Returns fiat currency that is used for actual purchases of cryptocurrency by server
* @return
*/
@Override
public String getPreferredFiatCurrency() {
return preferedFiatCurrency;
}
}

View File

@ -1,34 +0,0 @@
package com.generalbytes.batm.server.extensions.extra.potcoin.sources.coinmarketcap;
import java.math.BigDecimal;
public class CoinmarketcapResponse {
private BigDecimal price_usd;
private BigDecimal price_cad;
private BigDecimal price_eur;
public BigDecimal getPrice_usd() {
return price_usd;
}
public void setPrice_usd(BigDecimal price_usd) {
this.price_usd = price_usd;
}
public BigDecimal getPrice_cad() {
return price_cad;
}
public void setPrice_cad(BigDecimal price_cad) {
this.price_cad = price_cad;
}
public BigDecimal getPrice_eur() {
return price_eur;
}
public void setPrice_eur(BigDecimal price_eur) {
this.price_eur = price_eur;
}
}

View File

@ -1,15 +0,0 @@
package com.generalbytes.batm.server.extensions.extra.potcoin.sources.coinmarketcap;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/v1")
@Produces(MediaType.APPLICATION_JSON)
public interface ICoinmarketcapRateAPI {
@GET
@Path("/ticker/{cryptocurrency}/?convert={fiatcurrency}")
CoinmarketcapResponse[] getRequest(@PathParam("cryptocurrency") String cryptoCurrency, @PathParam("fiatcurrency") String fiatCurrency);
}

View File

@ -54,6 +54,15 @@
<param name="fiatcurrency" />
<cryptocurrency>BTC</cryptocurrency>
</ratesource>
<ratesource prefix="coinmarketcap" name ="CoinMarketCap.com" >
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>BCH</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
<cryptocurrency>ETH</cryptocurrency>
<cryptocurrency>DASH</cryptocurrency>
<cryptocurrency>XMR</cryptocurrency>
<cryptocurrency>POT</cryptocurrency>
</ratesource>
<paymentprocessor prefix="bitcoinpay" name="BitcoinPay.com" >
<param name="apikey" />
<cryptocurrency>BTC</cryptocurrency>