1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resource OSRS Grand Exchange data lookup API

Discussion in 'Tutorials & Resources' started by Defeat3d, Apr 17, 2015.

  1. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,017
    Likes Received:
    1,890
    Pretty much stolen, updated, and improved from TopBot, credits to whoever made that.

    Code (Text):
    1. package productions.celestial.api.osrs;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.InputStream;
    5. import java.io.InputStreamReader;
    6. import java.net.URL;
    7. import java.net.URLConnection;
    8.  
    9. public class PriceLookup {
    10.  
    11.     private static InputStream is;
    12.     private static InputStreamReader isr;
    13.     private static BufferedReader br;
    14.  
    15.     private static String[] getData(int id) {
    16.         try {
    17.             final URL url = new URL(
    18.                     "https://api.rsbuddy.com/grandExchange?a=guidePrice&i="
    19.                             + id);
    20.             final URLConnection con = url.openConnection();
    21.             is = con.getInputStream();
    22.             isr = new InputStreamReader(is);
    23.             br = new BufferedReader(isr);
    24.             final String line = br.readLine();
    25.             if (line != null) {
    26.                 return line.split(",");
    27.             }
    28.         } catch (Exception e) {
    29.             e.printStackTrace();
    30.         } finally {
    31.             try {
    32.                 if (br != null) {
    33.                     br.close();
    34.                 } else if (isr != null) {
    35.                     isr.close();
    36.                 } else if (is != null) {
    37.                     is.close();
    38.                 }
    39.             } catch (Exception e) {
    40.                 e.printStackTrace();
    41.             }
    42.         }
    43.         return null;
    44.     }
    45.  
    46.     public static int getAveragePrice(final int id) {
    47.         final String[] data = getData(id);
    48.         if (data != null && data.length == 5) {
    49.             return Integer.parseInt(data[0].replaceAll("\\D", ""));
    50.         }
    51.         return -1;
    52.     }
    53.  
    54.     public static int getAverageBuyingOffer(final int id) {
    55.         final String[] data = getData(id);
    56.         if (data != null && data.length == 5) {
    57.             return Integer.parseInt(data[1].replaceAll("\\D", ""));
    58.         }
    59.         return -1;
    60.     }
    61.  
    62.     public static int getAverageBuyingQuantity(final int id) {
    63.         final String[] data = getData(id);
    64.         if (data != null && data.length == 5) {
    65.             return Integer.parseInt(data[2].replaceAll("\\D", ""));
    66.         }
    67.         return -1;
    68.     }
    69.  
    70.     public static int getAverageSellingOffer(final int id) {
    71.         final String[] data = getData(id);
    72.         if (data != null && data.length == 5) {
    73.             return Integer.parseInt(data[3].replaceAll("\\D", ""));
    74.         }
    75.         return -1;
    76.     }
    77.  
    78.     public static int getAverageSellingQuantity(final int id) {
    79.         final String[] data = getData(id);
    80.         if (data != null && data.length == 5) {
    81.             return Integer.parseInt(data[4].replaceAll("\\D", ""));
    82.         }
    83.         return -1;
    84.     }
    85.  
    86. }
    Enjoy lads.
     
  2. Lad

    Lad

    Joined:
    Feb 6, 2015
    Messages:
    241
    Likes Received:
    69
    I don't think they have accurate prices on OSBuddy, I noticed it while I was collecting herbs.
     
  3. Infinite Inferno

    Infinite Inferno The Pip Collector

    Joined:
    Sep 14, 2014
    Messages:
    445
    Likes Received:
    122
    They are still far better than what Zybez has.
     

Share This Page

Loading...