forked from realgs/MSiD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
86 lines (65 loc) · 2.03 KB
/
Main.java
File metadata and controls
86 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@SuppressWarnings("unused")
public class Main
{
static ArrayList <Offer> buy;
static ArrayList <Offer> sell;
private static void bitbayUpdate(URL source) throws IOException
{
String tab[];
int i=0; buy = new ArrayList<Offer>(); sell = new ArrayList<Offer>();
URLConnection connection = source.openConnection();
connection.connect();
BufferedReader buffer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
tab = buffer.readLine().replaceAll("[:\\[\\]\\{\\}]", "").split(",");
tab[0]=tab[0].replace("\"bids\"", "");
for(; !tab[i].contains("asks"); i+=2)
{
Offer temp = new Offer(true,Double.parseDouble(tab[i]),Double.parseDouble(tab[i+1]));
buy.add(temp);
}
tab[i]=tab[i].replace("\"asks\"", "");
for(; i<tab.length-1; i+=2)
{
Offer temp = new Offer(false,Double.parseDouble(tab[i]),Double.parseDouble(tab[i+1]));
sell.add(temp);
}
}
private static void printBuySell(URL source) throws IOException
{
bitbayUpdate(source);
for(Offer o : buy)
{
System.out.println(o);
}
System.out.println("\n___________________________________________________\n");
for(Offer o : sell)
{
System.out.println(o);
}
}
private static double buySellDiff()
{
System.out.println(String.format("|BUY: %-15.2f|SELL: %-15.2f|", buy.get(0).price, sell.get(0).price));
return ( (sell.get(0).price - buy.get(0).price)/buy.get(0).price )*100;
}
private static void inspectDiff(URL source) throws IOException, InterruptedException
{
while(true)
{
bitbayUpdate(source);
System.out.println("Ró¿nica: " + String.format("%f", buySellDiff()) + "%");
Thread.sleep(5000);
}
}
public static void main(String[] args) throws Exception
{
URL bitBayUrl = new URL("https://bitbay.net/API/Public/BTC/orderbook.json");
inspectDiff(bitBayUrl);
}
}