Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!
RuneMate will permanently shut down on August 7, 2026
due to events outside our control. You can continue using RuneMate until this date after which it will no longer be available. Thank you to everyone that contributed to RuneMate's success and to the community for the opportunity to serve you all these years.

  • Learn about RuneMate Vault and how its zero knowledge local encryption already protects your sensitive information.
  • Edit or delete your RuneMate account from your Account Settings.
  • All account upgrade subscriptions have been cancelled. No action required.

Resource OSRS Grand Exchange data lookup API

Conelander
Joined
Oct 30, 2014
Messages
4,078
Pretty much stolen, updated, and improved from TopBot, credits to whoever made that.

Code:
package productions.celestial.api.osrs;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class PriceLookup {

    private static InputStream is;
    private static InputStreamReader isr;
    private static BufferedReader br;

    private static String[] getData(int id) {
        try {
            final URL url = new URL(
                    "https://api.rsbuddy.com/grandExchange?a=guidePrice&i="
                            + id);
            final URLConnection con = url.openConnection();
            is = con.getInputStream();
            isr = new InputStreamReader(is);
            br = new BufferedReader(isr);
            final String line = br.readLine();
            if (line != null) {
                return line.split(",");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                } else if (isr != null) {
                    isr.close();
                } else if (is != null) {
                    is.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static int getAveragePrice(final int id) {
        final String[] data = getData(id);
        if (data != null && data.length == 5) {
            return Integer.parseInt(data[0].replaceAll("\\D", ""));
        }
        return -1;
    }

    public static int getAverageBuyingOffer(final int id) {
        final String[] data = getData(id);
        if (data != null && data.length == 5) {
            return Integer.parseInt(data[1].replaceAll("\\D", ""));
        }
        return -1;
    }

    public static int getAverageBuyingQuantity(final int id) {
        final String[] data = getData(id);
        if (data != null && data.length == 5) {
            return Integer.parseInt(data[2].replaceAll("\\D", ""));
        }
        return -1;
    }

    public static int getAverageSellingOffer(final int id) {
        final String[] data = getData(id);
        if (data != null && data.length == 5) {
            return Integer.parseInt(data[3].replaceAll("\\D", ""));
        }
        return -1;
    }

    public static int getAverageSellingQuantity(final int id) {
        final String[] data = getData(id);
        if (data != null && data.length == 5) {
            return Integer.parseInt(data[4].replaceAll("\\D", ""));
        }
        return -1;
    }

}

Enjoy lads.
 

lad

Joined
Feb 6, 2015
Messages
241
I don't think they have accurate prices on OSBuddy, I noticed it while I was collecting herbs.
 
Top