Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • RSBuddy/OSBuddy Exchange Price Lookup


    Vlad
     Share

    Recommended Posts

    RSBuddy/OSBuddy Exchange has more accurate prices than Zybez for the most part.

    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 URLConnection con;
    	private static InputStream is;
    	private static InputStreamReader isr;
    	private static BufferedReader br;
    
    	private static String[] getData(int itemID) {
    		try {
    			URL url = new URL(
    					"https://api.rsbuddy.com/grandExchange?a=guidePrice&i="
    							+ itemID);
    			con = url.openConnection();
    			is = con.getInputStream();
    			isr = new InputStreamReader(is);
    			br = new BufferedReader(isr);
    			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 getPrice(int itemID) {
    		String[] data = getData(itemID);
    		if (data != null && data.length == 5) {
    			return Integer.parseInt(data[0].replaceAll("\\D", ""));
    		}
    		return 0;
    	}
    
    	public static int getAverageBuyOffer(int itemID) {
    		String[] data = getData(itemID);
    		if (data != null && data.length == 5) {
    			return Integer.parseInt(data[1].replaceAll("\\D", ""));
    		}
    		return 0;
    	}
    
    	public static int getAverageSellOffer(int itemID) {
    		String[] data = getData(itemID);
    		if (data != null && data.length == 5) {
    			return Integer.parseInt(data[3].replaceAll("\\D", ""));
    		}
    		return 0;
    	}
    } 

    Dump of all the prices from March 27, 2015: http://pastebin.com/rQ5dk7mp

    Edited by Vlad
    Link to comment
    Share on other sites

    • 4 weeks later...

    You should create an enum for each values index in the data row (item price is 0, average buy offer is 1, etc.) and then just have a generic method to grab the value from the row:

    public static int getValue(DataRowValueIndexOrWhateverYourEnumIsCalled value) {
    	String[] data = getData(itemID);
    	if (data != null && data.length == 5) {
    		return Integer.parseInt(data[value.getIndexOrWhateverTheGetterForIndexIs()].replaceAll("\\D", ""));
    	}
    	return 0;
    }
    

    It might be beneficial to also create a private constructor since everything's static and an instance will never need to be created.

    Link to comment
    Share on other sites

    • 4 months later...
    • 4 months later...

    If you're going to use this, don't call it every time you need a price. Store the prices in a map. I use something like this

     

     

    HashMap<String, Integer> priceMap = new HashMap<>();
    priceMap.put(item.getName(), PriceLookup.getPrice(item.getID()); //For each item. Do this only once.
    

     

    Then you can access your items prices with

     

     

    priceMap.get(item.getName());
    

     

    This may not be the best way of doing it, so if someone else has a better way please share. However, this will give you an access time of O(1) so it's pretty quick. May be able to use a smaller data structure so if you have a better way, show us ;)

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.