Merge pull request #51 from vsobalski/master
Added support for Flashcoin
This commit is contained in:
commit
4c18959044
|
@ -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, DOGE, NLG, ICG, NBT, GRS and MAX coin support 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_test** - contains tester for testing the extensions without requirement of having a BATM server
|
||||
|
||||
Note for developers
|
||||
|
|
|
@ -28,6 +28,7 @@ public interface ICurrencies {
|
|||
public static final String DEX = "DEX";
|
||||
public static final String DASH = "DASH";
|
||||
public static final String DOGE = "DOGE";
|
||||
public static final String FLASH = "FLASH";// FLASH Coin
|
||||
public static final String MAX = "MAX";
|
||||
public static final String LEO = "LEO";
|
||||
public static final String NLG = "NLG";
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*************************************************************************************
|
||||
* 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.flashcoin;
|
||||
|
||||
import com.generalbytes.batm.server.coinutil.AddressFormatException;
|
||||
import com.generalbytes.batm.server.coinutil.Base58;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
|
||||
public class FlashcoinAddressValidator implements ICryptoAddressValidator {
|
||||
|
||||
@Override
|
||||
public boolean isAddressValid(String address) {
|
||||
if (address.startsWith("U")) {
|
||||
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,144 @@
|
|||
/*************************************************************************************
|
||||
* 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.flashcoin;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.flashcoin.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.flashcoin.sources.coinexchange.CoinexchangeRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.flashcoin.sources.cryptopia.CryptopiaRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.flashcoin.wallets.flashcoind.FlashcoinRPCWallet;
|
||||
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 FlashcoinExtension implements IExtension{
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BATM Flashcoin extension";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExchange createExchange(String exchangeLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWallet createWallet(String walletLogin) {
|
||||
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(walletLogin,":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("flashcoind".equalsIgnoreCase(walletType)) {
|
||||
//"flashcoind: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 FlashcoinRPCWallet(rpcURL,accountName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (ICurrencies.FLASH.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new FlashcoinAddressValidator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
|
||||
return null; //no payment processors available
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRateSource createRateSource(String sourceLogin) {
|
||||
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(sourceLogin,":");
|
||||
String exchangeType = st.nextToken();
|
||||
|
||||
if ("cryptopia".equalsIgnoreCase(exchangeType)) {
|
||||
String preferredFiatCurrency = ICurrencies.BTC;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new CryptopiaRateSource(preferredFiatCurrency);
|
||||
}else if ("coinexchange".equalsIgnoreCase(exchangeType)) {
|
||||
String preferredFiatCurrency = ICurrencies.BTC;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferredFiatCurrency = st.nextToken();
|
||||
}
|
||||
return new CoinexchangeRateSource(preferredFiatCurrency);
|
||||
//} else if ("coinmarketcap".equalsIgnoreCase(exchangeType)) {
|
||||
// return new CoinmarketcapRateSource();
|
||||
}else if ("flashfix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
String preferedFiatCurrency = ICurrencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate,preferedFiatCurrency);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.FLASH);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedWatchListsNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWatchList getWatchList(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.flashcoin.sources;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 7/31/14.
|
||||
*/
|
||||
public class FixPriceRateSource implements IRateSource {
|
||||
private BigDecimal rate = BigDecimal.ZERO;
|
||||
|
||||
private String preferedFiatCurrency = ICurrencies.USD;
|
||||
|
||||
public FixPriceRateSource(BigDecimal rate,String preferedFiatCurrency) {
|
||||
this.rate = rate;
|
||||
if (ICurrencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = ICurrencies.EUR;
|
||||
}
|
||||
if (ICurrencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = ICurrencies.USD;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.FLASH);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (ICurrencies.FLASH.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.USD);
|
||||
result.add(ICurrencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferedFiatCurrency;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.flashcoin.sources.coinexchange;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by vsobalski on 15/02/18.
|
||||
*/
|
||||
|
||||
public class CoinexchangeRateSource implements IRateSource {
|
||||
private static final Logger log = LoggerFactory.getLogger(CoinexchangeRateSource.class);
|
||||
|
||||
private IcoinexchangeAPI api;
|
||||
private String preferedFiatCurrency;
|
||||
|
||||
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 CoinexchangeRateSource(String preferedFiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(preferedFiatCurrency)) {
|
||||
preferedFiatCurrency = ICurrencies.BTC;
|
||||
}
|
||||
this.preferedFiatCurrency = preferedFiatCurrency;
|
||||
|
||||
|
||||
api = RestProxyFactory.createProxy(IcoinexchangeAPI.class, "https://www.coinexchange.io/api/v1/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.FLASH);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.BTC);
|
||||
// result.add(ICurrencies.LTC);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return this.preferedFiatCurrency;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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 bitcoinaverage 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 bitcoinaverage 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 (!ICurrencies.FLASH.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return null; //unsupported currency
|
||||
}
|
||||
String key = null;
|
||||
|
||||
switch(fiatCurrency){
|
||||
case ICurrencies.BTC:
|
||||
key = "684";
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
OrderBookResponse orderBookResponse = api.returnOrderBook(key);
|
||||
if (orderBookResponse != null && orderBookResponse.success==1) {
|
||||
return orderBookResponse.result.AskPrice;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
CoinexchangeRateSource rs = new CoinexchangeRateSource(ICurrencies.BTC);
|
||||
BigDecimal exchangeRateLast = rs.getExchangeRateLast(ICurrencies.FLASH, ICurrencies.BTC);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*************************************************************************************
|
||||
* 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.flashcoin.sources.coinexchange;
|
||||
|
||||
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("")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IcoinexchangeAPI {
|
||||
@GET
|
||||
@Path("getmarketsummary?market_id={marketID}")
|
||||
public OrderBookResponse returnOrderBook(@PathParam("marketID") String marketID);
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.flashcoin.sources.coinexchange;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Created by vsobalski on 15/02/18.
|
||||
*/
|
||||
|
||||
/**
|
||||
{
|
||||
"success": "1",
|
||||
"request": "/api/v1/getmarket",
|
||||
"message": "",
|
||||
"result": {
|
||||
"MarketID": "684",
|
||||
"LastPrice": "0.00000373",
|
||||
"Change": "-4.85",
|
||||
"HighPrice": "0.00000461",
|
||||
"LowPrice": "0.00000372",
|
||||
"Volume": "0.13383691",
|
||||
"BTCVolume": "0.13383691",
|
||||
"TradeCount": "20",
|
||||
"BidPrice": "0.00000374",
|
||||
"AskPrice": "0.00000447",
|
||||
"BuyOrderCount": "50",
|
||||
"SellOrderCount": "255"
|
||||
}
|
||||
}
|
||||
**/
|
||||
public class OrderBookResponse {
|
||||
public int success;
|
||||
public String message;
|
||||
|
||||
@JsonProperty("result")
|
||||
public CResult result;
|
||||
|
||||
|
||||
public class CResult {
|
||||
public BigDecimal MarketID;
|
||||
public BigDecimal LastPrice;
|
||||
public BigDecimal Change;
|
||||
public BigDecimal HighPrice;
|
||||
public BigDecimal LowPrice;
|
||||
public BigDecimal Volume;
|
||||
public BigDecimal BTCVolume;
|
||||
public BigDecimal TradeCount;
|
||||
public BigDecimal BidPrice;
|
||||
public BigDecimal AskPrice;
|
||||
public BigDecimal BuyOrderCount;
|
||||
public BigDecimal SellOrderCount;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.flashcoin.sources.cryptopia;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by vsobalski on 15/02/18.
|
||||
*/
|
||||
|
||||
public class CryptopiaRateSource implements IRateSource {
|
||||
private static final Logger log = LoggerFactory.getLogger(CryptopiaRateSource.class);
|
||||
|
||||
private IcryptopiaAPI api;
|
||||
private String preferedFiatCurrency;
|
||||
|
||||
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 CryptopiaRateSource(String preferedFiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(preferedFiatCurrency)) {
|
||||
preferedFiatCurrency = ICurrencies.BTC;
|
||||
}
|
||||
this.preferedFiatCurrency = preferedFiatCurrency;
|
||||
|
||||
|
||||
api = RestProxyFactory.createProxy(IcryptopiaAPI.class, "https://www.cryptopia.co.nz/api");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.FLASH);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.BTC);
|
||||
// result.add(ICurrencies.LTC);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return this.preferedFiatCurrency;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!getFiatCurrencies().contains(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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 bitcoinaverage 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 bitcoinaverage 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 (!ICurrencies.FLASH.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return null; //unsupported currency
|
||||
}
|
||||
String key = cryptoCurrency +"_" + fiatCurrency;
|
||||
OrderBookResponse orderBookResponse = api.returnOrderBook(key);
|
||||
if (orderBookResponse != null && orderBookResponse.getSuccess()) {
|
||||
return orderBookResponse.getData().getAskPrice();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
CryptopiaRateSource rs = new CryptopiaRateSource(ICurrencies.BTC);
|
||||
BigDecimal exchangeRateLast = rs.getExchangeRateLast(ICurrencies.FLASH, ICurrencies.BTC);
|
||||
System.out.println("BTC exchangeRateLast = " + exchangeRateLast);
|
||||
exchangeRateLast = rs.getExchangeRateLast(ICurrencies.FLASH, ICurrencies.LTC);
|
||||
System.out.println("LTC exchangeRateLast = " + exchangeRateLast);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*************************************************************************************
|
||||
* 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.flashcoin.sources.cryptopia;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/GetMarket/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IcryptopiaAPI {
|
||||
@GET
|
||||
@Path("{marketName}")
|
||||
public OrderBookResponse returnOrderBook(@PathParam("marketName") String marketName);
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.flashcoin.sources.cryptopia;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Created by vsobalski on 15/02/18.
|
||||
*/
|
||||
/**
|
||||
|
||||
{
|
||||
"Success":true,
|
||||
"Message":null,
|
||||
"Data":{
|
||||
"TradePairId":5217,
|
||||
"Label":"FLASH/BTC",
|
||||
"AskPrice":0.00000385,
|
||||
"BidPrice":0.00000382,
|
||||
"Low":0.00000374,
|
||||
"High":0.00000401,
|
||||
"Volume":418366.4194124,
|
||||
"LastPrice":0.00000385,
|
||||
"BuyVolume":3682941.99093377,
|
||||
"SellVolume":12813571.80869622,
|
||||
"Change":-2.53,
|
||||
"Open":0.00000395,
|
||||
"Close":0.00000385,
|
||||
"BaseVolume":1.60835246,
|
||||
"BuyBaseVolume":4.26017443,
|
||||
"SellBaseVolume":28700.0528
|
||||
},
|
||||
"Error":null
|
||||
}
|
||||
**/
|
||||
public class OrderBookResponse {
|
||||
public boolean Success;
|
||||
public BigDecimal Message;
|
||||
|
||||
@JsonProperty("Data")
|
||||
public Data Data;
|
||||
public BigDecimal Error;
|
||||
|
||||
public BigDecimal getMessage() {
|
||||
return Message;
|
||||
}
|
||||
|
||||
public void setMessage(BigDecimal message) {
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public BigDecimal getError() {
|
||||
return Error;
|
||||
}
|
||||
|
||||
public void setError(BigDecimal error) {
|
||||
this.Error = error;
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return Data;
|
||||
}
|
||||
|
||||
public void setData(Data Data) {
|
||||
this.Data = Data;
|
||||
}
|
||||
|
||||
public boolean getSuccess() {
|
||||
return Success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.Success = success;
|
||||
}
|
||||
|
||||
public class Data {
|
||||
public BigDecimal TradePairId;
|
||||
public String Label;
|
||||
public BigDecimal AskPrice;
|
||||
public BigDecimal BidPrice;
|
||||
public BigDecimal Low;
|
||||
public BigDecimal High;
|
||||
public BigDecimal Volume;
|
||||
public BigDecimal LastPrice;
|
||||
public BigDecimal BuyVolume;
|
||||
public BigDecimal SellVolume;
|
||||
public BigDecimal Change;
|
||||
public BigDecimal Open;
|
||||
public BigDecimal Close;
|
||||
public BigDecimal BaseVolume;
|
||||
public BigDecimal BuyBaseVolume;
|
||||
public BigDecimal SellBaseVolume;
|
||||
|
||||
public BigDecimal getBaseVolume() {
|
||||
return BaseVolume;
|
||||
}
|
||||
|
||||
public void setBaseVolume(BigDecimal baseVolume) {
|
||||
BaseVolume = baseVolume;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BigDecimal getTradePairId() {return TradePairId;}
|
||||
public void setTradePairId(BigDecimal TradePairId) {this.TradePairId = TradePairId;}
|
||||
|
||||
public String getLabel() {return Label;}
|
||||
public void setLabel(String Label) {this.Label = Label;}
|
||||
|
||||
public BigDecimal getAskPrice() {return AskPrice;}
|
||||
public void setAskPrice(BigDecimal AskPrice) {this.AskPrice = AskPrice;}
|
||||
|
||||
public BigDecimal getBidPrice() {return BidPrice;}
|
||||
public void setBidPrice(BigDecimal BidPrice) {this.BidPrice = BidPrice;}
|
||||
|
||||
public BigDecimal getLow() {return Low;}
|
||||
public void setLow(BigDecimal Low) {this.Low = Low;}
|
||||
|
||||
public BigDecimal getHigh() {return High;}
|
||||
public void setHigh(BigDecimal High) {this.High = High;}
|
||||
|
||||
public BigDecimal getVolume() {return Volume;}
|
||||
public void setVolume(BigDecimal Volume) {this.Volume = Volume;}
|
||||
|
||||
public BigDecimal getLastPrice() {return LastPrice;}
|
||||
public void setLastPrice(BigDecimal LastPrice) {this.LastPrice = LastPrice;}
|
||||
|
||||
public BigDecimal getBuyVolume() {return BuyVolume;}
|
||||
public void setBuyVolume(BigDecimal BuyVolume) {this.BuyVolume = BuyVolume;}
|
||||
|
||||
public BigDecimal getSellVolume() {return SellVolume;}
|
||||
public void setSellVolume(BigDecimal SellVolume) {this.SellVolume = SellVolume;}
|
||||
|
||||
public BigDecimal getChange() {return Change;}
|
||||
public void setChange(BigDecimal Change) {this.Change = Change;}
|
||||
|
||||
public BigDecimal getOpen() {return Open;}
|
||||
public void setOpen(BigDecimal Open) {this.Open = Open;}
|
||||
|
||||
public BigDecimal getClose() {return Close;}
|
||||
public void setClose(BigDecimal Close) {this.Close = Close;}
|
||||
|
||||
public BigDecimal getBuyBaseVolume() {
|
||||
return BuyBaseVolume;
|
||||
}
|
||||
|
||||
public void setBuyBaseVolume(BigDecimal buyBaseVolume) {
|
||||
BuyBaseVolume = buyBaseVolume;
|
||||
}
|
||||
|
||||
public BigDecimal getSellBaseVolume() {
|
||||
return SellBaseVolume;
|
||||
}
|
||||
|
||||
public void setSellBaseVolume(BigDecimal sellBaseVolume) {
|
||||
SellBaseVolume = sellBaseVolume;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*************************************************************************************
|
||||
* 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.flashcoin.wallets.flashcoind;
|
||||
|
||||
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinException;
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient;
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
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 FlashcoinRPCWallet implements IWallet{
|
||||
private static final Logger log = LoggerFactory.getLogger(FlashcoinRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = ICurrencies.FLASH;
|
||||
|
||||
public FlashcoinRPCWallet(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("flashcoind wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("flashcoind 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("flashcoind 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("flashcoind 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -119,6 +119,36 @@
|
|||
</ratesource>
|
||||
<cryptologo cryptocurrency="DOGE" file="doge.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.flashcoin.FlashcoinExtension" >
|
||||
<wallet prefix="flashcoind" name="Flashcoind">
|
||||
<param name="protocol" />
|
||||
<param name="user" />
|
||||
<param name="password" />
|
||||
<param name="host" />
|
||||
<param name="port" />
|
||||
<param name="accountname" />
|
||||
<cryptocurrency>FLASH</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="cryptopia" name="cryptopia.co.nz" >
|
||||
<param name="fiatcurrency" />
|
||||
<cryptocurrency>FLASH</cryptocurrency>
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
<cryptocurrency>LTC</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="coinexchange" name="coinexchange.io" >
|
||||
<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>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="FLASH" file="flash.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.litecoin.LitecoinExtension" >
|
||||
<wallet prefix="litecoind" name="Litecoind">
|
||||
<param name="protocol" />
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue