It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
private void scanConsole() {
String command = null;
Scanner scanner = new Scanner(System.in);
while (!QUIT_COMMAND.equals(command)) {
String line = scanner.nextLine();
line = line.toUpperCase();
if (line.startsWith(QUIT_COMMAND)) {
command = QUIT_COMMAND;
System.out.println("Goodbye!");
} else if (line.startsWith(LIST_COMMAND)) {
command = LIST_COMMAND;
listPricesToWatch();
} else {
String[] tmp = line.split(";");
if (tmp.length != 2) {
System.out.println("Bad entry: COMMAND;Price");
} else {
command = tmp[0];
// we use a switch for future commands
switch (command) {
case WATCH_COMMAND:
Float price = null;
try {
price = Float.parseFloat(tmp[1]);
} catch (Exception e) {
price = null;
}
if (price == null) {
System.out.println("Bad price");
} else {
Price priceObj = new Price(currentPrice, price);
pricesToWatch.add(priceObj);
System.out.println("Watch for BTC " + priceObj.type + " = " + price);
}
break;
}
}
}
}
scanner.close();
cancelTimer();
System.exit(0);
}
package com.ssaurel.BitcoinPriceAlert;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONObject;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class App {
public static final String WATCH_COMMAND = "WATCH";
public static final String QUIT_COMMAND = "QUIT";
public static final String LIST_COMMAND = "LIST";
public static final long PERIOD = 60 * 1000; // 30 sec
public static final String BITCOIN_PRICE_ENDPOINT = "https://api.coindesk.com/v1/bpi/currentprice.json";
private OkHttpClient client = new OkHttpClient();
private Timer timer;
private ListpricesToWatch;
private float currentPrice;
public static void main(String[] args) {
App app = new App();
app.launchTimer();
app.scanConsole();
}
public App() {
pricesToWatch = new ArrayList<>();
}
private void scanConsole() {
String command = null;
Scanner scanner = new Scanner(System.in);
while (!QUIT_COMMAND.equals(command)) {
String line = scanner.nextLine();
line = line.toUpperCase();
if (line.startsWith(QUIT_COMMAND)) {
command = QUIT_COMMAND;
System.out.println("Goodbye!");
} else if (line.startsWith(LIST_COMMAND)) {
command = LIST_COMMAND;
listPricesToWatch();
} else {
String[] tmp = line.split(";");
if (tmp.length != 2) {
System.out.println("Bad entry: COMMAND;Price");
} else {
command = tmp[0];
// use a switch for future commands
switch (command) {
case WATCH_COMMAND:
Float price = null;
try {
price = Float.parseFloat(tmp[1]);
} catch (Exception e) {
price = null;
}
if (price == null) {
System.out.println("Bad price");
} else {
Price priceObj = new Price(currentPrice, price);
pricesToWatch.add(priceObj);
System.out.println("Watch for BTC " + priceObj.type + " = " + price);
}
break;
}
}
}
}
scanner.close();
cancelTimer();
System.exit(0);
}
private void listPricesToWatch() {
if (pricesToWatch.isEmpty()) {
System.out.println("No prices to watch");
} else {
System.out.println("Prices to watch:");
for (Price price : pricesToWatch) {
System.out.println("\t" + price.type + "\t" + price.target);
}
}
System.out.println();
}
private void launchTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
loadBitcoinPrice(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String str = response.body().string();
parseBitcoinPrice(str);
}
@Override
public void onFailure(Call call, IOException ioe) {
}
});
}
}, 0, PERIOD);
}
private void cancelTimer() {
if (timer != null) {
timer.cancel();
}
}
private void loadBitcoinPrice(Callback callback) {
Request request = new Request.Builder().url(BITCOIN_PRICE_ENDPOINT).build();
client.newCall(request).enqueue(callback);
}
private void parseBitcoinPrice(String str) {
JSONObject jsonObject = new JSONObject(str);
currentPrice = jsonObject.getJSONObject("bpi").getJSONObject("USD").getFloat("rate_float");
System.out.println(LocalDateTime.now() + " | Current price = " + currentPrice + "\n");
// we check if one price is reached
for (Iteratorit = pricesToWatch.iterator(); it.hasNext();) {
Price priceToWatch = it.next();
if (priceToWatch.type.reached(currentPrice, priceToWatch.target)) {
String message = priceToWatch.type.msg(currentPrice, priceToWatch.target);
System.out.println(message);
displayNotification("Bitcoin Watcher", message);
// remove from list to watch
it.remove();
}
}
}
public void displayNotification(String title, String message) {
if (SystemTray.isSupported()) {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
TrayIcon trayIcon = new TrayIcon(image, "Bitcoin Watcher Notif");
//Let the system resize the image if needed
trayIcon.setImageAutoSize(true);
//Set tooltip text for the tray icon
trayIcon.setToolTip("Bitcoin Watcher");
try {
tray.add(trayIcon);
} catch (AWTException e) { }
trayIcon.displayMessage(title, message, MessageType.INFO);
} else {
System.err.println("System tray not supported!");
}
}
}
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.ssaurel
BitcoinPriceAlert
0.0.1-SNAPSHOT
jar
BitcoinPriceAlert
http://maven.apache.org
UTF-8
com.squareup.okhttp3
okhttp
4.2.2
org.json
json
20190722
junit
junit
3.8.1
test
private void loadBitcoinPrice(Callback callback) {
Request request = new Request.Builder().url(BITCOIN_PRICE_ENDPOINT).build();
client.newCall(request).enqueue(callback);
}
private void launchTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
loadBitcoinPrice(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String str = response.body().string();
parseBitcoinPrice(str);
}
@Override
public void onFailure(Call call, IOException ioe) { }
});
}
}, 0, PERIOD);
}
private void cancelTimer() {
if (timer != null) {
timer.cancel();
}
}
private void loadBitcoinPrice(Callback callback) {
Request request = new Request.Builder().url(BITCOIN_PRICE_ENDPOINT).build();
client.newCall(request).enqueue(callback);
}
private void parseBitcoinPrice(String str) {
JSONObject jsonObject = new JSONObject(str);
currentPrice = jsonObject.getJSONObject("bpi").getJSONObject("USD").getFloat("rate_float");
System.out.println(LocalDateTime.now() + " | Current price = " + currentPrice + "\n");
// ...
}
public class Price {
enum Type {
UP() {
@Override
public boolean reached(float current, float target) {
return target < current;
}
@Override
public String msg(float current, float target) {
return "BTC has rised beyond " + target + " with price : " + current;
}
},
DOWN {
@Override
public boolean reached(float current, float target) {
return current < target;
}
@Override
public String msg(float current, float target) {
return "BTC has fallen below " + target + " with price : " + current;
}
};
public abstract boolean reached(float current, float target);
public abstract String msg(float current, float target);
}
public float target;
public Type type;
public Price(float current, float target) {
this.target = target;
type = Float.compare(current, target) < 0 ? Type.UP : Type.DOWN;
}
}
private void parseBitcoinPrice(String str) {
JSONObject jsonObject = new JSONObject(str);
currentPrice = jsonObject.getJSONObject("bpi").getJSONObject("USD").getFloat("rate_float");
System.out.println(LocalDateTime.now() + " | Current price = " + currentPrice + "\n");
for (Iteratorit = pricesToWatch.iterator(); it.hasNext();) {
Price priceToWatch = it.next();
if (priceToWatch.type.reached(currentPrice, priceToWatch.target)) {
String message = priceToWatch.type.msg(currentPrice, priceToWatch.target);
System.out.println(message);
displayNotification("Bitcoin Watcher", message);
// remove from list to watch
it.remove();
}
}
}
public void displayNotification(String title, String message) {
if (SystemTray.isSupported()) {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
TrayIcon trayIcon = new TrayIcon(image, "Bitcoin Watcher Notif");
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("Bitcoin Watcher");
try {
tray.add(trayIcon);
} catch (AWTException e) {}
trayIcon.displayMessage(title, message, MessageType.INFO);
} else {
System.err.println("System tray not supported!");
}
}