removed inc ticker files
This commit is contained in:
parent
36d2d35fc4
commit
d4a15d8349
|
@ -1,31 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* Copyright (C) 2014 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.incognitocoin.sources;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IIncognitocoinTickerRateAPI {
|
||||
@GET
|
||||
@Path("getticker?market=BTC-ICG")
|
||||
IncognitocoinTickerResponse getTicker();
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* Copyright (C) 2014 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.incognitocoin.sources;
|
||||
|
||||
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;
|
||||
|
||||
public class IncognitocoinTickerRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(IncognitocoinTickerRateSource.class);
|
||||
|
||||
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
|
||||
|
||||
private IIncognitocoinTickerRateAPI api;
|
||||
|
||||
public IncognitocoinTickerRateSource() {
|
||||
api = RestProxyFactory.createProxy(IIncognitocoinTickerRateAPI.class, "https://bittrex.com/api/v1.1/public");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!(ICurrencies.ICG.equalsIgnoreCase(cryptoCurrency))) {
|
||||
return null;
|
||||
}
|
||||
if (!(ICurrencies.USD.equalsIgnoreCase(fiatCurrency) || ICurrencies.EUR.equalsIgnoreCase(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 MaxTicker 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 MaxTicker 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.ICG.equalsIgnoreCase(cryptoCurrency))) {
|
||||
return null;
|
||||
}
|
||||
if (!(ICurrencies.USD.equalsIgnoreCase(fiatCurrency) || ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) {
|
||||
return null;
|
||||
}
|
||||
IncognitocoinTickerResponse ticker = api.getTicker();
|
||||
if (ticker != null) {
|
||||
if (ICurrencies.USD.equalsIgnoreCase(fiatCurrency)){
|
||||
return ticker.getMpusd();
|
||||
}else if (ICurrencies.USD.equalsIgnoreCase(fiatCurrency)){
|
||||
return ticker.getBtceuro();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.ICG);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.USD);
|
||||
result.add(ICurrencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
IncognitocoinTickerRateSource rs = new IncognitocoinTickerRateSource();
|
||||
BigDecimal exchangeRateLast = rs.getExchangeRateLast(ICurrencies.ICG, ICurrencies.USD);
|
||||
System.out.println("exchangeRateLast = " + exchangeRateLast);
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* Copyright (C) 2014 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.incognitocoin.sources;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class IncognitocoinTickerResponse {
|
||||
private BigDecimal btcusd;
|
||||
private BigDecimal btceuro;
|
||||
private BigDecimal btcgbp;
|
||||
private BigDecimal btccny;
|
||||
private BigDecimal mpbtc;
|
||||
private BigDecimal mpusd;
|
||||
private BigDecimal mpeuro;
|
||||
private BigDecimal mpgbp;
|
||||
private BigDecimal mpcny;
|
||||
|
||||
public BigDecimal getBtcusd() {
|
||||
return btcusd;
|
||||
}
|
||||
|
||||
public void setBtcusd(BigDecimal btcusd) {
|
||||
this.btcusd = btcusd;
|
||||
}
|
||||
|
||||
public BigDecimal getBtceuro() {
|
||||
return btceuro;
|
||||
}
|
||||
|
||||
public void setBtceuro(BigDecimal btceuro) {
|
||||
this.btceuro = btceuro;
|
||||
}
|
||||
|
||||
public BigDecimal getBtcgbp() {
|
||||
return btcgbp;
|
||||
}
|
||||
|
||||
public void setBtcgbp(BigDecimal btcgbp) {
|
||||
this.btcgbp = btcgbp;
|
||||
}
|
||||
|
||||
public BigDecimal getBtccny() {
|
||||
return btccny;
|
||||
}
|
||||
|
||||
public void setBtccny(BigDecimal btccny) {
|
||||
this.btccny = btccny;
|
||||
}
|
||||
|
||||
public BigDecimal getMpbtc() {
|
||||
return mpbtc;
|
||||
}
|
||||
|
||||
public void setMpbtc(BigDecimal mpbtc) {
|
||||
this.mpbtc = mpbtc;
|
||||
}
|
||||
|
||||
public BigDecimal getMpusd() {
|
||||
return mpusd;
|
||||
}
|
||||
|
||||
public void setMpusd(BigDecimal mpusd) {
|
||||
this.mpusd = mpusd;
|
||||
}
|
||||
|
||||
public BigDecimal getMpeuro() {
|
||||
return mpeuro;
|
||||
}
|
||||
|
||||
public void setMpeuro(BigDecimal mpeuro) {
|
||||
this.mpeuro = mpeuro;
|
||||
}
|
||||
|
||||
public BigDecimal getMpgbp() {
|
||||
return mpgbp;
|
||||
}
|
||||
|
||||
public void setMpgbp(BigDecimal mpgbp) {
|
||||
this.mpgbp = mpgbp;
|
||||
}
|
||||
|
||||
public BigDecimal getMpcny() {
|
||||
return mpcny;
|
||||
}
|
||||
|
||||
public void setMpcny(BigDecimal mpcny) {
|
||||
this.mpcny = mpcny;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue