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
  • RSBuddy/OSBuddy Exchange Price Lookup


    Vlad

    Recommended Posts

    Posted

    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

    Posted

    Updated it. It now closes the stream and readers. :)

    • 4 weeks later...
    Posted

    Updated. OSBuddy updated their API and it broke, but it will now work again.

    Posted

    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.

    • 4 months later...
    Posted

    Seems to still work, but the bot lags alot  :unsure:

    • 4 months later...
    Posted

    How would I read all the average buy prices in one go for example? I'm just wondering since it could be useful later on :D

    Posted

    Seems to still work, but the bot lags alot  :unsure:

    Lags the script a lot when implemented :)

    Posted

    So how can i dump all the item prices in one go ?:o

    Posted

    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 ;)

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.