colors, new currencies, new price provider
This commit is contained in:
parent
157ed1f162
commit
2934baee9d
@ -6,9 +6,12 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -40,8 +43,8 @@ public class MiningBean {
|
||||
List<KeyValue> pool = new ArrayList<>();
|
||||
List<KeyValue> network = new ArrayList<>();
|
||||
|
||||
String[] cryptoCur = new String[] { "btc", "ltc", "xrp", "eth" };
|
||||
double[] lastPrices = new double[] { 0, 0, 0, 0 };
|
||||
String[] cryptoCur = new String[] { "BTC", "LTC", "XRP", "ETH", "DOGE", "ADA" };
|
||||
double[] lastPrices = new double[cryptoCur.length];
|
||||
|
||||
ltcapikey = request.getParameter("ltcapikey");
|
||||
dogapikey = request.getParameter("dogapikey");
|
||||
@ -60,24 +63,43 @@ public class MiningBean {
|
||||
else if (currency.equals("eur"))
|
||||
curSym = "\u20ac";
|
||||
|
||||
for (int i = 0; i < cryptoCur.length; i++) {
|
||||
String ccur = cryptoCur[i];
|
||||
restRequest = getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("X-CMC_PRO_API_KEY", "d9fae81b-79a4-476e-8f5d-2b4f4033e9a1");
|
||||
restRequest = getStringResponse("https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest", headers);
|
||||
|
||||
if (restRequest != null && restRequest.length() > 0) {
|
||||
JSONObject tmp = new JSONObject(restRequest);
|
||||
double res = tmp.getDouble("last");
|
||||
lastPrices[i] = res;
|
||||
JSONArray data = (JSONArray) tmp.get("data");
|
||||
|
||||
for (int i=0;i<data.length();i++) {
|
||||
JSONObject o = data.getJSONObject(i);
|
||||
String symbol = o.getString("symbol");
|
||||
int pos = searchArray(cryptoCur, symbol);
|
||||
if (pos>=0) {
|
||||
JSONObject quote = (JSONObject) o.get("quote");
|
||||
JSONObject usd = (JSONObject) quote.get(currency.toUpperCase());
|
||||
double res = usd.getDouble("price");
|
||||
double change = usd.getDouble("percent_change_24h");
|
||||
|
||||
lastPrices[pos] = res;
|
||||
if (res > 0d)
|
||||
resultStr = curSym + res;
|
||||
resultStr = curSym + res + " ("+String.format("%.2f",(change))+"%)";
|
||||
else
|
||||
resultStr = "Unknown";
|
||||
KeyValue wi = new KeyValue();
|
||||
wi.setKey(ccur.toUpperCase().concat("/").concat(currency.toUpperCase()).concat(" (Bitstamp)"));
|
||||
wi.setKey(symbol.concat("/").concat(currency.toUpperCase()).concat(" (CoinMarketCap)"));
|
||||
wi.setValue(resultStr);
|
||||
if (change>0)
|
||||
wi.setColor("GREEN");
|
||||
else
|
||||
wi.setColor("RED");
|
||||
prices.add(wi);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
@ -480,11 +502,11 @@ public class MiningBean {
|
||||
}
|
||||
|
||||
while (finished != 0b1111111) {
|
||||
//System.out.println(Integer.toBinaryString(finished));
|
||||
// System.out.println(Integer.toBinaryString(finished));
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
//System.out.println("Done: " + Integer.toBinaryString(finished));
|
||||
// System.out.println("Done: " + Integer.toBinaryString(finished));
|
||||
finished = 0b0;
|
||||
|
||||
KeyValue wi = new KeyValue();
|
||||
@ -496,8 +518,10 @@ public class MiningBean {
|
||||
|
||||
String tmp = "";
|
||||
for (KeyValue kv : prices) {
|
||||
if (kv.getColor()==null)
|
||||
kv.setColor("BLUE");
|
||||
tmp = tmp.concat("<pair><key>").concat(
|
||||
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
|
||||
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value>").concat("<color>").concat(kv.getColor()).concat("</color></pair>"));
|
||||
}
|
||||
res = res.replace("#PRICES#", tmp);
|
||||
|
||||
@ -525,6 +549,16 @@ public class MiningBean {
|
||||
return res;
|
||||
}
|
||||
|
||||
private int searchArray(String[] array, String key) {
|
||||
int i=0;
|
||||
for (String str:array) {
|
||||
if (str.equals(key))
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return Constants.APP_VERSION;
|
||||
}
|
||||
@ -542,11 +576,16 @@ public class MiningBean {
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr) {
|
||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT,
|
||||
Constants.DEFAULT_HTTP_READ_TIMEOUT);
|
||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
|
||||
null);
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr, int timeout, int readTimeout) {
|
||||
public String getStringResponse(String urlStr, Map<String, String> headers) {
|
||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
|
||||
headers);
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr, int timeout, int readTimeout, Map<String, String> headers) {
|
||||
String output = "";
|
||||
|
||||
try {
|
||||
@ -558,6 +597,11 @@ public class MiningBean {
|
||||
conn.setReadTimeout(readTimeout);
|
||||
conn.setRequestProperty("User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
|
||||
if (headers != null && !headers.isEmpty()) {
|
||||
for (String key : headers.keySet()) {
|
||||
conn.setRequestProperty(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
conn.connect();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String inputLine;
|
||||
|
||||
@ -7,6 +7,7 @@ public class KeyValue implements Serializable {
|
||||
|
||||
String key;
|
||||
String value;
|
||||
String color;
|
||||
|
||||
public KeyValue() {
|
||||
}
|
||||
@ -14,15 +15,25 @@ public class KeyValue implements Serializable {
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -95,10 +95,13 @@ function AX_asynchUpdateResponse() {
|
||||
|
||||
var resStr = "<li class='group' id='prices'>Prices</li>";
|
||||
for (var i = 0; i <= (prices.length - 1); i++) {
|
||||
var color = prices[i].getElementsByTagName("color")[0].firstChild.data;
|
||||
if (color==null)
|
||||
color = "GREEN";
|
||||
resStr = resStr
|
||||
+ "<li>"
|
||||
+ prices[i].getElementsByTagName("key")[0].firstChild.data
|
||||
+ " <span class='value' style='transition: text-shadow 0.7s ease-in-out;'>"
|
||||
+ " <span class='value' style='transition: text-shadow 0.7s ease-in-out; color:"+color+";'>"
|
||||
+ prices[i].getElementsByTagName("value")[0].firstChild.data
|
||||
+ "</span></li>";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user