package cryptowatch;

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonValue;
import java.awt.List;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.io.IOUtils;

public class Market {
    static JsonArray arrayBittrex;
    
    public static void startTimer(){
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                String url = "https://bittrex.com/api/v1.1/public/getmarketsummaries";
                try {
                    URL url2 = new URL(url);
                    URLConnection con = url2.openConnection();
                    InputStream in = con.getInputStream();
                    String encoding = "UTF-8";
                    String body = IOUtils.toString(in, encoding);
                    arrayBittrex = Json.parse(body).asObject().get("result").asArray();
                    //System.out.println(arrayBittrex);
                }
                catch(MalformedURLException e) {}
                catch(IOException e) {}
            }
        }, 0,5000);
    }
    
    //public static 
    
    public static float getPrice(String exchange, String market) {
        for (JsonValue item : arrayBittrex) {
            float last = item.asObject().getFloat("Last", 0);
            System.out.println(last);
            return last;
        }
        return 0;
    }
        
}

@@ -137,30 +137,8 @@
 ue;%0A
-import java.awt.List;%0A
 impo
@@ -153,32 +153,32 @@
 io.IOException;%0A
+
 import java.io.I
@@ -301,17 +301,15 @@
 til.
-ArrayList
+Objects
 ;%0Aim
@@ -434,23 +434,18 @@
 tic 
-JsonArray array
+String raw
 Bitt
@@ -979,19 +979,18 @@
     
-String body
+rawBittrex
  = I
@@ -1024,152 +1024,8 @@
 g);%0A
-                    arrayBittrex = Json.parse(body).asObject().get(%22result%22).asArray();%0A                    //System.out.println(arrayBittrex);%0A
     
@@ -1177,34 +1177,8 @@
    %0A
-    //public static %0A    %0A
     
@@ -1252,42 +1252,378 @@
     
-for (JsonValue item : arrayBittrex
+if(exchange.equals(%22bittrex%22)) %7B%0A            JsonArray arrayBittrex = Json.parse(rawBittrex).asObject().get(%22result%22).asArray();%0A            int numArrays = Json.parse(rawBittrex).asObject().get(%22result%22).asArray().size();%0A%0A            for(int i=0; i%3CnumArrays; i++)%7B%0A                if(market.equalsIgnoreCase(arrayBittrex.get(i).asObject().getString(%22MarketName%22, %22%22))
 ) %7B%0A
@@ -1634,16 +1634,24 @@
         
+        
 float la
@@ -1659,12 +1659,27 @@
 t = 
-item
+arrayBittrex.get(i)
 .asO
@@ -1723,32 +1723,27 @@
     
-System.out.println(
+        return 
 last
-)
 ;%0A  
@@ -1748,36 +1748,43 @@
             
-return last;
+    %7D%0A            %7D
 %0A        %7D%0A 
@@ -1800,25 +1800,17 @@
 turn 0;%0A
+
     %7D
-%0A       
  %0A%7D%0A

Add working price functionality