Merge branch 'master' into BATM-535-support-for-AMD-currency
This commit is contained in:
commit
72e9032df9
|
@ -0,0 +1,13 @@
|
|||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = false
|
|
@ -8,4 +8,8 @@ out/
|
|||
*.iml
|
||||
target
|
||||
install-libs.sh
|
||||
.mvn-repo
|
||||
.mvn-repo
|
||||
..gitignore.swp
|
||||
.project
|
||||
.classpath
|
||||
.settings/
|
|
@ -21,7 +21,7 @@ Here is the list of functionality that can be extended with extenstions API:
|
|||
Content
|
||||
=======
|
||||
* **server_extensions_api** - contains extension api that all extensions use to extend BATM Server's functionality.
|
||||
* **server_extensions_extra** - reference extension implementation that implements BTC, LTC, DASH,FLASH, DOGE, NLG, ICG, NBT, GRS and MAX coin support functionality.
|
||||
* **server_extensions_extra** - reference extension implementation that implements BTC, LTC, DGB, DASH, SYS, FLASH, DOGE, NLG, ICG, NBT, GRS and MAX coin support functionality.
|
||||
* **server_extensions_test** - contains tester for testing the extensions without requirement of having a BATM server
|
||||
|
||||
Note for developers
|
||||
|
|
Binary file not shown.
|
@ -1,6 +1,5 @@
|
|||
#Fri Feb 02 13:42:34 CET 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
|
||||
|
|
|
@ -8,6 +8,7 @@ version = projectVersion
|
|||
|
||||
jar {
|
||||
baseName 'batm_server_extensions_api'
|
||||
archiveName "${baseName}.${extension}"
|
||||
}
|
||||
|
||||
distributions {
|
||||
|
@ -25,20 +26,22 @@ dependencies {
|
|||
compile(group: 'com.sun.mail', name: 'javax.mail', version: '1.4.7')
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
credentials {
|
||||
username gbArtifactoryUser
|
||||
password gbArtifactoryPassword
|
||||
if (hasProperty('gbArtifactoryUser') && hasProperty('gbArtifactoryPassword') && hasProperty('gbArtifactoryUploadUrl')) {
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
credentials {
|
||||
username gbArtifactoryUser
|
||||
password gbArtifactoryPassword
|
||||
}
|
||||
url gbArtifactoryUploadUrl
|
||||
}
|
||||
url gbArtifactoryUploadUrl
|
||||
}
|
||||
}
|
||||
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ public enum Country {
|
|||
LT("LT", "LTU", "Lithuania"),
|
||||
LU("LU", "LUX", "Luxembourg"),
|
||||
MO("MO", "MAC", "Macao"),
|
||||
MK("MK", "MKD", "Macedonia (the former Yugoslav Republic of)"),
|
||||
MK("MK", "MKD", "Macedonia"),
|
||||
MG("MG", "MDG", "Madagascar"),
|
||||
MW("MW", "MWI", "Malawi"),
|
||||
MY("MY", "MYS", "Malaysia"),
|
||||
|
|
|
@ -31,8 +31,10 @@ public class Currencies {
|
|||
public static final String VIA = "VIA";
|
||||
public static final String DEX = "DEX";
|
||||
public static final String DASH = "DASH";
|
||||
public static final String DGB = "DGB";
|
||||
public static final String DOGE = "DOGE";
|
||||
public static final String FLASH = "FLASH";// FLASH Coin
|
||||
public static final String FTO = "FTO";
|
||||
public static final String MAX = "MAX";
|
||||
public static final String LEO = "LEO";
|
||||
public static final String NLG = "NLG";
|
||||
|
@ -43,10 +45,12 @@ public class Currencies {
|
|||
public static final String POT = "POT";
|
||||
public static final String SMART = "SMART";
|
||||
public static final String START = "START";
|
||||
public static final String SYS = "SYS"; // Syscoin 3
|
||||
public static final String TKN = "TKN";
|
||||
public static final String WDC = "WDC";
|
||||
public static final String XMR = "XMR";
|
||||
|
||||
public static final String AMD = "AMD";
|
||||
public static final String CAD = "CAD";
|
||||
public static final String CHF = "CHF";
|
||||
public static final String CNY = "CNY";
|
||||
|
@ -55,7 +59,8 @@ public class Currencies {
|
|||
public static final String GBP = "GBP";
|
||||
public static final String HUF = "HUF";
|
||||
public static final String JPY = "JPY";
|
||||
public static final String AMD = "AMD";
|
||||
public static final String MKD = "MKD";
|
||||
public static final String MYR = "MYR";
|
||||
public static final String SGD = "SGD";
|
||||
public static final String USD = "USD";
|
||||
public static final String XAF = "XAF";
|
||||
|
@ -75,6 +80,7 @@ public class Currencies {
|
|||
crypto.add(VIA);
|
||||
crypto.add(DEX);
|
||||
crypto.add(DASH);
|
||||
crypto.add(DGB);
|
||||
crypto.add(DOGE);
|
||||
crypto.add(FLASH);
|
||||
crypto.add(MAX);
|
||||
|
@ -93,6 +99,7 @@ public class Currencies {
|
|||
CRYPTO_CURRENCIES = Collections.unmodifiableList(crypto);
|
||||
|
||||
List<String> fiat = new ArrayList<>();
|
||||
fiat.add(AMD);
|
||||
fiat.add(CAD);
|
||||
fiat.add(CHF);
|
||||
fiat.add(CNY);
|
||||
|
@ -101,6 +108,8 @@ public class Currencies {
|
|||
fiat.add(GBP);
|
||||
fiat.add(HUF);
|
||||
fiat.add(JPY);
|
||||
fiat.add(MKD);
|
||||
fiat.add(MYR);
|
||||
fiat.add(SGD);
|
||||
fiat.add(USD);
|
||||
fiat.add(XAF);
|
||||
|
|
|
@ -8,6 +8,7 @@ version = projectVersion
|
|||
|
||||
jar {
|
||||
baseName 'batm_server_extensions_extra'
|
||||
archiveName "${baseName}.${extension}"
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
@ -22,18 +23,20 @@ artifacts {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':server_extensions_api');
|
||||
compile project(':server_extensions_api')
|
||||
compile(group: 'com.azazar', name: 'bitcoin-json-rpc-client', version: '1.0')
|
||||
compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25')
|
||||
compile(group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25')
|
||||
compile(group: 'com.github.mmazi', name: 'rescu', version: '1.9.1')
|
||||
compile(group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.0')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-core', version: '4.2.1')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.2')
|
||||
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.2')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-core', version: '4.2.3')
|
||||
compile(group: 'com.google.guava', name: 'guava', version: '18.0')
|
||||
compile(group: 'com.google.zxing', name: 'core', version: '2.3.0')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-bitfinex', version: '4.2.1')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-itbit', version: '4.2.1')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-bitfinex', version: '4.2.3')
|
||||
compile(group: 'org.knowm.xchange', name: 'xchange-itbit', version: '4.2.3')
|
||||
}
|
||||
|
||||
dependencySubstitutions {
|
||||
|
@ -49,20 +52,22 @@ distributions {
|
|||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
credentials {
|
||||
username gbArtifactoryUser
|
||||
password gbArtifactoryPassword
|
||||
if (hasProperty('gbArtifactoryUser') && hasProperty('gbArtifactoryPassword') && hasProperty('gbArtifactoryUploadUrl')) {
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
credentials {
|
||||
username gbArtifactoryUser
|
||||
password gbArtifactoryPassword
|
||||
}
|
||||
url gbArtifactoryUploadUrl
|
||||
}
|
||||
url gbArtifactoryUploadUrl
|
||||
}
|
||||
}
|
||||
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,158 +0,0 @@
|
|||
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_eur;
|
||||
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_eur() {
|
||||
return price_eur;
|
||||
}
|
||||
|
||||
public void setPrice_eur(BigDecimal price_eur) {
|
||||
this.price_eur = price_eur;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,22 +1,23 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
/**
|
||||
* Created by kkyovsky on 11/29/17.
|
||||
*
|
||||
* Modified by sidhujag on 6/3/2018
|
||||
*/
|
||||
|
||||
public class CoinmarketcapRateSource implements IRateSource {
|
||||
private ICoinmarketcapAPI api;
|
||||
|
||||
private static HashMap<String,Integer> coinIDs = new HashMap<String, Integer>();
|
||||
private String preferredFiatCurrency = Currencies.USD;
|
||||
|
||||
public CoinmarketcapRateSource(String preferedFiatCurrency) {
|
||||
|
@ -27,6 +28,19 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferredFiatCurrency = Currencies.USD;
|
||||
}
|
||||
if (Currencies.CAD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferredFiatCurrency = Currencies.CAD;
|
||||
}
|
||||
coinIDs.put(Currencies.BTC, 1);
|
||||
coinIDs.put(Currencies.SYS, 541);
|
||||
coinIDs.put(Currencies.BCH, 1831);
|
||||
coinIDs.put(Currencies.BTX, 1654);
|
||||
coinIDs.put(Currencies.LTC, 2);
|
||||
coinIDs.put(Currencies.ETH, 1027);
|
||||
coinIDs.put(Currencies.DASH, 131);
|
||||
coinIDs.put(Currencies.XMR, 328);
|
||||
coinIDs.put(Currencies.POT, 122);
|
||||
coinIDs.put(Currencies.FLASH, 1755);
|
||||
}
|
||||
|
||||
public CoinmarketcapRateSource() {
|
||||
|
@ -37,6 +51,7 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.BTC);
|
||||
result.add(Currencies.SYS);
|
||||
result.add(Currencies.BCH);
|
||||
result.add(Currencies.BTX);
|
||||
result.add(Currencies.LTC);
|
||||
|
@ -53,6 +68,7 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.USD);
|
||||
result.add(Currencies.CAD);
|
||||
result.add(Currencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
@ -69,28 +85,27 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
if (!getFiatCurrencies().contains(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
CMCTicker[] tickers;
|
||||
if(Currencies.FLASH.equalsIgnoreCase(cryptoCurrency)){
|
||||
tickers = api.getTickers(cryptoCurrency,fiatCurrency);
|
||||
}else
|
||||
tickers = api.getTickers(fiatCurrency);
|
||||
|
||||
for (int i = 0; i < tickers.length; i++) {
|
||||
CMCTicker ticker = tickers[i];
|
||||
if (cryptoCurrency.equalsIgnoreCase(ticker.getSymbol())) {
|
||||
if (Currencies.EUR.equalsIgnoreCase(fiatCurrency)) {
|
||||
return ticker.getPrice_eur();
|
||||
}else{
|
||||
return ticker.getPrice_usd();
|
||||
}
|
||||
}
|
||||
Integer cryptoId = coinIDs.get(cryptoCurrency);
|
||||
if(cryptoId == null){
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
Map<String, Object> ticker = api.getTickers(cryptoId, fiatCurrency);
|
||||
if(ticker == null){
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> data = (Map<String, Object>) ticker.get("data");
|
||||
if(data == null){
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> quotes = (Map<String, Object>) data.get("quotes");
|
||||
if(quotes == null){
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> quote = (Map<String, Object>) quotes.get(fiatCurrency);
|
||||
if(quote == null){
|
||||
return null;
|
||||
}
|
||||
double price = (double) quote.get("price");
|
||||
return new BigDecimal(price).setScale(2, BigDecimal.ROUND_HALF_EVEN);
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// CoinmarketcapRateSource rs = new CoinmarketcapRateSource(Currencies.EUR);
|
||||
// BigDecimal exchangeRateLast = rs.getExchangeRateLast(Currencies.BTC, Currencies.EUR);
|
||||
// System.out.println("exchangeRateLast = " + exchangeRateLast);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -19,15 +19,11 @@ package com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap
|
|||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/v1/ticker")
|
||||
import java.util.Map;
|
||||
@Path("/v2/ticker")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface ICoinmarketcapAPI {
|
||||
@GET
|
||||
@Path("/")
|
||||
CMCTicker[] getTickers(@QueryParam("convert") String fiatCurrency);
|
||||
|
||||
@GET
|
||||
@Path("/{cryptoToGet}/?convert={convert}")
|
||||
CMCTicker[] getTickers(@PathParam("cryptoToGet") String cryptoToGet,@QueryParam("convert") String fiatCurrency);
|
||||
@Path("/{id}/")
|
||||
Map<String, Object> getTickers(@PathParam("id") Integer id, @QueryParam("convert") String fiatCurrency);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*************************************************************************************
|
||||
* 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.digibyte;
|
||||
|
||||
import com.generalbytes.batm.server.coinutil.AddressFormatException;
|
||||
import com.generalbytes.batm.server.coinutil.Base58;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
|
||||
public class DigiByteAddressValidator implements ICryptoAddressValidator {
|
||||
|
||||
@Override
|
||||
public boolean isAddressValid(String address) {
|
||||
//For whatever reason this may occur, cover the case
|
||||
String lowercase = address.toLowerCase();
|
||||
if (lowercase.startsWith("d") || lowercase.startsWith("3") || lowercase.startsWith("s")) {
|
||||
char[] addressChars = address.toCharArray();
|
||||
//Check for invalid characters; ensure alphanumeric and no forbidden characters exist
|
||||
for (char addressCharacter : addressChars) {
|
||||
if (!(((addressCharacter >= '0' && addressCharacter <= '9') ||
|
||||
(addressCharacter >= 'a' && addressCharacter <= 'z') ||
|
||||
(addressCharacter >= 'A' && addressCharacter <= 'Z')) &&
|
||||
addressCharacter != 'l' && addressCharacter != 'I' &&
|
||||
addressCharacter != '0' && addressCharacter != 'O')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Base58.decodeToBigInteger(address);
|
||||
Base58.decodeChecked(address);
|
||||
return true;
|
||||
} catch (AddressFormatException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaperWalletSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBeBase58Address() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
/*************************************************************************************
|
||||
* 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.digibyte;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
import com.generalbytes.batm.server.extensions.IExchange;
|
||||
import com.generalbytes.batm.server.extensions.IExtension;
|
||||
import com.generalbytes.batm.server.extensions.IPaperWalletGenerator;
|
||||
import com.generalbytes.batm.server.extensions.IPaymentProcessor;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
import com.generalbytes.batm.server.extensions.extra.digibyte.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.digibyte.sources.livecoin.LiveCoinRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.digibyte.wallets.digibyted.DigiByteRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class DigiByteExtension implements IExtension {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BATM DigiByte extra extension";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExchange createExchange(String exchangeLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
|
||||
return null; //no payment processors available
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWallet createWallet(String walletLogin) {
|
||||
if (walletLogin != null && !walletLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(walletLogin, ":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("digibyted".equalsIgnoreCase(walletType)) {
|
||||
//"digibyted:protocol:user:password:ip:port:accountname"
|
||||
|
||||
String protocol = st.nextToken();
|
||||
String username = st.nextToken();
|
||||
String password = st.nextToken();
|
||||
String hostname = st.nextToken();
|
||||
String port = st.nextToken();
|
||||
String accountName = "";
|
||||
if (st.hasMoreTokens()) {
|
||||
accountName = st.nextToken();
|
||||
}
|
||||
|
||||
if (protocol != null && username != null && password != null && hostname != null
|
||||
&& port != null && accountName != null) {
|
||||
String rpcURL =
|
||||
protocol + "://" + username + ":" + password + "@" + hostname + ":" + port;
|
||||
return new DigiByteRPCWallet(rpcURL, accountName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (Currencies.DGB.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new DigiByteAddressValidator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRateSource createRateSource(String sourceLogin) {
|
||||
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(sourceLogin, ":");
|
||||
String exchangeType = st.nextToken();
|
||||
if ("digibytefix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate, preferedFiatCurrency);
|
||||
} else if ("livecoin".equalsIgnoreCase(exchangeType)) {
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new LiveCoinRateSource(preferedFiatCurrency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.DGB);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedWatchListsNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWatchList getWatchList(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.digibyte.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 7/31/14.
|
||||
*/
|
||||
public class FixPriceRateSource implements IRateSource {
|
||||
|
||||
private BigDecimal rate = BigDecimal.ZERO;
|
||||
|
||||
private String preferedFiatCurrency = Currencies.USD;
|
||||
|
||||
public FixPriceRateSource(BigDecimal rate, String preferedFiatCurrency) {
|
||||
this.rate = rate;
|
||||
if (Currencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.EUR;
|
||||
}
|
||||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
if (Currencies.CAD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.CAD;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.DGB);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (Currencies.DGB.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.CAD);
|
||||
result.add(Currencies.USD);
|
||||
result.add(Currencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferedFiatCurrency;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.digibyte.sources.livecoin;
|
||||
|
||||
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("/exchange")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface ILiveCoinAPI {
|
||||
|
||||
@GET
|
||||
@Path("/ticker?currencyPair={currencyPair}")
|
||||
LiveCoinTicker getTicker(@PathParam("currencyPair") String currencyPair);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.digibyte.sources.livecoin;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
public class LiveCoinRateSource implements IRateSource {
|
||||
|
||||
private ILiveCoinAPI api;
|
||||
|
||||
private String preferredFiatCurrency = Currencies.USD;
|
||||
|
||||
public LiveCoinRateSource(String preferedFiatCurrency) {
|
||||
if (Currencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferredFiatCurrency = Currencies.EUR;
|
||||
}
|
||||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferredFiatCurrency = Currencies.USD;
|
||||
}
|
||||
api = RestProxyFactory.createProxy(ILiveCoinAPI.class, "https://api.livecoin.net");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.DGB);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.USD);
|
||||
result.add(Currencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(fiatCurrency) || !getCryptoCurrencies().contains(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
//Grab the last dgb rate in btc
|
||||
LiveCoinTicker dgbBtc = api.getTicker(Currencies.DGB + "/" + Currencies.BTC);
|
||||
|
||||
//Grab the last btc rate in the selected fiat currency
|
||||
LiveCoinTicker btcFiat = api.getTicker(Currencies.BTC + "/" + fiatCurrency);
|
||||
|
||||
BigDecimal lastDgbPriceInBtc = dgbBtc.getLast();
|
||||
BigDecimal lastBtcPriceInFiat = btcFiat.getLast();
|
||||
|
||||
//Multiply the last dgb/btc rate by the last btc/fiat rate to get the last dgb/fiat rate
|
||||
BigDecimal lastDgbPriceInFiat = lastDgbPriceInBtc.multiply(lastBtcPriceInFiat);
|
||||
|
||||
return lastDgbPriceInFiat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferredFiatCurrency;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.digibyte.sources.livecoin;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class LiveCoinTicker {
|
||||
|
||||
@JsonProperty("last")
|
||||
private BigDecimal last;
|
||||
|
||||
public BigDecimal getLast() {
|
||||
return last;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*************************************************************************************
|
||||
* 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.digibyte.wallets.digibyted;
|
||||
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinException;
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DigiByteRPCWallet implements IWallet {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DigiByteRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = Currencies.DGB;
|
||||
|
||||
public DigiByteRPCWallet(String rpcURL, String accountName) {
|
||||
this.rpcURL = rpcURL;
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
private String rpcURL;
|
||||
private String accountName;
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(CRYPTO_CURRENCY);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredCryptoCurrency() {
|
||||
return CRYPTO_CURRENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency,
|
||||
String description) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Digibyted wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("Digibyted sending coins from " + accountName + " to: " + destinationAddress + " "
|
||||
+ amount);
|
||||
try {
|
||||
String result = getClient(rpcURL)
|
||||
.sendFrom(accountName, destinationAddress, amount.doubleValue());
|
||||
log.debug("result = " + result);
|
||||
return result;
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCryptoAddress(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Digibyted wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> addressesByAccount = getClient(rpcURL).getAddressesByAccount(accountName);
|
||||
if (addressesByAccount == null || addressesByAccount.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return addressesByAccount.get(0);
|
||||
}
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Digibyted wallet error: unknown cryptocurrency: " + cryptoCurrency);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
double balance = getClient(rpcURL).getBalance(accountName);
|
||||
return BigDecimal.valueOf(balance);
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BitcoinJSONRPCClient getClient(String rpcURL) {
|
||||
try {
|
||||
return new BitcoinJSONRPCClient(rpcURL);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin;
|
||||
|
||||
import com.generalbytes.batm.server.coinutil.AddressFormatException;
|
||||
import com.generalbytes.batm.server.coinutil.Base58;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
|
||||
public class FuturocoinAddressValidator implements ICryptoAddressValidator {
|
||||
|
||||
@Override
|
||||
public boolean isAddressValid(String address) {
|
||||
if (address.startsWith("F") || address.startsWith("6")) {
|
||||
try {
|
||||
Base58.decodeToBigInteger(address);
|
||||
Base58.decodeChecked(address);
|
||||
} catch (AddressFormatException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBeBase58Address() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaperWalletSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*************************************************************************************
|
||||
* 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.futurocoin;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.YobitRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.futurocoin.wallets.futurocoind.FuturocoinRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class FuturocoinExtension implements IExtension{
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BATM Futurocoin extra extension";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExchange createExchange(String exchangeLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
|
||||
return null; //no payment processors available
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWallet createWallet(String walletLogin) {
|
||||
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(walletLogin,":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("futurocoind".equalsIgnoreCase(walletType)) {
|
||||
String protocol = st.nextToken();
|
||||
String username = st.nextToken();
|
||||
String password = st.nextToken();
|
||||
String hostname = st.nextToken();
|
||||
String port = st.nextToken();
|
||||
String accountName ="";
|
||||
if (st.hasMoreTokens()) {
|
||||
accountName = st.nextToken();
|
||||
}
|
||||
|
||||
|
||||
if (protocol != null && username != null && password != null && hostname !=null && port != null && accountName != null) {
|
||||
String rpcURL = protocol +"://" + username +":" + password + "@" + hostname +":" + port;
|
||||
return new FuturocoinRPCWallet(rpcURL,accountName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (Currencies.FTO.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new FuturocoinAddressValidator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRateSource createRateSource(String sourceLogin) {
|
||||
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(sourceLogin, ":");
|
||||
String exchangeType = st.nextToken();
|
||||
|
||||
if ("futurocoinfix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate, preferedFiatCurrency);
|
||||
} else if ("yobit".equalsIgnoreCase(exchangeType)) {
|
||||
return new YobitRateSource();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.FTO);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedWatchListsNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWatchList getWatchList(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by woolly_sammoth on 11/12/14.
|
||||
*/
|
||||
public class FixPriceRateSource implements IRateSource {
|
||||
private BigDecimal rate = BigDecimal.ZERO;
|
||||
|
||||
private String preferedFiatCurrency = Currencies.USD;
|
||||
|
||||
public FixPriceRateSource(BigDecimal rate, String preferedFiatCurrency) {
|
||||
this.rate = rate;
|
||||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.FTO);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (Currencies.FTO.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.USD);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferedFiatCurrency;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.YobitResponse;
|
||||
|
||||
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("/api/3/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IYobitAPI {
|
||||
@GET
|
||||
@Path("ticker/{cryptocurrency}_{fiatcurrency}")
|
||||
YobitResponse getTicker(@PathParam("cryptocurrency") String cryptoCurrency, @PathParam("fiatcurrency") String fiatCurrency);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.YobitResponse;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
public class YobitRateSource implements IRateSource {
|
||||
|
||||
private IYobitAPI api;
|
||||
|
||||
public YobitRateSource() {
|
||||
api = RestProxyFactory.createProxy(IYobitAPI.class, "https://yobit.net");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.FTO);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.USD);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(fiatCurrency) || !getCryptoCurrencies().contains(cryptoCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
YobitResponse response = api.getTicker(cryptoCurrency.toLowerCase(), fiatCurrency.toLowerCase());
|
||||
return response.getFto_usd().getLast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return Currencies.USD;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Ticker {
|
||||
private BigDecimal high;
|
||||
private BigDecimal low;
|
||||
private BigDecimal avg;
|
||||
private BigDecimal vol;
|
||||
private BigDecimal vol_cur;
|
||||
private BigDecimal last;
|
||||
private BigDecimal buy;
|
||||
private BigDecimal sell;
|
||||
private long updated;
|
||||
|
||||
public BigDecimal getHigh() {
|
||||
return high;
|
||||
}
|
||||
|
||||
public void setHigh(BigDecimal high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public BigDecimal getLow() {
|
||||
return low;
|
||||
}
|
||||
|
||||
public void setLow(BigDecimal low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public BigDecimal getAvg() {
|
||||
return avg;
|
||||
}
|
||||
|
||||
public void setAvg(BigDecimal avg) {
|
||||
this.avg = avg;
|
||||
}
|
||||
|
||||
public BigDecimal getVol() {
|
||||
return vol;
|
||||
}
|
||||
|
||||
public void setVol(BigDecimal vol) {
|
||||
this.vol = vol;
|
||||
}
|
||||
|
||||
public BigDecimal getVol_cur() {
|
||||
return vol_cur;
|
||||
}
|
||||
|
||||
public void setVol_cur(BigDecimal vol_cur) {
|
||||
this.vol_cur = vol_cur;
|
||||
}
|
||||
|
||||
public BigDecimal getLast() {
|
||||
return last;
|
||||
}
|
||||
|
||||
public void setLast(BigDecimal last) {
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public BigDecimal getBuy() {
|
||||
return buy;
|
||||
}
|
||||
|
||||
public void setBuy(BigDecimal buy) {
|
||||
this.buy = buy;
|
||||
}
|
||||
|
||||
public BigDecimal getSell() {
|
||||
return sell;
|
||||
}
|
||||
|
||||
public void setSell(BigDecimal sell) {
|
||||
this.sell = sell;
|
||||
}
|
||||
|
||||
public long getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(long updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto;
|
||||
|
||||
public class YobitResponse {
|
||||
private Ticker fot_usd;
|
||||
|
||||
public Ticker getFto_usd() {
|
||||
return fot_usd;
|
||||
}
|
||||
|
||||
public void setFot_usd(Ticker fot_usd) {
|
||||
this.fot_usd = fot_usd;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.futurocoin.wallets.futurocoind;
|
||||
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinException;
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class FuturocoinRPCWallet implements IWallet {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FuturocoinRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = Currencies.FTO;
|
||||
|
||||
public FuturocoinRPCWallet(String rpcURL, String accountName) {
|
||||
this.rpcURL = rpcURL;
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
private String rpcURL;
|
||||
private String accountName;
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(CRYPTO_CURRENCY);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredCryptoCurrency() {
|
||||
return CRYPTO_CURRENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Futurocoind wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("Futurocoind sending coins from " + accountName + " to: " + destinationAddress + " " + amount);
|
||||
try {
|
||||
String result = getClient(rpcURL).sendFrom(accountName, destinationAddress,amount.doubleValue());
|
||||
log.debug("result = " + result);
|
||||
return result;
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCryptoAddress(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Futurocoind wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> addressesByAccount = getClient(rpcURL).getAddressesByAccount(accountName);
|
||||
if (addressesByAccount == null || addressesByAccount.size() == 0) {
|
||||
return null;
|
||||
}else{
|
||||
return addressesByAccount.get(0);
|
||||
}
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Futurocoind wallet error: unknown cryptocurrency: " + cryptoCurrency);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
double balance = getClient(rpcURL).getBalance(accountName);
|
||||
return BigDecimal.valueOf(balance);
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BitcoinJSONRPCClient getClient(String rpcURL) {
|
||||
try {
|
||||
return new BitcoinJSONRPCClient(rpcURL);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
************************************************************************************/
|
||||
package com.generalbytes.batm.server.extensions.extra.maxcoin.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.generalbytes.batm.server.extensions.extra.smartcash;
|
|||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash.SmartCashRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.smartcash.wallets.smartcashd.SmartcashRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
|
@ -99,6 +100,12 @@ public class SmartcashExtension implements IExtension{
|
|||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate,preferedFiatCurrency);
|
||||
}else if ("smartapi".equalsIgnoreCase(exchangeType)) {
|
||||
String preferredFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new SmartCashRateSource(preferredFiatCurrency);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class APIResponse {
|
||||
|
||||
public BigDecimal count;
|
||||
public Item[] items;
|
||||
public Last last;
|
||||
public String resource;
|
||||
public BigDecimal status;
|
||||
public BigDecimal execution;
|
||||
|
||||
public static class Item {
|
||||
public String updated;
|
||||
public Currency currencies;
|
||||
}
|
||||
|
||||
public static class Currency {
|
||||
public BigDecimal USD;
|
||||
public BigDecimal EUR;
|
||||
public BigDecimal CHF;
|
||||
public BigDecimal CAD;
|
||||
public BigDecimal AUD;
|
||||
public BigDecimal GBP;
|
||||
public BigDecimal BRL;
|
||||
public BigDecimal VEF;
|
||||
public BigDecimal SGD;
|
||||
public BigDecimal KRW;
|
||||
public BigDecimal JPY;
|
||||
}
|
||||
|
||||
public class Last {
|
||||
public String id;
|
||||
public String created;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice(String fiatCurrency) {
|
||||
|
||||
BigDecimal price = null;
|
||||
|
||||
try {
|
||||
Field field = this.items[0].currencies.getClass().getDeclaredField(fiatCurrency);
|
||||
field.setAccessible(true);
|
||||
price = (BigDecimal)field.get(this.items[0].currencies);
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
return price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/v1/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface ISmartCashAPI {
|
||||
|
||||
@GET
|
||||
@Path("exchange/currencies?limit=2")
|
||||
public APIResponse returnResponse();
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/* ##
|
||||
# Part of the SmartCash API price extension
|
||||
#
|
||||
# Copyright 2018 dustinface
|
||||
# Created 29.04.2018
|
||||
#
|
||||
* 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").
|
||||
#
|
||||
## */
|
||||
|
||||
package com.generalbytes.batm.server.extensions.extra.smartcash.sources.smartcash;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import si.mazi.rescu.ClientConfig;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
import si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory;
|
||||
import si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SmartCashRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(SmartCashRateSource.class);
|
||||
|
||||
private String preferedFiatCurrency;
|
||||
private ISmartCashAPI api;
|
||||
|
||||
private static HashMap<String,BigDecimal> rateAmounts = new HashMap<String, BigDecimal>();
|
||||
private static HashMap<String,Long> rateTimes = new HashMap<String, Long>();
|
||||
private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec
|
||||
|
||||
public SmartCashRateSource(String preferedFiatCurrency) {
|
||||
|
||||
if (!getFiatCurrencies().contains(preferedFiatCurrency)) {
|
||||
preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
|
||||
this.preferedFiatCurrency = preferedFiatCurrency;
|
||||
|
||||
api = RestProxyFactory.createProxy(ISmartCashAPI.class, "https://api.smartcash.cc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> fiatCurrencies = new HashSet<String>();
|
||||
|
||||
Field[] fields = APIResponse.Currency.class.getFields();
|
||||
|
||||
for (Field f : fields) {
|
||||
fiatCurrencies.add(f.getName());
|
||||
}
|
||||
|
||||
return fiatCurrencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return this.preferedFiatCurrency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.SMART);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
|
||||
String key = cryptoCurrency +"_" + fiatCurrency;
|
||||
synchronized (rateAmounts) {
|
||||
long now = System.currentTimeMillis();
|
||||
BigDecimal amount = rateAmounts.get(key);
|
||||
if (amount == null) {
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called smartcash exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}else {
|
||||
Long expirationTime = rateTimes.get(key);
|
||||
if (expirationTime > now) {
|
||||
return rateAmounts.get(key);
|
||||
}else{
|
||||
//do the job;
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called smartcash exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal getExchangeRateLastSync(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!Currencies.SMART.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return null; //unsupported currency
|
||||
}
|
||||
APIResponse response = api.returnResponse();
|
||||
|
||||
if (response != null) {
|
||||
return response.getPrice(fiatCurrency);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*************************************************************************************
|
||||
* 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.syscoin;
|
||||
|
||||
import com.generalbytes.batm.server.coinutil.AddressFormatException;
|
||||
import com.generalbytes.batm.server.coinutil.Base58;
|
||||
import com.generalbytes.batm.server.extensions.ExtensionsUtil;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
|
||||
public class SyscoinAddressValidator implements ICryptoAddressValidator {
|
||||
@Override
|
||||
public boolean isAddressValid(String address) {
|
||||
if (address.startsWith("S")) {
|
||||
try {
|
||||
Base58.decodeToBigInteger(address);
|
||||
Base58.decodeChecked(address);
|
||||
} catch (AddressFormatException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaperWalletSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustBeBase58Address() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/*************************************************************************************
|
||||
* 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.syscoin;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.syscoin.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap.CoinmarketcapRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.syscoin.wallets.syscoind.SyscoinRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
public class SyscoinExtension implements IExtension{
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BATM Syscoin extra extension";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExchange createExchange(String exchangeLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
|
||||
return null; //no payment processors available
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWallet createWallet(String walletLogin) {
|
||||
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(walletLogin,":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("syscoind".equalsIgnoreCase(walletType)) {
|
||||
//"syscoind:protocol:user:password:ip:port:accountname"
|
||||
|
||||
String protocol = st.nextToken();
|
||||
String username = st.nextToken();
|
||||
String password = st.nextToken();
|
||||
String hostname = st.nextToken();
|
||||
String port = st.nextToken();
|
||||
String accountName ="";
|
||||
if (st.hasMoreTokens()) {
|
||||
accountName = st.nextToken();
|
||||
}
|
||||
|
||||
|
||||
if (protocol != null && username != null && password != null && hostname !=null && port != null && accountName != null) {
|
||||
String rpcURL = protocol +"://" + username +":" + password + "@" + hostname +":" + port;
|
||||
return new SyscoinRPCWallet(rpcURL,accountName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (Currencies.SYS.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new SyscoinAddressValidator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRateSource createRateSource(String sourceLogin) {
|
||||
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(sourceLogin, ":");
|
||||
String exchangeType = st.nextToken();
|
||||
if ("syscoinfix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate, preferedFiatCurrency);
|
||||
} else if ("coinmarketcap".equalsIgnoreCase(exchangeType)) {
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new CoinmarketcapRateSource(preferedFiatCurrency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.SYS);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedWatchListsNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWatchList getWatchList(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.syscoin.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 7/31/14.
|
||||
*/
|
||||
public class FixPriceRateSource implements IRateSource {
|
||||
private BigDecimal rate = BigDecimal.ZERO;
|
||||
|
||||
private String preferedFiatCurrency = Currencies.USD;
|
||||
|
||||
public FixPriceRateSource(BigDecimal rate,String preferedFiatCurrency) {
|
||||
this.rate = rate;
|
||||
if (Currencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.EUR;
|
||||
}
|
||||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
if (Currencies.CAD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.CAD;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.SYS);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (Currencies.SYS.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(Currencies.USD);
|
||||
result.add(Currencies.CAD);
|
||||
result.add(Currencies.EUR);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferedFiatCurrency;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*************************************************************************************
|
||||
* 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.syscoin.wallets.syscoind;
|
||||
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinException;
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SyscoinRPCWallet implements IWallet{
|
||||
private static final Logger log = LoggerFactory.getLogger(SyscoinRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = Currencies.SYS;
|
||||
|
||||
public SyscoinRPCWallet(String rpcURL, String accountName) {
|
||||
this.rpcURL = rpcURL;
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
private String rpcURL;
|
||||
private String accountName;
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(CRYPTO_CURRENCY);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredCryptoCurrency() {
|
||||
return CRYPTO_CURRENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Syscoind wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("Syscoind sending coins from " + accountName + " to: " + destinationAddress + " " + amount);
|
||||
try {
|
||||
String result = getClient(rpcURL).sendFrom(accountName, destinationAddress,amount.doubleValue());
|
||||
log.debug("result = " + result);
|
||||
return result;
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCryptoAddress(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Syscoind wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> addressesByAccount = getClient(rpcURL).getAddressesByAccount(accountName);
|
||||
if (addressesByAccount == null || addressesByAccount.size() == 0) {
|
||||
return null;
|
||||
}else{
|
||||
return addressesByAccount.get(0);
|
||||
}
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
|
||||
log.error("Syscoind wallet error: unknown cryptocurrency: " + cryptoCurrency);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
double balance = getClient(rpcURL).getBalance(accountName);
|
||||
return BigDecimal.valueOf(balance);
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BitcoinJSONRPCClient getClient(String rpcURL) {
|
||||
try {
|
||||
return new BitcoinJSONRPCClient(rpcURL);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -57,6 +57,7 @@
|
|||
<ratesource prefix="coinmarketcap" name ="CoinMarketCap.com" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
<cryptocurrency>SYS</cryptocurrency>
|
||||
<cryptocurrency>BCH</cryptocurrency>
|
||||
<cryptocurrency>LTC</cryptocurrency>
|
||||
<cryptocurrency>ETH</cryptocurrency>
|
||||
|
@ -139,10 +140,6 @@
|
|||
<cryptocurrency>FLASH</cryptocurrency>
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
</ratesource>
|
||||
<!--ratesource prefix="coinmarketcap" name ="coinmarketcap.com" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>FLASH</cryptocurrency>
|
||||
</ratesource-->
|
||||
<ratesource prefix="flashfix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>FLASH</cryptocurrency>
|
||||
|
@ -227,6 +224,42 @@
|
|||
</ratesource>
|
||||
<cryptologo cryptocurrency="DASH" file="dash.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.syscoin.SyscoinExtension" >
|
||||
<wallet prefix="syscoind" name="syscoind">
|
||||
<param name="protocol" />
|
||||
<param name="user" />
|
||||
<param name="password" />
|
||||
<param name="host" />
|
||||
<param name="port" />
|
||||
<param name="accountname" />
|
||||
<cryptocurrency>SYS</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="syscoinfix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>SYS</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="SYS" file="sys.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.digibyte.DigiByteExtension" >
|
||||
<wallet prefix="digibyted" name="Digibyted">
|
||||
<param name="protocol" />
|
||||
<param name="user" />
|
||||
<param name="password" />
|
||||
<param name="host" />
|
||||
<param name="port" />
|
||||
<param name="accountname" />
|
||||
<cryptocurrency>DGB</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="digibytefix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>DGB</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="livecoin" name ="livecoin.net" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>DGB</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="DGB" file="digibyte.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.maxcoin.MaxcoinExtension" >
|
||||
<wallet prefix="maxcoind" name="Maxcoind">
|
||||
<param name="protocol" />
|
||||
|
@ -327,6 +360,10 @@
|
|||
<param name="price" />
|
||||
<cryptocurrency>SMART</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="smartapi" name ="SmartCash API" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>SMART</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="SMART" file="smart.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.startcoin.StartcoinExtension" >
|
||||
|
@ -390,10 +427,6 @@
|
|||
<param name="price" />
|
||||
<cryptocurrency>POT</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="coinmarketcap" name ="coinmarketcap.com" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>POT</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="POT" file="pot.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.dexacoin.DexCoinSupport">
|
||||
|
@ -423,15 +456,30 @@
|
|||
<param name="accountname" />
|
||||
<cryptocurrency>BTX</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="coinmarketcap" name ="coinmarketcap.com" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>BTX</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="btxfix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>BTX</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="BTX" file="btx.png"/>
|
||||
</extension>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.watchlists.BasicWatchlistsExtension" />
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.futurocoin.FuturocoinExtension" >
|
||||
<wallet prefix="futurocoind" name="Futurocoind">
|
||||
<param name="protocol" />
|
||||
<param name="user" />
|
||||
<param name="password" />
|
||||
<param name="host" />
|
||||
<param name="port" />
|
||||
<param name="accountname" />
|
||||
<cryptocurrency>FTO</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="yobit" name="Yobit" >
|
||||
<cryptocurrency>FTO</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="ftofix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>FTO</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="FTO" file="fto.png"/>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
|
@ -397,50 +397,46 @@ public class Tester {
|
|||
final String preferredFiatCurrency = rs.getPreferredFiatCurrency();
|
||||
final Set<String> fiatCurrencies = rs.getFiatCurrencies();
|
||||
final Set<String> cryptoCurrencies = rs.getCryptoCurrencies();
|
||||
System.out.println("Preferred Fiat Currency = " + preferredFiatCurrency);
|
||||
System.out.println("Fiat Currencies:");
|
||||
for (String fiatCurrency : fiatCurrencies) {
|
||||
System.out.println(" " + fiatCurrency);
|
||||
}
|
||||
for (String selectedCryptoCurrency : cryptoCurrencies) {
|
||||
System.out.println("Crypto Currency:");
|
||||
System.out.println(" " + selectedCryptoCurrency);
|
||||
|
||||
final BigDecimal exchangeRateLast = rs.getExchangeRateLast(selectedCryptoCurrency, preferredFiatCurrency);
|
||||
if (exchangeRateLast != null) {
|
||||
System.out.println("Exchange Rate Last: 1 " + selectedCryptoCurrency + " = " + exchangeRateLast.stripTrailingZeros().toPlainString() + " " + preferredFiatCurrency);
|
||||
}else{
|
||||
System.err.println("Rate source returned NULL.");
|
||||
}
|
||||
|
||||
System.out.println("Preferred Fiat Currency = " + preferredFiatCurrency);
|
||||
System.out.println("Fiat Currencies:");
|
||||
for (String fiatCurrency : fiatCurrencies) {
|
||||
System.out.println(" " + fiatCurrency);
|
||||
}
|
||||
System.out.println("Crypto Currencies:");
|
||||
String selectedCryptoCurrency = params;
|
||||
for (String cryptoCurrency : cryptoCurrencies) {
|
||||
if (selectedCryptoCurrency == null) {
|
||||
selectedCryptoCurrency = cryptoCurrency;
|
||||
}
|
||||
System.out.println(" " + cryptoCurrency);
|
||||
}
|
||||
final BigDecimal exchangeRateLast = rs.getExchangeRateLast(selectedCryptoCurrency, preferredFiatCurrency);
|
||||
if (exchangeRateLast != null) {
|
||||
System.out.println("Exchange Rate Last: 1 " + selectedCryptoCurrency + " = " + exchangeRateLast.stripTrailingZeros().toPlainString() + " " + preferredFiatCurrency);
|
||||
}else{
|
||||
System.err.println("Rate source returned NULL.");
|
||||
}
|
||||
if (rs instanceof IRateSourceAdvanced) {
|
||||
IRateSourceAdvanced rsa = (IRateSourceAdvanced)rs;
|
||||
|
||||
if (rs instanceof IRateSourceAdvanced) {
|
||||
IRateSourceAdvanced rsa = (IRateSourceAdvanced)rs;
|
||||
for (String fiatCurrency : fiatCurrencies) {
|
||||
System.out.println("Checking price for " + fiatCurrency);
|
||||
|
||||
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 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, 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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -477,38 +473,38 @@ public class Tester {
|
|||
}
|
||||
|
||||
private void getExchangeBalance(String name, String params) {
|
||||
for (int i = 0; i < extensions.size(); i++) {
|
||||
IExtension extension = extensions.get(i);
|
||||
final IExchange e = extension.createExchange(name + ":" + params);
|
||||
if (e != null) {
|
||||
final String preferredFiatCurrency = e.getPreferredFiatCurrency();
|
||||
final Set<String> cryptoCurrencies = e.getCryptoCurrencies();
|
||||
final Set<String> fiatCurrencies = e.getFiatCurrencies();
|
||||
for (int i = 0; i < extensions.size(); i++) {
|
||||
IExtension extension = extensions.get(i);
|
||||
final IExchange e = extension.createExchange(name + ":" + params);
|
||||
if (e != null) {
|
||||
final String preferredFiatCurrency = e.getPreferredFiatCurrency();
|
||||
final Set<String> cryptoCurrencies = e.getCryptoCurrencies();
|
||||
final Set<String> fiatCurrencies = e.getFiatCurrencies();
|
||||
|
||||
System.out.println("Preferred Fiat Currency = " + preferredFiatCurrency);
|
||||
System.out.println("Crypto Currencies:");
|
||||
String selectedCryptoCurrency = null;
|
||||
for (String cryptoCurrency : cryptoCurrencies) {
|
||||
if (selectedCryptoCurrency == null) {
|
||||
selectedCryptoCurrency = cryptoCurrency;
|
||||
}
|
||||
System.out.println(" " + cryptoCurrency);
|
||||
}
|
||||
System.out.println("Fiat Currencies:");
|
||||
for (String fiatCurrency : fiatCurrencies) {
|
||||
System.out.println(" " + fiatCurrency);
|
||||
}
|
||||
final BigDecimal balance = e.getCryptoBalance(selectedCryptoCurrency);
|
||||
if (balance != null) {
|
||||
System.out.println("Crypto Balance: " + balance.stripTrailingZeros().toPlainString() + " " + selectedCryptoCurrency);
|
||||
}else{
|
||||
System.err.println("Exchange returned NULL.");
|
||||
}
|
||||
final String depositAddress = e.getDepositAddress(selectedCryptoCurrency);
|
||||
System.out.println("Deposit Address: " + depositAddress);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("Preferred Fiat Currency = " + preferredFiatCurrency);
|
||||
System.out.println("Crypto Currencies:");
|
||||
String selectedCryptoCurrency = null;
|
||||
for (String cryptoCurrency : cryptoCurrencies) {
|
||||
if (selectedCryptoCurrency == null) {
|
||||
selectedCryptoCurrency = cryptoCurrency;
|
||||
}
|
||||
System.out.println(" " + cryptoCurrency);
|
||||
}
|
||||
System.out.println("Fiat Currencies:");
|
||||
for (String fiatCurrency : fiatCurrencies) {
|
||||
System.out.println(" " + fiatCurrency);
|
||||
}
|
||||
final BigDecimal balance = e.getCryptoBalance(selectedCryptoCurrency);
|
||||
if (balance != null) {
|
||||
System.out.println("Crypto Balance: " + balance.stripTrailingZeros().toPlainString() + " " + selectedCryptoCurrency);
|
||||
}else{
|
||||
System.err.println("Exchange returned NULL.");
|
||||
}
|
||||
final String depositAddress = e.getDepositAddress(selectedCryptoCurrency);
|
||||
System.out.println("Deposit Address: " + depositAddress);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.err.println("Error: Exchange not found.");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue